Re: Optomizing left outer joins

From: Rod Taylor <rbt(at)rbt(dot)ca>
To: Lorraine Dewey <Lorraine(dot)Dewey(at)companiongroup(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Optomizing left outer joins
Date: 2003-04-23 17:48:38
Message-ID: 1051120118.38778.34.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, 2003-04-21 at 11:14, Lorraine Dewey wrote:
> I'm writing an on-the-fly report program that generates and executes
> an SQL statement. The statement depends upon the choices users make
> when selecting from several hundred columns spread across > 90 tables.
>
> Since some of the data fields are optional and I won't be able to
> match across tables, I need to use left outer joins to make sure I
> don't drop rows. Unfortunately, execution time is somewhere around a
> minute (there's other stuff going on, but the majority of the time is
> in the execution). Way too long. For comparison, my queries run in
> about 2 seconds when I don't have to do outer joins.

Have you tried (or are able to) change the order the tables are joined
in? PostgreSQL runs outer joins in the order they are provided in,
which not not necessarily the best order to do so.

Try using EXPLAIN ANALYZE on your fast query for help on determining the
best join order.

Its up to you to ensure the results still apply. Switch the join order
may change the results depending on what you're doing.

--
Rod Taylor <rbt(at)rbt(dot)ca>

PGP Key: http://www.rbt.ca/rbtpub.asc

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message mallah 2003-04-23 17:54:45 Re: Why is seq search preferred here by planner?
Previous Message Rod Taylor 2003-04-23 17:40:08 Re: New to SQL; hopefully simple question