From ccd860bff791222a454dd9fe2f83fcb5cb882000 Mon Sep 17 00:00:00 2001 From: WangXiuqiang Date: Tue, 3 Jan 2023 16:14:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3update=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=88=97=E6=97=A0=E6=B3=95=E9=80=89=E6=8B=A9=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E5=88=86=E5=8C=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runtime/executor/nodeModifyTable.cpp | 4 +- .../regress/input/partition_expr_key.source | 16 +++++++ .../regress/output/partition_expr_key.source | 46 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/gausskernel/runtime/executor/nodeModifyTable.cpp b/src/gausskernel/runtime/executor/nodeModifyTable.cpp index 95979e9a7..dd05038de 100644 --- a/src/gausskernel/runtime/executor/nodeModifyTable.cpp +++ b/src/gausskernel/runtime/executor/nodeModifyTable.cpp @@ -2418,11 +2418,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) (