Mysql中default分区_MySQL中的分区表(下)

分区表的管理range和list分区添加分区

删除分区

修改分区

合并或拆分分区

hash和key分区添加分区

删除分区

修改分区

合并或拆分分区

分区的维护重建分区

优化分区

分析分区

检查分区

修复分区

分区表的注意事项

总结

关于分区表的的分类和示例,请参考上篇文章。

分区表的管理

range和list分区

对于range和list两种类型的分区表的管理,接下来的各种演示示例:添加分区、删除分区、修改分区、合并拆分分区的各种操作,都是基于下面的这个range范围分区表来做演示,list类型的分区操作类似。

这个range范围分区表的建表语句和初始化数据如下所示:/*创建range范围分区表*/ drop table if exists range_partition_table; create table range_partition_table( id int auto_increment, code varchar(16), create_date date, primary key(id, create_date) ) partition by range columns(create_date) ( partition p1 values less than('2020-02-01'), /*p1分区不包含2020-02-01这一天的数据*/ partition p2 values less than('2020-03-01'), partition p3 values less than('2020-04-01'), partition p4 values less than('2020-05-01'), partition px values less than maxvalue ); /*插入测试数据*/ insert into range_partition_table(id, code, create_date) values (null, 'A', '2020-01-04'); insert into range_partition_table(id, code, create_date) values (null, 'B', '2020-01-31'); insert into range_partition_table(id, code, create_date) values (null, 'C', '2020-02-01'); insert into range_partition_table(id, code, create_date) values (null, 'D', '2020-02-29'); insert into range_partition_table(id, code, create_date) values (null, 'E', '2020-03-01'); insert into range_partition_table(id, code, create_date) values (null, 'F', '2020-03-31'); insert into range_partition_table(id, code, create_date) values (null, 'G', '2020-04-01'); insert into range_partition_table(id, code, create_date) values (null, 'H', '2020-04-30'); insert into range_partition_table(id, code, create_date) values (null, 'I', '2020-05-01'); insert into range_partition_table(id, code, create_date) values (null, 'J', '2020-05-31'); insert into range_partition_table(id, code, create_date) values (null, 'K', '2020-06-01'); insert into range_partition_table(id, code, create_date) values (null, 'L', '2020-06-30'); insert into range_partition_table(id, code, create_date) values (null, 'M', '2020-07-01');

原始range分区表的详细信息如下图所示:

bace784fe2f48936e48db279fcc6ce76.png

添加分区

这里管理分区部分,我们都使用range范围分区来做演示,

如果要添加一个分区,则只需如下的SQL语句alter table range_partition_table add partition (partition p5 values less than ('2020-06-01'));

在添加分区的时候,需要注意如果你的分区表类型是range范围分区,并且制定了最后一个范围分区的范围边界为maxvalue,那么你不能直接在这样的一个range范围分区表上增加分区,否则会出现如下的错误:mysql> alter table range_partition_table add partition (partition p5 values less than ('2020-06-01')); ERROR 1493 (HY000): VALUES LESS THAN value must be strictly increasing for each partition

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL分区的索引也是随着各个分区单独存储的。每个分区都被视为独立的,因此每个分区都有自己的索引文件(.ibd文件)。这意味着在分区上创建的索引只会在相应的分区上生效,并且可以独立地进行索引维护和查询优化。 需要注意的是,分区的索引结构与普通的索引结构是一样的。MySQL提供了多种索引数据结构,如哈希索引、有序数组索引和多路搜索树。哈希索引适用于等值查询场景,有序数组索引适用于静态存储引擎,而多路搜索树索引(如InnoDB使用的B+树)则适用于大部分场景,并且具有较好的查询效率。 总结来说,在MySQL分区,索引与普通的索引相同,但是每个分区都有自己的索引文件,使得索引操作和查询可以在特定的分区上进行,提高了查询效率和维护的灵活性。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [MySQL分区与索引](https://blog.csdn.net/qq_41345173/article/details/104640441)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [mysql分区之三:MySQL分区建索引[转]](https://blog.csdn.net/weixin_33804582/article/details/85863312)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值