Re: "SELECT .. WHERE NOT IN" query running for hours

From: Scott Carey <scott(at)richrelevance(dot)com>
To: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, ??????? ???????? <lebiathan(at)gmail(dot)com>, Mladen Gogala <mladen(dot)gogala(at)vmsinfo(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: "SELECT .. WHERE NOT IN" query running for hours
Date: 2011-01-10 21:05:04
Message-ID: C950B38E.18665%scott@richrelevance.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 1/10/11 12:37 PM, "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> wrote:

>Scott Carey <scott(at)richrelevance(dot)com> wrote:
>
>> Often, the best query plans result from 'LEFT JOIN WHERE right
>> side is NULL' rather than NOT EXISTS however. I often get
>> performance gains by switching NOT EXISTS queries to LEFT JOIN
>> form.
>
>Even in 8.4 and later? I would think that the anti-join that Tom
>added in 8.4 would always perform at least as well as the LEFT JOIN
>technique you describe.
>
>-Kevin

Yes, in 8.4. The query planner definitely does not treat the two as
equivalent. I don't have a concrete example at hand right now, but I've
been working exclusively on 8.4 since a month after it was released. It
does often use an anti-join for NOT EXISTS, but does not seem to explore
all avenues there. Or perhaps the statistics it has differ for some
reason at that point. All I know, is that the resulting query plan
differs sometimes and I'd say 3 out of 4 times the LEFT JOIN variant is
more optimal when they differ.

>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Rauan Maemirov 2011-01-11 08:16:10 Re: Problems with FTS
Previous Message Kevin Grittner 2011-01-10 20:37:50 Re: "SELECT .. WHERE NOT IN" query running for hours