From 756c4f7b5ddc18cd00ba2c97fbcb730029f0072a Mon Sep 17 00:00:00 2001 From: suncan <1006949218@qq.com> Date: Fri, 2 Feb 2024 17:35:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=9A=E8=A1=A8=E6=9B=B4?= =?UTF-8?q?=E9=83=A8=E5=88=86=E8=A1=8C=E4=B8=BA=E4=B8=8Emysql=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=B7=AE=E5=BC=82=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 | 7 ++ src/test/regress/expected/multi_update.out | 83 ++++++++++++++++++++++ src/test/regress/sql/multi_update.sql | 34 +++++++++ 3 files changed, 124 insertions(+) diff --git a/src/common/backend/parser/analyze.cpp b/src/common/backend/parser/analyze.cpp index f0d0c3be7..f344e0476 100644 --- a/src/common/backend/parser/analyze.cpp +++ b/src/common/backend/parser/analyze.cpp @@ -4297,6 +4297,13 @@ static int fixUpdateResTargetName(ParseState* pstate, List* resultRelations, Res /* Mark the target column as requiring update permissions */ target_rte->updatedCols = bms_add_member(target_rte->updatedCols, attrno - FirstLowInvalidHeapAttributeNumber); + if (DB_IS_CMPT(B_FORMAT) && ((strcmp(rangeVar->relname, res->name) == 0) || + ((rangeVar->alias != NULL) && (strcmp((rangeVar->alias)->aliasname, res->name) == 0)))) { + if (matchRelname == true) { + removeRelname = true; + } + break; + } } if (matchRelname == true) { removeRelname = true; diff --git a/src/test/regress/expected/multi_update.out b/src/test/regress/expected/multi_update.out index 52c02736a..e3441000c 100644 --- a/src/test/regress/expected/multi_update.out +++ b/src/test/regress/expected/multi_update.out @@ -55,6 +55,89 @@ select * from t0; (2 rows) drop table t0; +drop table if exists tt0; +NOTICE: table "tt0" does not exist, skipping +create table tt0(a int, b int); +insert into tt0 values(1,2),(2,3); +begin; +update tt0 a0, tt0 a1 set a0.a=5; +select * from tt0; + a | b +---+--- + 5 | 2 + 5 | 3 +(2 rows) + +rollback; +begin; +update tt0 a, tt0 b set a.a=10; +select * from tt0; + a | b +----+--- + 10 | 2 + 10 | 3 +(2 rows) + +rollback; +drop table tt0; +create type newtype as(a int, b int); +create table test(a newtype,b int); +insert into test values(ROW(1,2),3); +update test set test.a=ROW(10,20); +select * from test; + a | b +---------+--- + (10,20) | 3 +(1 row) + +update test t set t.a=ROW(11,21); +select * from test; + a | b +---------+--- + (11,21) | 3 +(1 row) + +--Ambiguous scene +--update field a of column a rather than column a of table a +update test a set a.a=12; +NOTICE: update field 'a' of column 'a', though it's ambiguous. +--update field b of column a rather than column b of table a +update test a set a.b=22; +NOTICE: update field 'b' of column 'a', though it's ambiguous. +select * from test; + a | b +---------+--- + (12,22) | 3 +(1 row) + +--fail +update test a set a.a=ROW(13,23); +NOTICE: update field 'a' of column 'a', though it's ambiguous. +ERROR: subfield "a" is of type integer but expression is of type record +LINE 1: update test a set a.a=ROW(13,23); + ^ +HINT: You will need to rewrite or cast the expression. +CONTEXT: referenced column: a +update test a set a.c=10; +NOTICE: update field 'c' of column 'a', though it's ambiguous. +ERROR: cannot assign to field "c" of column "a" because there is no such column in data type newtype +LINE 1: update test a set a.c=10; + ^ +CONTEXT: referenced column: a +update test b set b.c=10; +ERROR: column "c" of relation "test" does not exist +LINE 1: update test b set b.c=10; + ^ +--must compatible with previous features, though not perfect +update test a set a.a.a=12; +select * from test; + a | b +---------+--- + (12,22) | 3 +(1 row) + +drop table test; +drop type newtype; -- three relation drop table if exists t_t_mutil_t1; NOTICE: table "t_t_mutil_t1" does not exist, skipping diff --git a/src/test/regress/sql/multi_update.sql b/src/test/regress/sql/multi_update.sql index e0ad8720f..029b25b31 100644 --- a/src/test/regress/sql/multi_update.sql +++ b/src/test/regress/sql/multi_update.sql @@ -12,6 +12,40 @@ insert into t0 values(25, -8, -88, -8),(-88, -77, 25, -8); update t0 a, t0 b set b.c1=10, a.c2=200, b.c3=20, a.c4=100; select * from t0; drop table t0; +drop table if exists tt0; +create table tt0(a int, b int); +insert into tt0 values(1,2),(2,3); +begin; +update tt0 a0, tt0 a1 set a0.a=5; +select * from tt0; +rollback; +begin; +update tt0 a, tt0 b set a.a=10; +select * from tt0; +rollback; +drop table tt0; +create type newtype as(a int, b int); +create table test(a newtype,b int); +insert into test values(ROW(1,2),3); +update test set test.a=ROW(10,20); +select * from test; +update test t set t.a=ROW(11,21); +select * from test; +--Ambiguous scene +--update field a of column a rather than column a of table a +update test a set a.a=12; +--update field b of column a rather than column b of table a +update test a set a.b=22; +select * from test; +--fail +update test a set a.a=ROW(13,23); +update test a set a.c=10; +update test b set b.c=10; +--must compatible with previous features, though not perfect +update test a set a.a.a=12; +select * from test; +drop table test; +drop type newtype; -- three relation drop table if exists t_t_mutil_t1; drop table if exists t_t_mutil_t2;