Search Postgresql Archives

Re: Curious why planner can't handle NOT IN

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Yang Zhang <yanghatespam@xxxxxxxxx> writes:
> The most obvious query doesn't work so hot due to repeated execution
> of the subplan:

> => explain insert into newaccount select * from account where id not
> in (select id from account);

Yeah.  Try using a NOT EXISTS instead.

> This isn't a big deal as there's a straightforward workaround, but I
> am curious what happened here.  Googling turns up various mentions of
> "NOT IN" with poor plans that involve subplans.  Then again I have
> read mention of hash anti-join which seems appropriate here(?), but
> that wasn't used here

The trouble with NOT IN is that it's not exactly the same as an
antijoin, because of the spec-mandated bizarre behavior for NULLs.
It's very difficult to optimize it to any extent without producing
wrong answers.  NOT EXISTS avoids that problem.

			regards, tom lane


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux