diff --git a/src/gausskernel/runtime/executor/nodeModifyTable.cpp b/src/gausskernel/runtime/executor/nodeModifyTable.cpp index aac3bf0b3..2e9fe8fef 100644 --- a/src/gausskernel/runtime/executor/nodeModifyTable.cpp +++ b/src/gausskernel/runtime/executor/nodeModifyTable.cpp @@ -2431,11 +2431,11 @@ lreplace: bool need_create_file = false; int seqNum = -1; bool can_ignore = estate->es_plannedstmt->hasIgnore; - if (!partKeyUpdate) { + Datum newval = ComputePartKeyExprTuple(result_relation_desc, estate, slot, NULL); + if (!newval && !partKeyUpdate) { row_movement = false; new_partId = oldPartitionOid; } else { - Datum newval = ComputePartKeyExprTuple(result_relation_desc, estate, slot, NULL); if (newval) { partitionRoutingForTuple(result_relation_desc, (void*)newval, u_sess->exec_cxt.route, can_ignore); } else { diff --git a/src/test/regress/input/partition_expr_key.source b/src/test/regress/input/partition_expr_key.source index 79becca17..711adbbce 100644 --- a/src/test/regress/input/partition_expr_key.source +++ b/src/test/regress/input/partition_expr_key.source @@ -199,6 +199,22 @@ insert into b_bug_1 values(100,1.5),(199,2.5); select * from b_bug_1 partition(p1); select * from b_bug_1 partition(p2); drop table if exists b_bug_1; +create table b_bug_2(a int, b int, c int) partition by range(a-b) +( + partition p1 values less than(10), + partition p2 values less than(20), + partition p3 values less than(30) +); +create index on b_bug_2(a) global; +create index on b_bug_2(b) local; +insert into b_bug_2 values(19,10,1),(30,20,2),(50,30,3); +select * from b_bug_2 partition(p1); +select * from b_bug_2 partition(p2); +select * from b_bug_2 partition(p3); +update b_bug_2 set b = 21 where c = 2; +select * from b_bug_2 partition(p1); +select * from b_bug_2 partition(p2); +select * from b_bug_2 partition(p3); --test pg_get_tabledef and pg_dump diff --git a/src/test/regress/output/partition_expr_key.source b/src/test/regress/output/partition_expr_key.source index 2b2c05f8b..648b914ee 100644 --- a/src/test/regress/output/partition_expr_key.source +++ b/src/test/regress/output/partition_expr_key.source @@ -558,6 +558,52 @@ select * from b_bug_1 partition(p2); (1 row) drop table if exists b_bug_1; +create table b_bug_2(a int, b int, c int) partition by range(a-b) +( + partition p1 values less than(10), + partition p2 values less than(20), + partition p3 values less than(30) +); +create index on b_bug_2(a) global; +create index on b_bug_2(b) local; +insert into b_bug_2 values(19,10,1),(30,20,2),(50,30,3); +select * from b_bug_2 partition(p1); + a | b | c +----+----+--- + 19 | 10 | 1 +(1 row) + +select * from b_bug_2 partition(p2); + a | b | c +----+----+--- + 30 | 20 | 2 +(1 row) + +select * from b_bug_2 partition(p3); + a | b | c +----+----+--- + 50 | 30 | 3 +(1 row) + +update b_bug_2 set b = 21 where c = 2; +select * from b_bug_2 partition(p1); + a | b | c +----+----+--- + 19 | 10 | 1 + 30 | 21 | 2 +(2 rows) + +select * from b_bug_2 partition(p2); + a | b | c +---+---+--- +(0 rows) + +select * from b_bug_2 partition(p3); + a | b | c +----+----+--- + 50 | 30 | 3 +(1 row) + --test pg_get_tabledef and pg_dump create table testnormalsubpart(a int, b int) partition by range(a) subpartition by range(b) (