Re: [PERFORM] Hypothetical suggestions for planner, indexing improvement

From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-performance <pgsql-performance(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PERFORM] Hypothetical suggestions for planner, indexing improvement
Date: 2003-05-07 13:36:16
Message-ID: 20030507083616.F66185@flake.decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

> Supposing that tab1.col1 contains 1, NULL, 2, then for an outer
> table row where col2 = 42
>
> WHERE outer.col2 IN (SELECT col1 FROM tab1)
>
> will yield NULL (not FALSE). But
>
> WHERE EXISTS(SELECT * FROM tab1 WHERE col1 = outer.col2)
>
> will yield FALSE (not NULL).
>
> The distinction doesn't matter at the top level of WHERE, but it
> matters a lot underneath a NOT ...

OK, but even if a true transform can't be done, couldn't they share the
same set of code to fetch the data for the subquery? Going back to my
original post, I tend to use IN only in cases where I think the subquery
will return a small result-set, and use EXISTS elsewhere. Presumably,
the subquery for an IN will only be run once, while EXISTS will be run
as an inner-loop (I'm guessing here, I could be wrong). It might be
useful if the subquery was executed based on how many rows it
would/might return.
--
Jim C. Nasby (aka Decibel!) jim(at)nasby(dot)net
Member: Triangle Fraternity, Sports Car Club of America
Give your computer some brain candy! www.distributed.net Team #1828

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2003-05-07 13:50:55 CIDR in pg_hba.conf
Previous Message Robert Treat 2003-05-07 13:23:50 Re: 7.4 features list

Browse pgsql-performance by date

  From Date Subject
Next Message Hannu Krosing 2003-05-07 13:40:06 Re: An unresolved performance problem.
Previous Message Dennis Björklund 2003-05-07 07:36:52 Re: [PERFORM] Hypothetical suggestions for planner, indexing