Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id AE21F9FB321 for ; Mon, 16 Oct 2006 19:28:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 91968-03 for ; Mon, 16 Oct 2006 19:28:48 -0300 (ADT) X-Greylist: delayed 05:28:36.903903 by SQLgrey- Received: from turing.leapfrogonline.com (Leapfrog-Online-1143628.cust-rtr.ameritech.net [70.230.73.42]) by postgresql.org (Postfix) with ESMTP id 32EC99F9F96 for ; Mon, 16 Oct 2006 19:28:47 -0300 (ADT) Received: by turing.leapfrogonline.com (Postfix, from userid 1000) id 1D9775821F; Mon, 16 Oct 2006 17:28:43 -0500 (CDT) From: Shaun Thomas Organization: Leapfrog Online To: pgsql-performance@postgresql.org Subject: Re: Performance Optimization for Dummies 2 - the SQL Date: Mon, 16 Oct 2006 17:28:42 -0500 User-Agent: KMail/1.9.4 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200610161728.43193.sthomas@leapfrogonline.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.185 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/309 X-Sequence-Number: 21438 On Monday 16 October 2006 16:37, Carlo Stonebanks wrote: > The facility_address_id is null statement is necessary, as this is a > sub-query from a union clause and I want to optimise the query with > the original logic intact. The value is not hard coded to true but > rather to null. Heh, you neglect to mention that this query is discovering faculty who do *not* have an address entry, which makes the "is null" a major necessity. With that, how did a "not exists (blabla faculty_address blabla)" subquery to get the same effect treat you? How about an "IN (blabla LIMIT 1)" ? -- Shaun Thomas Database Administrator Leapfrog Online 807 Greenwood Street Evanston, IL 60201 Tel. 847-440-8253 Fax. 847-570-5750 www.leapfrogonline.com