Re: [SQL] Selecting with a large number of foreign keys

From: "Ross J(dot) Reedstrom" <reedstrm(at)rice(dot)edu>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Selecting with a large number of foreign keys
Date: 1999-05-04 21:08:04
Message-ID: 372F61B4.AC6BD458@rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Matt -
We've been running into exactly the same problems you, for exactly the
same reason: we have a highly 'normalized' database design, in order to
easily populate drop-downs and picklists (get the users to enter the
right data by only giving them the right data!) You don't mention what
version of PostgreSQL you're using, but I bet it's 6.4.2. The
development team found some nasty problems in the query optimzer that
caused exactly these symptoms, and there are fixes in v6.5beta.

The way to test if this is the problem is to try your query at the psql
prompt, then try an EXPLAIN of your query. IF the EXPLAIN takes a long
time (and a lot of memory), bingo!

One workaround until you can upgrade (the beta is shaking out bugs right
now) is to enable the Genetic Query Optimizer at a small number of
tables. This sort of short circuits the problem. Note that the WinODBC
driver disables GQO by default (if you're using that)

via SQL, do:
SET GEQO TO 'ON=5';

or some other small number: it's the number of tables in a 'join' at
which GEQO will take over.

HTH,
Ross

Matt Behrens wrote:
>

<problem with large joins blowing up>

--
Ross J. Reedstrom, Ph.D., <reedstrm(at)rice(dot)edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St., Houston, TX 77005

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 1999-05-04 23:33:25 Re: [SQL] Selecting with a large number of foreign keys
Previous Message Matt Behrens 1999-05-04 20:47:43 Selecting with a large number of foreign keys