X-Original-To: pgsql-performance@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7BB1B4758DC for ; Sun, 23 Feb 2003 16:49:21 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 26949-09 for ; Sun, 23 Feb 2003 16:49:10 -0500 (EST) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id EFFF447590C for ; Sun, 23 Feb 2003 16:48:42 -0500 (EST) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 2853849; Sun, 23 Feb 2003 13:48:43 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Ryan Bradetich Subject: Re: slow query Date: Sun, 23 Feb 2003 13:47:58 -0800 User-Agent: KMail/1.4.3 Cc: Oleg Lebedev , "pgsql-performance@postgresql.org" References: <993DBE5B4D02194382EC8DF8554A5273033583@postoffice.waterford.org> <200302231252.30681.josh@agliodbs.com> <1046034334.13010.3.camel@beavis.ybsoft.com> In-Reply-To: <1046034334.13010.3.camel@beavis.ybsoft.com> MIME-Version: 1.0 Message-Id: <200302231347.58960.josh@agliodbs.com> Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/168 X-Sequence-Number: 1224 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* s= ure=20 that the subquery will only return a handful of records, *and* the subquery= =20 doesn't have to do an complex work like aggregating or custom function=20 evaluation.=20=20 You're safer using EXISTS for all subqueries, really. --=20 Josh Berkus Aglio Database Solutions San Francisco