Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 6AAC07E4442 for ; Fri, 22 Jun 2012 13:00:09 -0300 (ADT) Received: from gwmta.wicourts.gov ([165.219.244.99] helo=gw.wicourts.gov) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Si6HD-0007fk-Jc for pgsql-performance@postgresql.org; Fri, 22 Jun 2012 16:00:08 +0000 Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Fri, 22 Jun 2012 10:59:50 -0500 Message-Id: <4FE4502002000025000489DA@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.2 Date: Fri, 22 Jun 2012 10:59:44 -0500 From: "Kevin Grittner" To: "Tim Jacobs" , Subject: Re: Why is a hash join being used? References: <9D1AF2AE-9605-41B5-8BCC-177B5EF6F1A5@gmail.com> In-Reply-To: <9D1AF2AE-9605-41B5-8BCC-177B5EF6F1A5@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201206/117 X-Sequence-Number: 47143 Tim Jacobs wrote: > The nested loop join performs very quickly, whereas the hash join > is incredibly slow. If I disable the hash join temporarily then a > nested loop join is used in the second case and is the query runs > much more quickly. How can I change my configuration to favor the > nested join in this case? Is this a bad idea? Before anyone can make solid suggestions on what you might want to change in your configuration, they would need to know more. Please read this page: http://wiki.postgresql.org/wiki/SlowQueryQuestions ... and repost with your PostgreSQL version, your configuration overrides, a description of your hardware, and EXPLAIN ANALYZE output from the query (rather than just EXPLAIN output). You might not be modeling your costs correctly, you might not be allocating resources well, you might be on an old version without an optimizer as smart as more recent versions, your statistics might be out of date, or you might be running into an optimizer weakness of some sort. -Kevin