query optimisation - Mailing list pgsql-general

From Abdul-wahid Paterson
Subject query optimisation
Date
Msg-id 1047690549.31880.5002.camel@yusuf.lintrix.net
Whole thread Raw
Responses Re: query optimisation  (Mike Mascari <mascarm@mascari.com>)
Re: query optimisation  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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?

I am actually adopting someone else's work. In their code I found about
7-8 different SQL statements wrapped up in a couple of pages of
programming code that were used to get the desired result. The code
seemed to me long and convoluted and I was sure that it could be
whittled down to one SQL statement. However, it now take longer to run
as one SQL statement than it did when the external program was doing the
sorting and merging of data. Surely it should be the case, that in the
worst case, Postgres should still be more efficient then letting an
external program do the work? Are there occasions when it is better to
do the calculations outside of Postgres?

Thanks for any help.


Abdul-Wahid

Attachment

pgsql-general by date:

Previous
From: "Fernando Papa"
Date:
Subject: Re: LIMIT/OFFSET doesn't work on PL/PGSQL
Next
From: Mike Mascari
Date:
Subject: Re: query optimisation