Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-23 Thread Bruce Momjian
On Tue, Nov 20, 2012 at 02:24:01PM -0600, Merlin Moncure wrote: On Tue, Nov 20, 2012 at 1:53 PM, Jon Nelson jnelson+pg...@jamponi.net wrote: As can be seen by the current conversation, not everyone is convinced that CTEs ought to be an explicit optimization barrier On Tue, Nov 20, 2012 at

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-22 Thread Vitalii Tymchyshyn
I'd also add ANALYZED/NOT ANALYZED. This should force it behave like 'create table, analyze, select' with statistics used in second query plan. P.S. defaults can be configurable. 20 лист. 2012 02:22, Gavin Flower gavinflo...@archidevsys.co.nz напис. On 15/11/12 15:03, Peter Geoghegan wrote:

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-20 Thread Merlin Moncure
On Wed, Nov 14, 2012 at 8:03 PM, Peter Geoghegan pe...@2ndquadrant.com wrote: On 15 November 2012 01:46, Andrew Dunstan and...@dunslane.net wrote: It cuts both ways. I have used CTEs a LOT precisely because this behaviour lets me get better plans. Without that I'll be back to using the offset 0

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-20 Thread Claudio Freire
On Tue, Nov 20, 2012 at 4:22 PM, Merlin Moncure mmonc...@gmail.com wrote: On Wed, Nov 14, 2012 at 8:03 PM, Peter Geoghegan pe...@2ndquadrant.com wrote: On 15 November 2012 01:46, Andrew Dunstan and...@dunslane.net wrote: It cuts both ways. I have used CTEs a LOT precisely because this

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-20 Thread Jon Nelson
My perspective on this is that CTEs *should* be just like creating a temporary table and then joining to it, but without the materialization costs. In that respect, they seem like they should be like nifty VIEWs. If I wanted the behavior of materialization and then join, I'd do that explicitly

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-20 Thread Merlin Moncure
On Tue, Nov 20, 2012 at 1:53 PM, Jon Nelson jnelson+pg...@jamponi.net wrote: As can be seen by the current conversation, not everyone is convinced that CTEs ought to be an explicit optimization barrier On Tue, Nov 20, 2012 at 1:26 PM, Claudio Freire klaussfre...@gmail.com wrote: It *could* just

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-20 Thread Claudio Freire
On Tue, Nov 20, 2012 at 5:24 PM, Merlin Moncure mmonc...@gmail.com wrote: On Tue, Nov 20, 2012 at 1:53 PM, Jon Nelson jnelson+pg...@jamponi.net wrote: As can be seen by the current conversation, not everyone is convinced that CTEs ought to be an explicit optimization barrier On Tue, Nov 20,

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-20 Thread Tom Lane
Jon Nelson jnelson+pg...@jamponi.net writes: ... Perhaps even including a small blurb about what an optimization barrier even means (my understanding is that it merely forces materialization of that part of the query). FWIW, it has nothing to do with materialization; it means that we don't

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-19 Thread Gavin Flower
On 15/11/12 15:03, Peter Geoghegan wrote: On 15 November 2012 01:46, Andrew Dunstan and...@dunslane.net wrote: It cuts both ways. I have used CTEs a LOT precisely because this behaviour lets me get better plans. Without that I'll be back to using the offset 0 hack. Is the OFFSET 0 hack really

SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-14 Thread David Greco
-Original Message- From: Andrew Dunstan [mailto:and...@dunslane.net] Sent: Wednesday, November 14, 2012 11:08 AM To: David Greco Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] Poor performance using CTE On 11/14/2012 10:56 AM, David Greco wrote: You're right. I was

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-14 Thread Tom Lane
David Greco david_gr...@harte-hanks.com writes: Thanks, that did the trick. Though I'm still not clear as to why. PG treats WITH as an optimization fence --- the WITH query will be executed pretty much as-is. It may be that Oracle flattens the query somehow; though if you're using black-box

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-14 Thread Craig Ringer
On 11/15/2012 12:29 AM, Tom Lane wrote: David Greco david_gr...@harte-hanks.com writes: Thanks, that did the trick. Though I'm still not clear as to why. PG treats WITH as an optimization fence --- the WITH query will be executed pretty much as-is. It may be that Oracle flattens the query

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-14 Thread Tom Lane
Craig Ringer cr...@2ndquadrant.com writes: I was looking through the latest spec drafts I have access to and couldn't find any reference to Pg's optimisation-fence-for-CTEs behaviour being required by the standard, though I've repeatedly seen it said that there is such a requirement. I don't

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-14 Thread Andrew Dunstan
On 11/14/2012 08:17 PM, Craig Ringer wrote: On 11/15/2012 12:29 AM, Tom Lane wrote: David Greco david_gr...@harte-hanks.com writes: Thanks, that did the trick. Though I'm still not clear as to why. PG treats WITH as an optimization fence --- the WITH query will be executed pretty much as-is.

Re: SOLVED - RE: [PERFORM] Poor performance using CTE

2012-11-14 Thread Peter Geoghegan
On 15 November 2012 01:46, Andrew Dunstan and...@dunslane.net wrote: It cuts both ways. I have used CTEs a LOT precisely because this behaviour lets me get better plans. Without that I'll be back to using the offset 0 hack. Is the OFFSET 0 hack really so bad? We've been telling people to do