Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UPvWi-0005sk-R0 for pgsql-performance@arkaria.postgresql.org; Wed, 10 Apr 2013 13:57:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UPvWi-000068-Al for pgsql-performance@arkaria.postgresql.org; Wed, 10 Apr 2013 13:57:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UPvWh-000063-J0 for pgsql-performance@postgresql.org; Wed, 10 Apr 2013 13:57:27 +0000 Received: from proofpoint2.mail.rice.edu ([128.42.201.101] helo=pp2.rice.edu) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UPvWb-0006Hv-4T for pgsql-performance@postgresql.org; Wed, 10 Apr 2013 13:57:26 +0000 Received: from pps.filterd (pp2.rice.edu [127.0.0.1]) by pp2.rice.edu (8.14.5/8.14.5) with SMTP id r3AAMswW019695; Wed, 10 Apr 2013 08:56:58 -0500 Received: from mh11.mail.rice.edu (mh11.mail.rice.edu [128.42.199.30]) by pp2.rice.edu with ESMTP id 1bmv0w88mx-1; Wed, 10 Apr 2013 08:56:58 -0500 X-Virus-Scanned: by amavis-2.7.0 at mh11.mail.rice.edu, auth channel X-SMTP-Auth: no X-SMTP-Auth: no Received: from aart.rice.edu (aart.rice.edu [168.7.56.48]) by mh11.mail.rice.edu (Postfix) with ESMTP id DC2AE4C0006; Wed, 10 Apr 2013 08:56:57 -0500 (CDT) Received: by aart.rice.edu (Postfix, from userid 18612) id D38731005F5; Wed, 10 Apr 2013 08:56:57 -0500 (CDT) Date: Wed, 10 Apr 2013 08:56:57 -0500 From: "ktm@rice.edu" To: Steve Singer Cc: pgsql-performance@postgresql.org Subject: Re: slow bitmap heap scans on pg 9.2 Message-ID: <20130410135657.GY32580@aart.rice.edu> References: <51656E03.7000701@ca.afilias.info> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <51656E03.7000701@ca.afilias.info> User-Agent: Mutt/1.5.20 (2009-12-10) X-Proofpoint-SSN: Sensitivity3 X-Pg-Spam-Score: -4.3 (----) 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 On Wed, Apr 10, 2013 at 09:49:55AM -0400, Steve Singer wrote: > I'm encountering an issue where PG 9.2.4 (we also see this with > 9.2.3) is picking a plan involving a bitmap heap scan that turns out > to be much slower than a nested-loop plan using indexes. > > The planner picks the hashjoin plan by default (see attached files) > > Bitmap Heap Scan on public.table_b_2 b (cost=172635.99..9800225.75 > rows=8435754 width=10) (actual t > ime=9132.194..1785196.352 rows=9749680 loops=1) > Recheck Cond: ((b.organization_id = 3) > AND (b.year = 2013) AND (b.month = 3)) > Rows Removed by Index Recheck: 313195667 > Filter: (b.product_id = 2) > > Is the part that seems be causing the problem (or at least taking > most of the time, other than the final aggregation) > > If I set enable_hashjoin=false and enable_mergejoin=false I get the > nestedloop join plan. > > table_b is 137 GB plus indexes each on is around 43 GB > table_a is 20 GB > > random_page_cost = 2.0 > effective_cache_size = 3500MB > cpu_tuple_cost = 0.01 > cpu_index_tuple_cost = 0.005 > cpu_operator_cost = 0.0025 > work_mem = 64MB > shared_buffers = 300MB (for this output, I've also had it at 2GB) > > If I bump cpu_tuple_cost to the 10-20 range it will pick the nested > loop join for some date ranges but not all. cpu_tuple_cost of 20 > doesn't sound like an sane value. > > This database used to run 8.3 where it picked the nested-loop join. > We used pg_upgrade to migrate to 9.2 > > Any ideas why the bitmap heap scan is much slower than the planner expects? > > Steve Hi Steve, The one thing that stands out to me is that you are working with 200GB of data on a machine with 4-8GB of ram and you have the random_page_cost set to 2.0. That is almost completely uncached and I would expect a value of 10 or more to be closer to reality. Regards, Ken -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance