From: Josh Berkus <josh@agliodbs.com>
To: Ryan Bradetich <rbradetich@uswest.net>
Cc: Oleg Lebedev <oleg.lebedev@waterford.org>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: slow query
Date: Sun, 23 Feb 2003 13:47:58 -0800
Message-ID: <200302231347.58960.josh@agliodbs.com> (raw)
In-Reply-To: <1046034334.13010.3.camel@beavis.ybsoft.com>
References: <993DBE5B4D02194382EC8DF8554A5273033583@postoffice.waterford.org>
<200302231252.30681.josh@agliodbs.com>
<1046034334.13010.3.camel@beavis.ybsoft.com>
Ryan,
> > The above should use an EXISTS clause, not IN, unless you are absolutely
> > sure that the subquery will never return more than 12 rows.
>
> I am assuming you said this because EXISTS is faster for > 12 rows?
> Interesting :)
That's my rule of thumb, *NOT* any kind of relational-calculus-based truth.
Basically, one should only use IN for a subquery when one is *absolutely* sure
that the subquery will only return a handful of records, *and* the subquery
doesn't have to do an complex work like aggregating or custom function
evaluation.
You're safer using EXISTS for all subqueries, really.
--
Josh Berkus
Aglio Database Solutions
San Francisco
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: josh@agliodbs.com, rbradetich@uswest.net, oleg.lebedev@waterford.org
Subject: Re: slow query
In-Reply-To: <200302231347.58960.josh@agliodbs.com>
* 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