mysql innodb單錶分割槽實戰

2021-08-03 23:42:16 字數 1983 閱讀 2378

目的:為了了解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單錶分割槽方法,特此作為學習筆記記錄一下。一。準備表,建立乙個學生表,包含主鍵sid和名稱sname欄位 create table students sid int 5 primary key,sname varchar 24 二。準備資料 insert into stude...

MYSQL INNODB 鎖錶小研究

表結構如下 delimiter create table wrox shop order o id int 11 not null auto increment,order date datetime default null,order status varchar 45 default crea...