Re: Complex SQL query and performance strategy

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Adam Witney <awitney(at)sghms(dot)ac(dot)uk>
Cc: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Complex SQL query and performance strategy
Date: 2002-10-09 13:47:22
Message-ID: 19820.1034171242@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Adam Witney <awitney(at)sghms(dot)ac(dot)uk> writes:
> I have a complex SQL query which requires the joining of 18 tables. There
> are only primary key indices on the table and at the moment it runs a little
> slow (30s or so) and so I am trying to optimise it.

> The output of EXPLAIN is a little confusing and seems to vary from run to
> run. Does the query optimiser have trouble with larger number of table
> joins?

The output probably would vary, because at that number of tables it'll
be using the GEQO optimizer, which is probabilistic. If you don't like
that, you can raise the GEQO threshold above 18 tables, but I suspect
you'll not like the amount of time the exhaustive optimizer will take.

A reasonable solution is to jack up the threshold, experiment until you
find a good query plan, and then restructure the query with explicit
JOIN operators to limit the optimizer's search space. That will bring
the planning time down out of the stratosphere.

See
http://www.ca.postgresql.org/users-lounge/docs/7.2/postgres/explicit-joins.html
for details.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jose Antonio Leo 2002-10-09 16:56:41 problem with the Index
Previous Message Shridhar Daithankar 2002-10-09 13:41:09 Re: [pgsql-performance] Large databases, performance