diff --git a/src/gausskernel/runtime/opfusion/opfusion_update.cpp b/src/gausskernel/runtime/opfusion/opfusion_update.cpp index bec178d21..929c919d8 100644 --- a/src/gausskernel/runtime/opfusion/opfusion_update.cpp +++ b/src/gausskernel/runtime/opfusion/opfusion_update.cpp @@ -377,7 +377,7 @@ lreplace: temp_values = m_local.m_reslot->tts_values; m_local.m_reslot->tts_values = m_local.m_values; bool update_fix_result = ExecComputeStoredUpdateExpr(result_rel_info, m_c_local.m_estate, m_local.m_reslot, - tup, CMD_UPDATE, tupleid, InvalidOid, bucketid); + tup, CMD_UPDATE, tupleid, (part == NULL ? InvalidOid : part->pd_id), bucketid); if (!update_fix_result) { if (tup != m_local.m_reslot->tts_tuple) { tableam_tops_free_tuple(tup); diff --git a/src/test/regress/expected/single_node_update.out b/src/test/regress/expected/single_node_update.out index 8f4a1ff93..a334ae5b4 100644 --- a/src/test/regress/expected/single_node_update.out +++ b/src/test/regress/expected/single_node_update.out @@ -665,5 +665,89 @@ select * from t_dmpportal_common_intent; --?.* (3 rows) +show sql_beta_feature; + sql_beta_feature +------------------ + a_style_coerce +(1 row) + +show enable_partition_opfusion; + enable_partition_opfusion +--------------------------- + off +(1 row) + +show enable_opfusion; + enable_opfusion +----------------- + off +(1 row) + +set sql_beta_feature = 'a_style_coerce, partition_opfusion'; +set enable_partition_opfusion = on; +set enable_opfusion = on; +create table bypass_pt_update ( + a serial primary key, + b int default 1 +) partition by range(a) ( + partition p1 values less than (5), + partition p2 values less than (maxvalue) +); +NOTICE: CREATE TABLE will create implicit sequence "bypass_pt_update_a_seq" for serial column "bypass_pt_update.a" +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "bypass_pt_update_pkey" for table "bypass_pt_update" +insert into bypass_pt_update(b) select generate_series(1,8); +select * from bypass_pt_update order by a; + a | b +---+--- + 1 | 1 + 2 | 2 + 3 | 3 + 4 | 4 + 5 | 5 + 6 | 6 + 7 | 7 + 8 | 8 +(8 rows) + +explain (verbose on, costs off) update bypass_pt_update set b = 2 where a = 1; + QUERY PLAN +------------------------------------------------------------------------------------- + [Bypass] + Update on public.bypass_pt_update + -> Partitioned Index Scan using bypass_pt_update_pkey on public.bypass_pt_update + Output: a, 2, ctid, tableoid + Index Cond: (bypass_pt_update.a = 1) + Selected Partitions: 1 +(6 rows) + +update bypass_pt_update set b = 2 where a = 1; +explain (verbose on, costs off) update bypass_pt_update set a = 9 where a = 2; + QUERY PLAN +------------------------------------------------------------------------------------- + Update on public.bypass_pt_update + -> Partitioned Index Scan using bypass_pt_update_pkey on public.bypass_pt_update + Output: 9, b, ctid, tableoid + Index Cond: (bypass_pt_update.a = 2) + Selected Partitions: 1 +(5 rows) + +update bypass_pt_update set a = 9 where a = 2; +select * from bypass_pt_update order by a; + a | b +---+--- + 1 | 2 + 3 | 3 + 4 | 4 + 5 | 5 + 6 | 6 + 7 | 7 + 8 | 8 + 9 | 2 +(8 rows) + +drop table bypass_pt_update; +set sql_beta_feature='a_style_coerce'; +set enable_partition_opfusion = off; +set enable_opfusion = off; \c regression DROP database mysql; diff --git a/src/test/regress/sql/single_node_update.sql b/src/test/regress/sql/single_node_update.sql index 8f54ca728..889d06b76 100644 --- a/src/test/regress/sql/single_node_update.sql +++ b/src/test/regress/sql/single_node_update.sql @@ -261,5 +261,37 @@ update t_dmpportal_common_intent set intent_name='2' where id=2; select count(upt_time) from t_dmpportal_common_intent group by upt_time order by upt_time; select * from t_dmpportal_common_intent; + +show sql_beta_feature; +show enable_partition_opfusion; +show enable_opfusion; +set sql_beta_feature = 'a_style_coerce, partition_opfusion'; +set enable_partition_opfusion = on; +set enable_opfusion = on; + +create table bypass_pt_update ( + a serial primary key, + b int default 1 +) partition by range(a) ( + partition p1 values less than (5), + partition p2 values less than (maxvalue) +); + +insert into bypass_pt_update(b) select generate_series(1,8); +select * from bypass_pt_update order by a; + +explain (verbose on, costs off) update bypass_pt_update set b = 2 where a = 1; +update bypass_pt_update set b = 2 where a = 1; + +explain (verbose on, costs off) update bypass_pt_update set a = 9 where a = 2; +update bypass_pt_update set a = 9 where a = 2; + +select * from bypass_pt_update order by a; + +drop table bypass_pt_update; +set sql_beta_feature='a_style_coerce'; +set enable_partition_opfusion = off; +set enable_opfusion = off; + \c regression -DROP database mysql; \ No newline at end of file +DROP database mysql;