Re: BUG #17721: A completely unused CTE negatively affect Query Plan

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: nh(dot)dev(at)sturdy(dot)ai
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17721: A completely unused CTE negatively affect Query Plan
Date: 2022-12-14 18:25:28
Message-ID: 2784036.1671042328@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> I've boiled down an issue we have in production to a simple query that can
> demonstrate it. I've run this on 13,14 and 15 locally in a docker container
> with the same results. If a CTE that is completely unexecuted exists in a
> subquery (or view in our production case) it affects the query plan VERY
> negatively. The first explain shows a sequential scan, where the second
> explain shows an index scan, just by the existence of the (obviously)
> unexecuted CTE.

The presence of the CTE prevents flattening of the subquery.
If you don't like it, don't attach the CTE right there.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Mats Kindahl 2022-12-14 21:14:19 Re: Crash during backend start when low on memory
Previous Message PG Bug reporting form 2022-12-14 17:41:37 BUG #17721: A completely unused CTE negatively affect Query Plan