Re: Optimizing NOT IN plans / verify rewrite

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Dave Crooke" <dcrooke(at)gmail(dot)com>
Cc: <pgsql-performance(at)postgresql(dot)org>, "Maciek Sakrejda" <msakrejda(at)truviso(dot)com>
Subject: Re: Optimizing NOT IN plans / verify rewrite
Date: 2010-08-02 21:03:05
Message-ID: 4C56EC3902000025000340B8@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Dave Crooke <dcrooke(at)gmail(dot)com> wrote:

> With Oracle, I've found an anti-union (MINUS in Oracle, EXCEPT in
> PGSQL) to be often a bit better than an anti-join, which is in
> turn faster than NOT IN. Depends of course on row distribution and
> index layouts, and a bunch of other details.

I found that assertion intriguing, so I tested the "fast" query from
the original post against my suggestion and a version using EXCEPT.
(This was against the development HEAD, not any release.)

OP "fast": 32.9 seconds
NOT EXISTS: 11.2 seconds
EXCEPT: 7.7 seconds

That last was using this query, which just might work OK on 8.3:

DELETE FROM foo
where foo.b in (
select b from foo WHERE type = 'o'
except SELECT b FROM bar
except SELECT b FROM foo where type <> 'o');

I wonder whether this could make a reasonable alternative plan for
the optmizer to consider some day....

-Kevin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Peter Hussey 2010-08-02 21:23:05 Re: Questions on query planner, join types, and work_mem
Previous Message Maciek Sakrejda 2010-08-02 20:35:13 Re: Optimizing NOT IN plans / verify rewrite