fix problem that startwith result not correct while cte and subquery nesting

This commit is contained in:
yanghao 2022-03-17 10:12:07 +08:00
parent 9963364bfa
commit 53e0d681cf
3 changed files with 20 additions and 0 deletions

View File

@ -331,6 +331,11 @@ void AddStartWithTargetRelInfo(ParseState* pstate, Node* relNode,
startInfo->aliasname = sub->alias->aliasname;
}
SelectStmt *substmt = (SelectStmt*)sub->subquery;
if (substmt->withClause == NULL) {
substmt->withClause = (WithClause*)copyObject(pstate->origin_with);
}
startInfo->rte = rte;
startInfo->rtr = rtr;
startInfo->rtekind = rte->rtekind;

View File

@ -1415,3 +1415,13 @@ LIMIT 169;
----
(0 rows)
create table t123(id int, lid int, name text);
insert into t123 values(1,null,'A'),(2,1,'B'),(3,2,'C');
with t2 as (select * from t123 where id!=10) select level,t.* from (select * from t2 where id!=10 order by id) t start with t.id=2 connect by prior t.id=t.lid;
level | id | lid | name
-------+----+-----+------
1 | 2 | 1 | B
2 | 3 | 2 | C
(2 rows)
drop table t123;

View File

@ -501,3 +501,8 @@ WHERE true CONNECT BY EXISTS (
test_hcb_ptb as ref_7
)
LIMIT 169;
create table t123(id int, lid int, name text);
insert into t123 values(1,null,'A'),(2,1,'B'),(3,2,'C');
with t2 as (select * from t123 where id!=10) select level,t.* from (select * from t2 where id!=10 order by id) t start with t.id=2 connect by prior t.id=t.lid;
drop table t123;