Re: SOLVED - RE: Poor performance using CTE

From: Claudio Freire <klaussfreire(at)gmail(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Peter Geoghegan <peter(at)2ndquadrant(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Craig Ringer <craig(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, David Greco <David_Greco(at)harte-hanks(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: SOLVED - RE: Poor performance using CTE
Date: 2012-11-20 19:26:09
Message-ID: CAGTBQpY=7vJOCbypUs8kD0ii5rSAYOR5WpA8z1bMduYKphL+xA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, Nov 20, 2012 at 4:22 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> On Wed, Nov 14, 2012 at 8:03 PM, Peter Geoghegan <peter(at)2ndquadrant(dot)com> wrote:
>> On 15 November 2012 01:46, Andrew Dunstan <andrew(at)dunslane(dot)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
>> that for years, so it's already something that we've effectively
>> committed to.
>
> IMSNHO, 'OFFSET 0' is completely unreadable black magic. I agree with
> Andrew: CTEs allow for manual composition of queries and can be the
> best tool when the planner is outsmarting itself. In the old days,
> we'd extract data to a temp table and join against that: CTE are
> essentially a formalization of that technique. I like things the way
> they are; if CTE are hurting your plan, that's an indication you're
> using them inappropriately.

I agree, **BUT**, I cannot imagine how pushing constraints to the CTE
(under adequate conditions) could be anything but beneficial.

It *could* just be a lack of imagination on my part. But if it were
not, then it'd be nice for it to be done automatically (since this
particular CTE behavior bites enough people already).

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Jon Nelson 2012-11-20 19:53:30 Re: SOLVED - RE: Poor performance using CTE
Previous Message Merlin Moncure 2012-11-20 19:22:50 Re: SOLVED - RE: Poor performance using CTE