pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
looking to speed up SELECT ... LEFT JOIN query
2+ messages / 2 participants
[nested] [flat]

* looking to speed up SELECT ... LEFT JOIN query
@ 2002-08-07 05:03 Trey Ackerman <ta145@yahoo.com>
  2002-08-08 14:24 ` Re: looking to speed up SELECT ... LEFT JOIN query Richard Huxton <dev@archonet.com>
  0 siblings, 1 reply; 2+ messages in thread

From: ta145@yahoo.com @ 2002-08-07 05:03 UTC (permalink / raw)
  To: pgsql-general@postgresql.org; pgsql-php@postgresql.org; pgsql-sql

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.

Regards,

Trey Ackerman



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: looking to speed up SELECT ... LEFT JOIN query
  2002-08-07 05:03 looking to speed up SELECT ... LEFT JOIN query Trey Ackerman <ta145@yahoo.com>
@ 2002-08-08 14:24 ` Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Huxton @ 2002-08-08 14:24 UTC (permalink / raw)
  To: ta145@yahoo.com; pgsql-general@postgresql.org; pgsql-php@postgresql.org; 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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-08-08 14:24 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-08-07 05:03 looking to speed up SELECT ... LEFT JOIN query Trey Ackerman <ta145@yahoo.com>
2002-08-08 14:24 ` Richard Huxton <dev@archonet.com>

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