Re: Optimizing NOT IN plans / verify rewrite

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: <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 19:29:29
Message-ID: 4C56D6490200002500034093@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Maciek Sakrejda <msakrejda(at)truviso(dot)com> wrote:

> DELETE FROM foo WHERE type = 'o' AND b NOT IN (SELECT cqc.b FROM
> bar cqc) AND b NOT IN (SELECT car.b FROM foo car WHERE car.type !=
> 'o');

Can "b" be null in any of these tables? If not, then you can
rewrite your query to us NOT EXISTS and have the same semantics.
That will often be much faster. Something like:

DELETE FROM foo
WHERE type = 'o'
AND NOT EXISTS (SELECT * FROM bar cqc where cqc.b = foo.b)
AND NOT EXISTS (SELECT * FROM foo car WHERE car.b = foo.b
AND car.type <> 'o');

-Kevin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Maciek Sakrejda 2010-08-02 19:42:43 Re: Optimizing NOT IN plans / verify rewrite
Previous Message Maciek Sakrejda 2010-08-02 19:12:51 Optimizing NOT IN plans / verify rewrite