diff --git a/src/common/backend/parser/parse_startwith.cpp b/src/common/backend/parser/parse_startwith.cpp index 7d244031e..260ec42bb 100644 --- a/src/common/backend/parser/parse_startwith.cpp +++ b/src/common/backend/parser/parse_startwith.cpp @@ -1482,10 +1482,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;