X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E49054762FE for ; Wed, 23 Apr 2003 13:48:45 -0400 (EDT) Received: from nat.inquent.com (unknown [216.208.117.7]) by postgresql.org (Postfix) with ESMTP id 89EF7475F16 for ; Wed, 23 Apr 2003 13:48:42 -0400 (EDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by nat.inquent.com (8.12.8p1/8.12.8) with ESMTP id h3NHmcDl045641; Wed, 23 Apr 2003 13:48:39 -0400 (EDT) (envelope-from rbt@rbt.ca) Subject: Re: Optomizing left outer joins From: Rod Taylor To: Lorraine Dewey Cc: pgsql-sql@postgresql.org In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-cYExNGy8XbmoYetaXXBk" Organization: Message-Id: <1051120118.38778.34.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Date: 23 Apr 2003 13:48:38 -0400 X-Spam-Status: No, hits=-45.1 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,PGP_SIGNATURE_2, QUOTED_EMAIL_TEXT,REFERENCES,REPLY_WITH_QUOTES, USER_AGENT_XIMIAN autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/341 X-Sequence-Number: 13042 --=-cYExNGy8XbmoYetaXXBk Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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. >=20 > 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. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-cYExNGy8XbmoYetaXXBk Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQA+ptH16DETLow6vwwRAhVqAJ96Dai1rHf8BtA62g4mSWluaNMoYgCfcnxN E7jDOvof2BfGRbWxbEBDX4Q= =ZnsH -----END PGP SIGNATURE----- --=-cYExNGy8XbmoYetaXXBk--