!2461 【bugfix】解决cte+connect by语句sql执行报错,找不到relation的问题

Merge pull request !2461 from laishenghao/cte-connect
This commit is contained in:
opengauss-bot
2022-11-29 12:11:23 +00:00
committed by Gitee
3 changed files with 27 additions and 4 deletions

View File

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

View File

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

View File

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