【 使用环境 】生产环境
【 OB or 其他组件 】observer
【 使用版本 】4.2.5bp4
【问题描述】当前4.2.5最新版本支持了二级分区表的增加/删除分区的功能,但是不支持exchange临时表的功能。线上核心表强依赖此功能,配置临时表保留7天删除,防止分区被误删,可以在7天内回退操作。
【复现路径】
1.一级分区支持增加&删除分区,但是不支持exchange操作:
mysql> CREATE TABLE test1(col1 INT,col2 INT,db_create_time
timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP )
→ PARTITION BY RANGE (UNIX_TIMESTAMP(db_create_time))
→ (PARTITION p20240718 VALUES LESS THAN (1721232000),
→ PARTITION p20240725 VALUES LESS THAN (1721836800) ) ;
Query OK, 0 rows affected (0.26 sec)
mysql> alter table test1 add PARTITION (partition p20250101
values less than (1735660800000));
Query OK, 0 rows affected (0.16 sec)
mysql> alter table test1 drop PARTITION p20240718;
Query OK, 0 rows affected (0.17 sec)
mysql> CREATE TABLE _test1_tmp(col1 INT,col2 INT,db_create_time
timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ) ;
Query OK, 0 rows affected (0.12 sec)
mysql> alter table test1 exchange partition p20240725 with table _test1_tmp;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near ‘exchange partition p20240725 with table _test1_tmp’ at line 1
(ob sql语法也不支持exchange,本案例根据MySQL语法进行执行)
2.二级分区支持增加&删除分区,但是不支持exchange操作:
mysql> CREATE TABLE test2(col1 INT,col2 INT,db_create_time
timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP )
→ PARTITION BY HASH(col2)
→ SUBPARTITION BY RANGE (UNIX_TIMESTAMP(db_create_time))
→ SUBPARTITION TEMPLATE
→ (SUBPARTITION p20240718 VALUES LESS THAN (1721232000),
→ SUBPARTITION p20240725 VALUES LESS THAN (1721836800) ) PARTITIONS 6;
Query OK, 0 rows affected (0.16 sec)
mysql> alter table test2 modify partition p0 add subpartition (subpartition p20250101
values less than (1735660800000));
Query OK, 0 rows affected (0.13 sec)
mysql> alter table test2 drop subpartition p0sp20240718;
Query OK, 0 rows affected (0.13 sec)
mysql> CREATE TABLE _test2_tmp(col1 INT,col2 INT,db_create_time
timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP )
→ PARTITION BY HASH(col2) PARTITIONS 6;
Query OK, 0 rows affected (0.12 sec)
(ob二级分区表也没有exchange分区的语法提供,在此无法提供exchange失败案例)
【备注】MySQL分区表exchange分区为临时表官方文档URL:https://dev.mysql.com/doc/refman/5.7/en/partitioning-management-exchange.html
摘要:“In MySQL 5.7, it is possible to exchange a table partition or subpartition with a table using ALTER TABLE pt
EXCHANGE PARTITION p
WITH TABLE nt
, where pt
is the partitioned table and p
is the partition or subpartition of pt
to be exchanged with unpartitioned table nt
”