From acb27f93b4586690f3099e951ef1d8839ef81fea Mon Sep 17 00:00:00 2001 From: laishenghao Date: Tue, 29 Nov 2022 16:06:14 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90bugfixed=E3=80=91=E8=A7=A3=E5=86=B3cte?= =?UTF-8?q?+connect=20by=E8=AF=AD=E5=8F=A5sql=E6=89=A7=E8=A1=8C=E6=8A=A5?= =?UTF-8?q?=E9=94=99=EF=BC=8C=E6=89=BE=E4=B8=8D=E5=88=B0relation=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/parse_startwith.cpp | 5 +---- src/test/regress/expected/sw_basic.out | 13 +++++++++++++ src/test/regress/sql/sw_basic.sql | 13 +++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/common/backend/parser/parse_startwith.cpp b/src/common/backend/parser/parse_startwith.cpp index 15d8d1eff..45e8c93b6 100644 --- a/src/common/backend/parser/parse_startwith.cpp +++ b/src/common/backend/parser/parse_startwith.cpp @@ -1280,10 +1280,7 @@ static void AddWithClauseToBranch(ParseState *pstate, SelectStmt *stmt, List *re foreach(lc2, clause->ctes) { CommonTableExpr *cte = (CommonTableExpr *)lfirst(lc2); - - if (pg_strcasecmp(cte->ctename, info->relname) == 0) { - ctes = lappend(ctes, cte); - } + ctes = lappend(ctes, cte); } foreach(lc2, pstate->p_ctenamespace) { diff --git a/src/test/regress/expected/sw_basic.out b/src/test/regress/expected/sw_basic.out index e4016470d..9e0c67ac6 100644 --- a/src/test/regress/expected/sw_basic.out +++ b/src/test/regress/expected/sw_basic.out @@ -628,3 +628,16 @@ reset enable_startwith_debug; LOG: statement: reset enable_startwith_debug; reset client_min_messages; LOG: statement: reset client_min_messages; +-- bugfixed I61AIW: cte+connect by error, cannot find relation +create table temptest (col numeric(3)); +insert into temptest values ('1'),('2'),('3'),('4'),(''); +WITH alias5 AS ( SELECT alias1.col AS alias2 FROM temptest AS alias1 CONNECT BY nocycle alias1.col >= alias1.col ), + alias8 AS ( SELECT * FROM alias5 CONNECT BY nocycle PRIOR alias5.alias2 != alias5.alias2) + SELECT * FROM alias8, temptest CONNECT BY nocycle PRIOR temptest.col < temptest.col; +ERROR: Current Start With...Connect by has exceeded max iteration times 200 +HINT: Please check your connect by clause carefully +WITH alias5 AS ( SELECT alias1.col AS alias2 FROM temptest AS alias1 CONNECT BY nocycle alias1.col >= alias1.col ) +SELECT * FROM alias5, temptest CONNECT BY nocycle PRIOR temptest.col < temptest.col; +ERROR: Current Start With...Connect by has exceeded max iteration times 200 +HINT: Please check your connect by clause carefully +drop table temptest; diff --git a/src/test/regress/sql/sw_basic.sql b/src/test/regress/sql/sw_basic.sql index 2b5d67771..e483a60e7 100644 --- a/src/test/regress/sql/sw_basic.sql +++ b/src/test/regress/sql/sw_basic.sql @@ -180,3 +180,16 @@ order siblings by id; reset enable_startwith_debug; reset client_min_messages; + +-- bugfixed I61AIW: cte+connect by error, cannot find relation +create table temptest (col numeric(3)); +insert into temptest values ('1'),('2'),('3'),('4'),(''); + +WITH alias5 AS ( SELECT alias1.col AS alias2 FROM temptest AS alias1 CONNECT BY nocycle alias1.col >= alias1.col ), + alias8 AS ( SELECT * FROM alias5 CONNECT BY nocycle PRIOR alias5.alias2 != alias5.alias2) + SELECT * FROM alias8, temptest CONNECT BY nocycle PRIOR temptest.col < temptest.col; + +WITH alias5 AS ( SELECT alias1.col AS alias2 FROM temptest AS alias1 CONNECT BY nocycle alias1.col >= alias1.col ) +SELECT * FROM alias5, temptest CONNECT BY nocycle PRIOR temptest.col < temptest.col; + +drop table temptest;