Yang Zhang <[email protected]> writes:
> On Thu, Sep 15, 2011 at 1:22 AM, Tomas Vondra <[email protected]> wrote:
>> [ use a left join instead of NOT IN ]
> This worked great, thank you. Too bad the planner isn't smart enough
> to do this yet!
It never will be, because they're not equivalent queries. NOT IN has
different (and very hard-to-optimize) behavior in the face of NULLs in
the right-hand table.
The moral of the story is avoid NOT IN. You could use NOT EXISTS,
which is less of a notational change than recasting as a left join.
regards, tom lane
--
Sent via pgsql-general mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general