执行表分区操作时,报错:start value of partition "xxx" NOT EQUAL up-boundary of last partition
问题现象
执行ALTER TABLE PARTITION时报错:
ERROR:start value of partition "XX" NOT EQUAL up-boundary of last partition.
原因分析
在同一条ALTER TABLE PARTITION语句中,既存在DROP PARTITION又存在ADD PARTITION时,无论它们的相对顺序是什么,GaussDB(DWS)总会先执行DROP PARTITION再执行ADD PARTITION。执行完DROP PARTITION删除末尾分区后,再执行ADD PARTITION操作会出现分区间隙,导致报错。
解决办法
为防止出现分区间隙,需要将ADD PARTITION的START值前移。
以分区表partitiontest为例:
1 2 3 4 5 6 7 8 9 10 |
CREATE TABLE partitiontest ( c_int integer, c_time TIMESTAMP WITHOUT TIME ZONE ) PARTITION BY range (c_int) ( partition p1 start(100)end(108), partition p2 start(108)end(120) ); |
执行如下两种语句会发生报错:
1 2 |
ALTER TABLE partitiontest ADD PARTITION p3 start(120)end(130), DROP PARTITION p2; ERROR: start value of partition "p3" NOT EQUAL up-boundary of last partition. |
1 2 |
ALTER TABLE partitiontest DROP PARTITION p2,ADD PARTITION p3 start(120)end(130); ERROR: start value of partition "p3" NOT EQUAL up-boundary of last partition. |
可以修改语句为:
1
|
ALTER TABLE partitiontest ADD PARTITION p3 start(108)end(130), DROP PARTITION p2; |
1
|
ALTER TABLE partitiontest DROP PARTITION p2,ADD PARTITION p3 start(108)end(130); |