Re: Interesting Query Performance Question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David W Noon <dwnoon(at)ntlworld(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Interesting Query Performance Question
Date: 2010-11-06 17:12:18
Message-ID: 21222.1289063538@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

David W Noon <dwnoon(at)ntlworld(dot)com> writes:
> On Sat, 06 Nov 2010 11:59:48 -0400, Tom Lane wrote about Re: [ADMIN]
>> In general, NOT IN is hard to optimize because of its weird behavior
>> for NULLs. I'd suggest looking into converting the query to use an
>> EXISTS instead.

> I have know about that issue for some years, so I always use a column
> that has been declared NOT NULL for the sub-query. Does PostgreSQL not
> use that property to bypass the vagaries of NULL in an IN predicate?

No. It's a reasonable TODO item though. Up till fairly recently, we
didn't have infrastructure that would allow building plans that depended
for correctness on the existence of a constraint. (In particular,
I'd want such a plan to get thrown away and redone if someone dropped
the NOT NULL constraint.) We have most of that now, although it only
works for constraints that have entries in pg_constraint, which NOT NULL
doesn't yet. Maybe in another few months ...

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Viktor Bojović 2010-11-06 19:30:40 drop table
Previous Message David W Noon 2010-11-06 16:53:54 Re: Interesting Query Performance Question