Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id CB1A6475935; Thu, 8 Aug 2002 10:30:00 -0400 (EDT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by postgresql.org (Postfix) with ESMTP id EEF824758F3; Thu, 8 Aug 2002 10:29:59 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 3.36 #2) id 17coId-0007bo-0U; Thu, 08 Aug 2002 15:30:03 +0100 Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 35ACB120D0; Thu, 8 Aug 2002 15:24:20 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: ta145@yahoo.com (Trey Ackerman), pgsql-general@postgresql.org, pgsql-php@postgresql.org, pgsql-sql@postgresql.org Subject: Re: looking to speed up SELECT ... LEFT JOIN query Date: Thu, 8 Aug 2002 15:24:17 +0100 User-Agent: KMail/1.4.1 References: <1b23bd38.0208062103.3ec45a2b@posting.google.com> In-Reply-To: <1b23bd38.0208062103.3ec45a2b@posting.google.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200208081524.17392.dev@archonet.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/378 X-Sequence-Number: 28723 On Wednesday 07 Aug 2002 6:03 am, Trey Ackerman wrote: > Hi, > > I have a working SELECT statement using LEFT JOIN but I'm hoping > someone can suggest something that might be a bit quicker (currently 3 > seconds for result). > > SELECT * FROM ((table1 LEFT JOIN table2 USING (custno)) AS j1 > LEFT JOIN table3 USING (custno)) AS j2 > LEFT JOIN table4 USING (custno) > WHERE custno=3D'$custno'; > > The primary table is table1, the key for all tables is 'custno'. I > need the LEFT JOIN because any one or all of the other tables (table2, > table3, table4) might not have corresponding data. We'll need to see the output of an EXPLAIN / EXPLAIN ANALYSE - also could y= ou=20 join the tables in a different order, smallest first? - Richard Huxton