Re: Encouraging multi-table join order

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dan Harris <fbsd(at)drivefaster(dot)net>
Cc: PostgreSQL Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Encouraging multi-table join order
Date: 2006-04-10 23:12:36
Message-ID: 1543.1144710756@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Dan Harris <fbsd(at)drivefaster(dot)net> writes:
> I have a query that is intended to select from multiple "small tables"
> to get a limited subset of "incidentid" and then join with a "very
> large" table. One of the operations will require a sequential scan, but
> the planner is doing the scan on the very large table before joining the
> small ones, resulting in a huge amount of disk I/O. How would I make
> this query join the large table only after narrowing down the possible
> selections from the smaller tables? This is running on version 8.0.3.

That's very strange --- the estimated cost of the seqscan is high enough
that the planner should have chosen a nestloop with inner indexscan on
the big table. I'm not sure about the join-order point, but the hash
plan for the first join seems wrong in any case.

Um, you do have an index on eventactivity.incidentid, right? What's the
datatype(s) of the incidentid columns? What happens to the plan if you
turn off enable_hashjoin and enable_mergejoin?

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Dan Harris 2006-04-10 23:51:55 Re: Encouraging multi-table join order
Previous Message Chris Mair 2006-04-10 21:05:22 Re: bad performance on Solaris 10