Re: looking to speed up SELECT ... LEFT JOIN query

From: Richard Huxton <dev(at)archonet(dot)com>
To: ta145(at)yahoo(dot)com (Trey Ackerman), pgsql-general(at)postgresql(dot)org, pgsql-php(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: looking to speed up SELECT ... LEFT JOIN query
Date: 2002-08-08 14:24:17
Message-ID: 200208081524.17392.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

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='$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 you
join the tables in a different order, smallest first?

- Richard Huxton

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Novodvorsky 2002-08-08 14:28:01 Re: double quotes in unicode dbs
Previous Message Richard Huxton 2002-08-08 14:22:53 Re: any way to check if a transaction is active?

Browse pgsql-sql by date

  From Date Subject
Next Message John Brothers 2002-08-08 19:18:57 Re: getting oid of an INSERT automatically
Previous Message Tom Lane 2002-08-08 13:35:48 Re: manipulating the POINT data type