解决多表更部分行为与mysql存在差异问题

This commit is contained in:
suncan
2024-02-02 17:35:59 +08:00
committed by totaj
parent 4bdbf23d8e
commit 756c4f7b5d
3 changed files with 124 additions and 0 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;