From 3b73572c0fffba1f1f68a3a5499d85c6b195d01c Mon Sep 17 00:00:00 2001 From: laishenghao Date: Mon, 13 Feb 2023 15:55:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=8F=B3=E5=80=BC=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E5=AD=98=E5=9C=A8returning=E8=AF=AD=E5=8F=A5=E6=97=B6?= =?UTF-8?q?core=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/parser/analyze.cpp | 1 + .../runtime/executor/nodeModifyTable.cpp | 1 - .../regress/input/insert_right_ref.source | 74 ++++++++++++++++ .../regress/output/insert_right_ref.source | 86 +++++++++++++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) diff --git a/src/common/backend/parser/analyze.cpp b/src/common/backend/parser/analyze.cpp index b1eac03e7..7a0d5ed17 100644 --- a/src/common/backend/parser/analyze.cpp +++ b/src/common/backend/parser/analyze.cpp @@ -2136,6 +2136,7 @@ static Query* transformInsertStmt(ParseState* pstate, InsertStmt* stmt) if (stmt->returningList) { pstate->p_relnamespace = NIL; pstate->p_varnamespace = NIL; + pstate->rightRefState = nullptr; addRTEtoQuery(pstate, rte, false, true, true); qry->returningList = transformReturningList(pstate, stmt->returningList); if (qry->returningList != NIL && RelationIsColStore(targetrel)) { diff --git a/src/gausskernel/runtime/executor/nodeModifyTable.cpp b/src/gausskernel/runtime/executor/nodeModifyTable.cpp index edeb04468..aac3bf0b3 100644 --- a/src/gausskernel/runtime/executor/nodeModifyTable.cpp +++ b/src/gausskernel/runtime/executor/nodeModifyTable.cpp @@ -4059,7 +4059,6 @@ ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int efl /* Need an econtext too */ econtext = CreateExprContext(estate); mt_state->ps.ps_ExprContext = econtext; - ATTACH_RIGHT_REF_STATE(&(mt_state->ps)); /* * Build a projection for each result rel. diff --git a/src/test/regress/input/insert_right_ref.source b/src/test/regress/input/insert_right_ref.source index 9987853c0..2a1d5cf5a 100644 --- a/src/test/regress/input/insert_right_ref.source +++ b/src/test/regress/input/insert_right_ref.source @@ -364,6 +364,80 @@ insert into other_notnull_t values(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c1 concat(c27 ,'beijing'), c28, c29, c30, c31, c32); select * from other_notnull_t; +-- test returning +CREATE TABLE t_replica_batch ( + i_id_batch serial NOT NULL, + i_id_source bigint NOT NULL, + t_binlog_name text, + v_log_table character varying DEFAULT 't_log_replica'::character varying NOT NULL, + i_binlog_position bigint, + t_gtid_set text, + b_started boolean DEFAULT false NOT NULL, + b_processed boolean DEFAULT false NOT NULL, + b_replayed boolean DEFAULT false NOT NULL, + ts_created timestamp without time zone DEFAULT clock_timestamp() NOT NULL, + ts_processed timestamp without time zone, + ts_replayed timestamp without time zone, + i_replayed bigint, + i_skipped bigint, + i_ddl bigint) +WITH (orientation=row, compression=no); + +CREATE UNIQUE INDEX idx_t_replica_batch_ts_created ON t_replica_batch USING btree (i_id_source, ts_created) TABLESPACE pg_default; + CREATE UNIQUE INDEX idx_t_replica_batch_binlog_name_position ON t_replica_batch USING btree (i_id_source, t_binlog_name, i_binlog_position) TABLESPACE pg_default; +ALTER TABLE t_replica_batch ADD CONSTRAINT pk_t_batch PRIMARY KEY USING btree (i_id_batch); + +INSERT INTO t_replica_batch +( + i_id_source, + t_binlog_name, + i_binlog_position, + t_gtid_set, + v_log_table +) +VALUES +( + 1, + 'on.000153', + 11432, + '57e77afd-510a-11ed-b66a-fa163e34abbc:1-101658', + 't_log_replica_mysql_2' +) RETURNING i_id_batch; + +INSERT INTO t_replica_batch +( + i_id_source, + t_binlog_name, + i_binlog_position, + t_gtid_set, + v_log_table +) +VALUES +( + i_id_source, + 'on.000153', + 11432, + '57e77afd-510a-11ed-b66a-fa163e34abbc:1-101658', + 't_log_replica_mysql_2' +) RETURNING i_id_batch; + +INSERT INTO t_replica_batch +( + i_id_source, + t_binlog_name, + i_binlog_position, + t_gtid_set, + v_log_table +) +VALUES +( + i_id_source + 2, + 'on.000153', + i_binlog_position, + '57e77afd-510a-11ed-b66a-fa163e34abbc:1-101658', + 't_log_replica_mysql_2' +) RETURNING i_id_batch; + -- jdbc case DROP USER IF EXISTS rightref CASCADE; CREATE USER rightref WITH PASSWORD 'rightref@123'; diff --git a/src/test/regress/output/insert_right_ref.source b/src/test/regress/output/insert_right_ref.source index 6310e670d..5f10a59ca 100644 --- a/src/test/regress/output/insert_right_ref.source +++ b/src/test/regress/output/insert_right_ref.source @@ -527,6 +527,92 @@ select * from other_notnull_t; $0.00 | empty | | | \x | (0,0) | [(0,0),(0,0)] | (0,0),(0,0) | ((0,0)) | ((0,0)) | <(0,0),0> | 0.0.0.0/32 | 0.0.0.0 | 00:00:00:00:00:00 | | | 00000000-0000-0000-0000-000000000000 | null | null | empty | empty | empty | empty | empty | \x | \x | beijing | | | 0000000000000000 | 00000000000000000000000000000000 | (2 rows) +-- test returning +CREATE TABLE t_replica_batch ( + i_id_batch serial NOT NULL, + i_id_source bigint NOT NULL, + t_binlog_name text, + v_log_table character varying DEFAULT 't_log_replica'::character varying NOT NULL, + i_binlog_position bigint, + t_gtid_set text, + b_started boolean DEFAULT false NOT NULL, + b_processed boolean DEFAULT false NOT NULL, + b_replayed boolean DEFAULT false NOT NULL, + ts_created timestamp without time zone DEFAULT clock_timestamp() NOT NULL, + ts_processed timestamp without time zone, + ts_replayed timestamp without time zone, + i_replayed bigint, + i_skipped bigint, + i_ddl bigint) +WITH (orientation=row, compression=no); +NOTICE: CREATE TABLE will create implicit sequence "t_replica_batch_i_id_batch_seq" for serial column "t_replica_batch.i_id_batch" +CREATE UNIQUE INDEX idx_t_replica_batch_ts_created ON t_replica_batch USING btree (i_id_source, ts_created) TABLESPACE pg_default; + CREATE UNIQUE INDEX idx_t_replica_batch_binlog_name_position ON t_replica_batch USING btree (i_id_source, t_binlog_name, i_binlog_position) TABLESPACE pg_default; +ALTER TABLE t_replica_batch ADD CONSTRAINT pk_t_batch PRIMARY KEY USING btree (i_id_batch); +NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "pk_t_batch" for table "t_replica_batch" +INSERT INTO t_replica_batch +( + i_id_source, + t_binlog_name, + i_binlog_position, + t_gtid_set, + v_log_table +) +VALUES +( + 1, + 'on.000153', + 11432, + '57e77afd-510a-11ed-b66a-fa163e34abbc:1-101658', + 't_log_replica_mysql_2' +) RETURNING i_id_batch; + i_id_batch +------------ + 1 +(1 row) + +INSERT INTO t_replica_batch +( + i_id_source, + t_binlog_name, + i_binlog_position, + t_gtid_set, + v_log_table +) +VALUES +( + i_id_source, + 'on.000153', + 11432, + '57e77afd-510a-11ed-b66a-fa163e34abbc:1-101658', + 't_log_replica_mysql_2' +) RETURNING i_id_batch; + i_id_batch +------------ + 2 +(1 row) + +INSERT INTO t_replica_batch +( + i_id_source, + t_binlog_name, + i_binlog_position, + t_gtid_set, + v_log_table +) +VALUES +( + i_id_source + 2, + 'on.000153', + i_binlog_position, + '57e77afd-510a-11ed-b66a-fa163e34abbc:1-101658', + 't_log_replica_mysql_2' +) RETURNING i_id_batch; + i_id_batch +------------ + 3 +(1 row) + -- jdbc case DROP USER IF EXISTS rightref CASCADE; NOTICE: role "rightref" does not exist, skipping