pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jim C. Nasby <jim@nasby.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Josh Berkus <josh@agliodbs.com>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] Hypothetical suggestions for planner, indexing improvement
Date: Wed, 7 May 2003 08:36:16 -0500
Message-ID: <20030507083616.F66185@flake.decibel.org> (raw)
In-Reply-To: <25000.1052284836@sss.pgh.pa.us>
References: <200305051219.58955.josh@agliodbs.com>
	<22292.1052195133@sss.pgh.pa.us>
	<200305052133.33680.josh@agliodbs.com>
	<20030506080747.C66185@flake.decibel.org>
	<24779.1052228707@sss.pgh.pa.us>
	<20030507000801.E66185@flake.decibel.org>
	<25000.1052284836@sss.pgh.pa.us>

> 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@nasby.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?"




view thread (16+ messages)  latest in thread

Message-ID: <20030507083616.F66185@flake.decibel.org>
Permalink:  ../20030507083616.F66185@flake.decibel.org/
Also on:    postgresql.org/message-id/20030507083616.F66185@flake.decibel.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: jim@nasby.net, tgl@sss.pgh.pa.us, josh@agliodbs.com, pgsql-hackers@postgresql.org
  Subject: Re: [PERFORM] Hypothetical suggestions for planner, indexing improvement
  In-Reply-To: <20030507083616.F66185@flake.decibel.org>
  References: <200305051219.58955.josh@agliodbs.com> <22292.1052195133@sss.pgh.pa.us> <200305052133.33680.josh@agliodbs.com> <20030506080747.C66185@flake.decibel.org> <24779.1052228707@sss.pgh.pa.us> <20030507000801.E66185@flake.decibel.org> <25000.1052284836@sss.pgh.pa.us> <20030507083616.F66185@flake.decibel.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox