diff --git a/src/gausskernel/optimizer/commands/indexcmds.cpp b/src/gausskernel/optimizer/commands/indexcmds.cpp index 64911467a..fe0211950 100755 --- a/src/gausskernel/optimizer/commands/indexcmds.cpp +++ b/src/gausskernel/optimizer/commands/indexcmds.cpp @@ -5412,6 +5412,8 @@ static void CheckIndexParamsNumber(IndexStmt* stmt) { static bool CheckIdxParamsOwnPartKey(Relation rel, const List* indexParams) { + if (!PartExprKeyIsNull(rel, NULL)) + return false; int2vector* partKey = ((RangePartitionMap*)rel->partMap)->partitionKey; for (int i = 0; i < partKey->dim1; i++) { int2 attNum = partKey->values[i]; diff --git a/src/test/regress/input/partition_expr_key.source b/src/test/regress/input/partition_expr_key.source index 711adbbce..c5d8ef0d4 100644 --- a/src/test/regress/input/partition_expr_key.source +++ b/src/test/regress/input/partition_expr_key.source @@ -290,6 +290,17 @@ select pg_get_tabledef('testrangesubpart'); select pg_get_tabledef('testlistsubpart'); select pg_get_tabledef('testhashsubpart'); select pg_get_tabledef('testnormalsubpart'); +create database part_expr_key_db1 dbcompatibility 'B'; +\c part_expr_key_db1; +create table t1(c1 int not null, c2 int) +partition by range(c1 + 100) ( +partition p1 values less than(200), +partition p2 values less than(300), +partition p3 values less than(400) +); +CREATE INDEX t1_c2_idx ON t1 USING btree (c2) LOCAL(PARTITION p1_c2_idx, PARTITION p2_c2_idx, PARTITION p3_c2_idx); +ALTER TABLE t1 ADD CONSTRAINT t3_pkey PRIMARY KEY USING btree (c1) INCLUDE (tableoid); \c regression -drop database if exists part_expr_key_db; \ No newline at end of file +drop database if exists part_expr_key_db; +drop database if exists part_expr_key_db1; diff --git a/src/test/regress/output/partition_expr_key.source b/src/test/regress/output/partition_expr_key.source index 648b914ee..3185072dd 100644 --- a/src/test/regress/output/partition_expr_key.source +++ b/src/test/regress/output/partition_expr_key.source @@ -954,5 +954,17 @@ select pg_get_tabledef('testnormalsubpart'); ENABLE ROW MOVEMENT; (1 row) +create database part_expr_key_db1 dbcompatibility 'B'; +\c part_expr_key_db1; +create table t1(c1 int not null, c2 int) +partition by range(c1 + 100) ( +partition p1 values less than(200), +partition p2 values less than(300), +partition p3 values less than(400) +); +CREATE INDEX t1_c2_idx ON t1 USING btree (c2) LOCAL(PARTITION p1_c2_idx, PARTITION p2_c2_idx, PARTITION p3_c2_idx); +ALTER TABLE t1 ADD CONSTRAINT t3_pkey PRIMARY KEY USING btree (c1) INCLUDE (tableoid); +NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "t3_pkey" for table "t1" \c regression drop database if exists part_expr_key_db; +drop database if exists part_expr_key_db1;