Re: query optimisation

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: Abdul-wahid Paterson <aw(at)lintrix(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: query optimisation
Date: 2003-03-15 01:18:24
Message-ID: 3E727F60.9090506@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Abdul-wahid Paterson wrote:
> Hi,
>
> I have a query of the form:
>
> select a.id, e.id from tablea a, tableb b, tablec c, tabled d, tablee e
> where a.fk=b.id and b.fk=c.id and c.fk=d.id and d.fk=e.id;
>
> In fact, my statement is a bit more complex as it is joined across 7
> tables, has an aggregate function and a CASE statement.
>
> My problem is that it executes to slow and I need to optimise it. Is
> there any documentation anywhere that can help me work out how to
> optimise the statement? My statement has a few other conditions that
> need to be met on the joining tables. Does changing the order of the
> conditional statement affect the way the statement is optimised?

Assuming indexes on the appropriate tables and a recent VACUUM
ANALYZE, I've found that using explicit joins can reduce
planning time significantly:

http://www.postgresql.org/docs/view.php?version=7.2&idoc=0&file=explicit-joins.html

Hope that helps,

Mike Mascari
mascarm(at)mascari(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-03-15 04:02:08 Re: query optimisation
Previous Message Abdul-wahid Paterson 2003-03-15 01:09:10 query optimisation