Mysql分区

 

Myisam:多个小表一个聚合表,逻辑上的

Innodb:物理文件的划分

注意事项

 

Show plugins

Show engines

Show variables like ‘%partition%

 

 

分区方式:Range、LIST、HASH、KEY,5.5版本之后支持非整形的Range和List分区;Hash分区不支持字符串

 

 

Explain:sql优化常用命令,比如Explain partitions select * from tbl1 where uuid=80

Select * from tbl where uuid=8 partition(p1)

 

Select * from information_schema.partions where table_schema=’test’ and table_name=’tbl_1’ \G;

 

 

Show global variables like ‘%datadir%’;

 

Range分区

Create table tb1(uuid int not null,name varchar(20))

Partition by range(uuid)(

Partition p0 values less than(5),

Partition p1 values less than(10),

Partition p2 values less than maxvalue

)

或者list分区

Partition by list(uuid)

partitions(

Partition p0 values in (1,2,3)

)

 

Patition by hash(mod(uuid,2))

( partition 3)

 

Alter table tb1 remove partitioning

 

 

分区列需要包含唯一索引或者主键;不支持有外键的表做分区;不支持全文索引;数据和索引都会产生分区文件;单条记录查询在分区中是没有优势的,因为需要做分区选择,插入等其他操作也是需要成本的;分区字段不要使用null;

 

 

分区可以做删除、合并、重建等操作,含不删除数据 单独针对分区的操作

posted @ 2019-12-07 10:30  那只狐狸  阅读(244)  评论(0编辑  收藏  举报