CTE optimization fence - Mailing list pgsql-general

From Guy Burgess
Subject CTE optimization fence
Date
Msg-id ce9c1fb9-c309-f666-3221-5d5f9e66051e@burgess.co.nz
Whole thread Raw
Responses Re: CTE optimization fence  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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



pgsql-general by date:

Previous
From: Melvin Davidson
Date:
Subject: Re: We find few queries running three times simultaneously with sameparameters on postgres db
Next
From: Tom Lane
Date:
Subject: Re: CTE optimization fence