From 03894838fa30b1ec12552fa4ad6c580c251e7734 Mon Sep 17 00:00:00 2001 From: "changying.yue" Date: Sat, 6 May 2023 09:35:57 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwith=20for=20update=E7=9A=84?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=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/gram.y | 6 +- src/test/regress/expected/xc_dml.out | 91 ++++++++++++++++++++++++++++ src/test/regress/sql/xc_dml.sql | 40 ++++++++++++ 3 files changed, 134 insertions(+), 3 deletions(-) diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index 55cb30706e..fb5a3e4076 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -23070,7 +23070,7 @@ select_no_parens: (Node*)list_nth($5, 0), (Node*)list_nth($5, 1), $1, yyscanner); - $$ = processIntoClauseInSelectStmt((SelectStmt *) $1, (IntoClause *) $6); + $$ = processIntoClauseInSelectStmt((SelectStmt *) $2, (IntoClause *) $6); } | with_clause select_clause opt_sort_clause select_limit for_locking_clause into_clause { @@ -23079,7 +23079,7 @@ select_no_parens: (Node*)list_nth($4, 0), (Node*)list_nth($4, 1), $1, yyscanner); - $$ = processIntoClauseInSelectStmt((SelectStmt *) $1, (IntoClause *) $6); + $$ = processIntoClauseInSelectStmt((SelectStmt *) $2, (IntoClause *) $6); } | with_clause select_clause opt_sort_clause opt_select_limit into_clause opt_for_locking_clause { @@ -23088,7 +23088,7 @@ select_no_parens: (Node*)list_nth($4, 0), (Node*)list_nth($4, 1), $1, yyscanner); - $$ = processIntoClauseInSelectStmt((SelectStmt *) $1, (IntoClause *) $5); + $$ = processIntoClauseInSelectStmt((SelectStmt *) $2, (IntoClause *) $5); } | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause { diff --git a/src/test/regress/expected/xc_dml.out b/src/test/regress/expected/xc_dml.out index 5bc733c4b4..a5aad51e8a 100644 --- a/src/test/regress/expected/xc_dml.out +++ b/src/test/regress/expected/xc_dml.out @@ -1742,3 +1742,94 @@ DROP TABLE parent_replica_table; -- DROP TABLE UPDATE_XC_C; DROP TABLE UPDATE_XC_D; +-- +-- create some tables +-- +create table t1(val int, val2 int); +create table t2(val int, val2 int); +create table t3(val int, val2 int); +create table p1(a int, b int); +create table c1(a int, b int,d int, e int); +-- insert some rows in them +insert into t1 values(1,11),(2,11); +insert into t2 values(3,11),(4,11); +insert into t3 values(5,11),(6,11); +insert into p1 values(55,66),(77,88),(111,222),(123,345); +insert into c1 values(111,222,333,444),(123,345,567,789); +select * from t1 order by val; + val | val2 +-----+------ + 1 | 11 + 2 | 11 +(2 rows) + +select * from t2 order by val; + val | val2 +-----+------ + 3 | 11 + 4 | 11 +(2 rows) + +select * from t3 order by val; + val | val2 +-----+------ + 5 | 11 + 6 | 11 +(2 rows) + +select * from p1 order by a; + a | b +-----+----- + 55 | 66 + 77 | 88 + 111 | 222 + 123 | 345 +(4 rows) + +select * from c1 order by a; + a | b | d | e +-----+-----+-----+----- + 111 | 222 | 333 | 444 + 123 | 345 | 567 | 789 +(2 rows) + +-- test a few queries with row marks +select * from t1 order by 1 for update of t1 nowait; + val | val2 +-----+------ + 1 | 11 + 2 | 11 +(2 rows) + +select * from t1, t2, t3 order by 1 for update; + val | val2 | val | val2 | val | val2 +-----+------+-----+------+-----+------ + 1 | 11 | 3 | 11 | 5 | 11 + 1 | 11 | 3 | 11 | 6 | 11 + 1 | 11 | 4 | 11 | 5 | 11 + 1 | 11 | 4 | 11 | 6 | 11 + 2 | 11 | 3 | 11 | 5 | 11 + 2 | 11 | 3 | 11 | 6 | 11 + 2 | 11 | 4 | 11 | 5 | 11 + 2 | 11 | 4 | 11 | 6 | 11 +(8 rows) + +WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1,t2 order by 1 FOR UPDATE; +ERROR: SELECT FOR UPDATE/SHARE cannot be applied to a WITH query +WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1; + val | val2 +-----+------ + 1 | 11 + 2 | 11 +(2 rows) + +WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1 FOR UPDATE; +ERROR: SELECT FOR UPDATE/SHARE cannot be applied to a WITH query +WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1 FOR UPDATE; +ERROR: SELECT FOR UPDATE/SHARE cannot be applied to a WITH query +-- drop objects created +drop table c1; +drop table p1; +drop table t1; +drop table t2; +drop table t3; diff --git a/src/test/regress/sql/xc_dml.sql b/src/test/regress/sql/xc_dml.sql index 70c059a77d..f8c28f698b 100644 --- a/src/test/regress/sql/xc_dml.sql +++ b/src/test/regress/sql/xc_dml.sql @@ -350,3 +350,43 @@ DROP TABLE parent_replica_table; DROP TABLE UPDATE_XC_C; DROP TABLE UPDATE_XC_D; +-- +-- create some tables +-- +create table t1(val int, val2 int); +create table t2(val int, val2 int); +create table t3(val int, val2 int); + +create table p1(a int, b int); +create table c1(a int, b int,d int, e int); + +-- insert some rows in them +insert into t1 values(1,11),(2,11); +insert into t2 values(3,11),(4,11); +insert into t3 values(5,11),(6,11); + +insert into p1 values(55,66),(77,88),(111,222),(123,345); +insert into c1 values(111,222,333,444),(123,345,567,789); + +select * from t1 order by val; +select * from t2 order by val; +select * from t3 order by val; +select * from p1 order by a; +select * from c1 order by a; + +-- test a few queries with row marks +select * from t1 order by 1 for update of t1 nowait; +select * from t1, t2, t3 order by 1 for update; + +WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1,t2 order by 1 FOR UPDATE; + +WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1; +WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1 FOR UPDATE; +WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1 FOR UPDATE; + +-- drop objects created +drop table c1; +drop table p1; +drop table t1; +drop table t2; +drop table t3; -- Gitee