mysql單錶分割槽

2022-04-12 05:02:24 字數 1983 閱讀 9458

目的:為了了解mysql單錶分割槽方法,特此作為學習筆記記錄一下。

一。準備表,建立乙個學生表,包含主鍵sid和名稱sname欄位

create table students(

sid int(5) primary key,

sname varchar(24)

);二。準備資料

insert into students(sid,sname) values(10003,'tom');

insert into students(sid,sname) values(10005,'jerry');

insert into students(sid,sname) values(10006,'hengte');

insert into students(sid,sname) values(10007,'weilian');

insert into students(sid,sname) values(10000,'tom1');

insert into students(sid,sname) values(10001,'jerry2');

insert into students(sid,sname) values(10002,'hengte3');

insert into students(sid,sname) values(10004,'weilian4');

三。查詢結果

select * from sutdents

四。建立分割槽,按照主鍵id的值進行設定分割槽規則如下:

alter table students partition by range(sid)

(partition p0 values less than (10001),

partition p1 values less than (10003),

partition p2 values less than (10005),

partition p3 values less than maxvalue

);五。查詢結果,可以看到查詢結果分布到不同的分割槽裡

select  * from students partition (p0);

select  * from students partition (p1);

select  * from students partition (p2);

select  * from students partition (p3);

六。驗證新插入資料

insert into students(sid,sname) values(10011,'tom12');

insert into students(sid,sname) values(10012,'jerry13');

insert into students(sid,sname) values(10013,'hengte14');

insert into students(sid,sname) values(10014,'weilian15');

insert into students(sid,sname) values(10015,'tom116');

insert into students(sid,sname) values(10016,'jerry22');

insert into students(sid,sname) values(10017,'hengte32');

insert into students(sid,sname) values(10018,'weilian42');

七。再次查詢分割槽資料,會看到新插入的資料按照分割槽規則劃分到對應的分割槽裡了

select  * from students partition (p0);

select  * from students partition (p1);

select  * from students partition (p2);

select  * from students partition (p3);

Oracle單錶分割槽

1 表中大小超過2g 2 表中有歷史資料,新的資料被新增到新的分割槽中。sql檢視表占用空間 檢視表中占用記憶體大小,固定用法 select segment name,sum bytes 1024 1024 m from dba extents where segment name 表名 group...

mysql表分割槽全文搜尋 Mysql表分割槽

什麼時候使用分割槽 海量資料 資料表索引大於伺服器有效記憶體 分割槽的限制 大部分只能對資料表的整型列進行分割槽,或者資料列可以通過分割槽函式轉化成整型列 其中columns支援 integer string date datetime型別 最大分割槽數目不能超過1024 如果含有唯一索引或者主鍵,...

mysql表分割槽

表分割槽的優點 查詢優化 缺點 除了資料庫管理方面複雜了點,其它的還沒有發現 只有5.1及之後的版本才支付分割槽,同時5.1中分割槽的一些維護的工具還不完善 mysql目前四種分割槽 1range 根據某個列的某種運算進行分割槽,分割槽的標誌都是該列的某種運算後的連續區間 create table ...