Re: Assert failure in CTE inlining with view and correlated subquery

2022-04-21 Thread Tom Lane
Tomas Vondra writes: > On 4/21/22 21:03, Tom Lane wrote: >> I think we should just drop this cross-check altogether; it is not nearly >> useful enough to justify the work that'd be involved in maintaining >> cterefcount accurately for all such transformations. All it's really >> there for is to b

Re: Assert failure in CTE inlining with view and correlated subquery

2022-04-21 Thread Tomas Vondra
On 4/21/22 21:03, Tom Lane wrote: > Tomas Vondra writes: >> On 4/21/22 10:29, Richard Guo wrote: >>> Further debugging shows that in this repro the reference to the CTE is >>> removed when generating paths for the subquery 'sub', where we would try >>> to remove subquery targetlist items that are

Re: Assert failure in CTE inlining with view and correlated subquery

2022-04-21 Thread Tom Lane
Tomas Vondra writes: > On 4/21/22 10:29, Richard Guo wrote: >> Further debugging shows that in this repro the reference to the CTE is >> removed when generating paths for the subquery 'sub', where we would try >> to remove subquery targetlist items that are not needed. So for the >> items we are t

Re: Assert failure in CTE inlining with view and correlated subquery

2022-04-21 Thread Tomas Vondra
On 4/21/22 10:29, Richard Guo wrote: > > On Thu, Apr 21, 2022 at 3:51 PM Richard Guo > wrote: > > > On Thu, Apr 21, 2022 at 5:33 AM Tomas Vondra > > wrote: > > > it seems there's something wrong with CTE

Re: Assert failure in CTE inlining with view and correlated subquery

2022-04-21 Thread Richard Guo
On Thu, Apr 21, 2022 at 3:51 PM Richard Guo wrote: > > On Thu, Apr 21, 2022 at 5:33 AM Tomas Vondra < > tomas.von...@enterprisedb.com> wrote: > >> >> it seems there's something wrong with CTE inlining when there's a view >> containing a correlated subquery referencing the CTE. >> > > BTW, seems v

Re: Assert failure in CTE inlining with view and correlated subquery

2022-04-21 Thread Richard Guo
On Thu, Apr 21, 2022 at 5:33 AM Tomas Vondra wrote: > > it seems there's something wrong with CTE inlining when there's a view > containing a correlated subquery referencing the CTE. > BTW, seems view is not a necessary condition to reproduce this issue. For instance: create table t (a int, b i

Re: Assert failure in CTE inlining with view and correlated subquery

2022-04-21 Thread Richard Guo
On Thu, Apr 21, 2022 at 5:33 AM Tomas Vondra wrote: > > The difference between plans in (2) and (3) is interesting, because it > seems the CTE got inlined, so why was the refcount not decremented? > The query is not actually referencing the cte. So the cte range table entry would not appear anyw

Assert failure in CTE inlining with view and correlated subquery

2022-04-20 Thread Tomas Vondra
Hi, it seems there's something wrong with CTE inlining when there's a view containing a correlated subquery referencing the CTE. Consider a simple example like this: create table results ( id serial primary key, run text, tps float4 ); creat