X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8DEF611F6667 for ; Mon, 10 Apr 2006 20:59:55 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0.126 X-Spam-Level: X-Spam-Status: No, score=0.126 required=5 tests=[AWL=0.126] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id Do5hd7sNQvBO for ; Mon, 10 Apr 2006 20:59:21 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8390F11F6931 for ; Mon, 10 Apr 2006 20:12:37 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k3ANCaZH001544; Mon, 10 Apr 2006 19:12:36 -0400 (EDT) To: Dan Harris cc: PostgreSQL Performance Subject: Re: Encouraging multi-table join order In-reply-to: <443AAC26.4070802@drivefaster.net> References: <443AAC26.4070802@drivefaster.net> Comments: In-reply-to Dan Harris message dated "Mon, 10 Apr 2006 13:04:06 -0600" Date: Mon, 10 Apr 2006 19:12:36 -0400 Message-ID: <1543.1144710756@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200604/220 X-Sequence-Number: 18304 Dan Harris 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