pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
CTE optimization fence
4+ messages / 4 participants
[nested] [flat]

* CTE optimization fence
@ 2018-06-27 03:42 Guy Burgess <guy@burgess.co.nz>
  2018-06-27 03:48 ` Re: CTE optimization fence Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Guy Burgess @ 2018-06-27 03:42 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hello,
I am running into performance issues with large CTE "WITH" queries (just 
for selecting, not updating).  I was surprised to find that the queries 
run much faster if I convert the CTEs to subqueries. From googling, I 
see that this is due to CTE acting as an optimization fence in PG. 
Unfortunately due to the application I'm dealing with, converting all 
CTE queries to subquery model is not feasible. Plus, the readability of 
CTE is a big bonus.

I see there was some discussion last year about removing the CTE 
optimization fence (e.g. 
http://www.postgresql-archive.org/CTE-inlining-td5958992.html) but can't 
find anything more recent. Does anyone know if this is still under 
consideration? For what it's worth, I would love some way to make CTEs 
inlined/optimized.

Thank you very much to the developers for a truly amazing database system.

Thanks
Guy





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: CTE optimization fence
  2018-06-27 03:42 CTE optimization fence Guy Burgess <guy@burgess.co.nz>
@ 2018-06-27 03:48 ` Tom Lane <tgl@sss.pgh.pa.us>
  2018-06-27 05:45   ` Re: CTE optimization fence Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2018-06-27 03:48 UTC (permalink / raw)
  To: Guy Burgess <guy@burgess.co.nz>; +Cc: pgsql-general@lists.postgresql.org

Guy Burgess <guy@burgess.co.nz> writes:
> I see there was some discussion last year about removing the CTE 
> optimization fence (e.g. 
> http://www.postgresql-archive.org/CTE-inlining-td5958992.html) but can't 
> find anything more recent. Does anyone know if this is still under 
> consideration?

Nothing's actually happened since then ... it's still under consideration,
but we have to settle on a way of controlling it.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: CTE optimization fence
  2018-06-27 03:42 CTE optimization fence Guy Burgess <guy@burgess.co.nz>
  2018-06-27 03:48 ` Re: CTE optimization fence Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-06-27 05:45   ` Thomas Kellerer <spam_eater@gmx.net>
  2018-06-27 06:27     ` Re: CTE optimization fence Rob Sargent <robjsargent@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Thomas Kellerer @ 2018-06-27 05:45 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Tom Lane schrieb am 27.06.2018 um 05:48:
>> I see there was some discussion last year about removing the CTE 
>> optimization fence (e.g. 
>> http://www.postgresql-archive.org/CTE-inlining-td5958992.html) but can't 
>> find anything more recent. Does anyone know if this is still under 
>> consideration?
> 
> but we have to settle on a way of controlling it.

+1 from me. 

I am running more and more into situations where people consider this a bug rather than a feature.

FWIW, I think a GUC that switches between the current (mostly unwanted, at least surprising) 
way and one where the CTE is optimized together with the main query would suit "most" people.

For sake of compatibility this could default to the current behaviour




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: CTE optimization fence
  2018-06-27 03:42 CTE optimization fence Guy Burgess <guy@burgess.co.nz>
  2018-06-27 03:48 ` Re: CTE optimization fence Tom Lane <tgl@sss.pgh.pa.us>
  2018-06-27 05:45   ` Re: CTE optimization fence Thomas Kellerer <spam_eater@gmx.net>
@ 2018-06-27 06:27     ` Rob Sargent <robjsargent@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Rob Sargent @ 2018-06-27 06:27 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; +Cc: pgsql-general@lists.postgresql.org

I don’t think the fence analogy works. Try wall (a la Berlin). 
I count myself amongst those who thought “Ooh this little CTE will garner just what the rest of the query needs”. Only to find the planner didn’t groc that optimization. 

Is it a matter of deciding to trust the SQLer and runtime analyzing the CTE product before continuing? As an SQLer I have doubts about that precept but without _some_ change in attack CTEs approach fluff. 

> On Jun 26, 2018, at 11:45 PM, Thomas Kellerer <spam_eater@gmx.net> wrote:
> 
> Tom Lane schrieb am 27.06.2018 um 05:48:
>>> I see there was some discussion last year about removing the CTE 
>>> optimization fence (e.g. 
>>> http://www.postgresql-archive.org/CTE-inlining-td5958992.html) but can't 
>>> find anything more recent. Does anyone know if this is still under 
>>> consideration?
>> 
>> but we have to settle on a way of controlling it.
> 
> +1 from me. 
> 
> I am running more and more into situations where people consider this a bug rather than a feature.
> 
> FWIW, I think a GUC that switches between the current (mostly unwanted, at least surprising) 
> way and one where the CTE is optimized together with the main query would suit "most" people.
> 
> For sake of compatibility this could default to the current behaviour
> 




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2018-06-27 06:27 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-06-27 03:42 CTE optimization fence Guy Burgess <guy@burgess.co.nz>
2018-06-27 03:48 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-06-27 05:45   ` Thomas Kellerer <spam_eater@gmx.net>
2018-06-27 06:27     ` Rob Sargent <robjsargent@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox