Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TjVd0-0001uC-9S for pgsql-performance@arkaria.postgresql.org; Fri, 14 Dec 2012 13:48:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TjVcz-0003pn-Qn for pgsql-performance@arkaria.postgresql.org; Fri, 14 Dec 2012 13:48:37 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TjVcy-0003pg-Mn for pgsql-performance@postgresql.org; Fri, 14 Dec 2012 13:48:36 +0000 Received: from mailout-us.gmx.com ([74.208.5.67]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TjVct-0003ys-E4 for pgsql-performance@postgresql.org; Fri, 14 Dec 2012 13:48:35 +0000 Received: (qmail 32185 invoked by uid 0); 14 Dec 2012 13:48:30 -0000 Received: from 76.255.19.161 by rms-us003 with HTTP Cc: "Huan Ruan" ,pgsql-performance@postgresql.org Content-Type: text/plain; charset="utf-8" Date: Fri, 14 Dec 2012 08:48:30 -0500 From: "Kevin Grittner" Message-ID: <20121214134830.80090@gmx.com> MIME-Version: 1.0 Subject: Re: hash join vs nested loop join To: "Huan Ruan" X-Authenticated: #138763884 X-Flags: 0001 X-Mailer: GMX.com Web Mailer x-registered: 0 Content-Transfer-Encoding: 8bit X-GMX-UID: eUu5cC1+3zOlOQ09LnwhEAB+IGRvb4DL X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Huan Ruan wrote: > Kevin Grittner wrote: >> With a low cache hit rate, that would generally be when the number >> of lookups into the table exceeds about 10% of the table's rows. > > So far, my main performance issue comes down to this pattern where > Postgres chooses hash join that's slower than a nest loop indexed join. By > changing those cost parameters, this query works as expected now, but there > are others fall into the same category and appear to be harder to convince > the optimiser. > > I'm still a bit worried about this query as Postgres gets the record count > right, and knows the index is a primary key index, therefore it knows it's > 0.05m out of 170m records (0.03%) but still chooses the sequential scan. > Hopefully this is just related to that big index penalty bug introduced in > 9.2. Quite possibly, but it could be any of a number of other things, like a type mismatch. It might be best to rule out other causes. If you post the new query and EXPLAIN ANALYZE output, along with the settings you have now adopted, someone may be able to spot something. It wouldn't hurt to repeat OS and hardware info with it so people have it handy for reference. -Kevin -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance