Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UR36C-0004t1-1U for pgsql-performance@arkaria.postgresql.org; Sat, 13 Apr 2013 16:14:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UR36A-0002hF-VL for pgsql-performance@arkaria.postgresql.org; Sat, 13 Apr 2013 16:14:43 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UR369-0002h9-Md for pgsql-performance@postgresql.org; Sat, 13 Apr 2013 16:14:41 +0000 Received: from outbound.afilias.info ([66.199.183.4]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UR362-0002gg-D6 for pgsql-performance@postgresql.org; Sat, 13 Apr 2013 16:14:40 +0000 Received: from ms5.on1.afilias-ops.info ([10.109.8.9] helo=smtp.afilias.info) by outbound.afilias.info with esmtp (Exim 4.69) (envelope-from ) id 1UR35o-0001fh-5r for pgsql-performance@postgresql.org; Sat, 13 Apr 2013 16:14:20 +0000 Received: from mail-wg0-f69.google.com ([74.125.82.69]) by smtp.afilias.info with esmtps (TLSv1:RC4-SHA:128) (Exim 4.72) (envelope-from ) id 1UR35o-0003cQ-5L for pgsql-performance@postgresql.org; Sat, 13 Apr 2013 16:14:20 +0000 Received: by mail-wg0-f69.google.com with SMTP id k13so3847697wgh.8 for ; Sat, 13 Apr 2013 09:14:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-received:message-id:date:from:user-agent:mime-version :to:cc:subject:references:in-reply-to:content-type :content-transfer-encoding:x-gm-message-state; bh=oLUAauzKXH9oKt93+0srbMQGmzDdXoIMLGkbF+16IgI=; b=fv/SdrjBduRBhCqXfWxXgN8hMnMtFSm0rLfjf80+yt1TwfF5EMxBeyrboGzxQWP+hl xPPLBh61Xmi14F1Hu3e8o5VBG94B41Rq0stB+R252jb30FfT8hWi6tVPeUn/hFPIMRDH nuxQF3vdzxNul4L0390qnpIZSwQgBDGqT+CARL7ENRLgyZ3gwqLnPDLEJb6LadmmMvtt rThQ5Ux/HxLd2obOACYJHJI7o+rRXot35hoU8N1G29r6BOejLEJqpIpTzbRzMt+Z2HwJ t7MfjwOeBsn6eZtEzpklkHCVhrVDlhILdriPbHjDMZAjS0Q39UDR29FJus67rGfgEbLI rIDg== X-Received: by 10.180.90.41 with SMTP id bt9mr3671634wib.19.1365869654654; Sat, 13 Apr 2013 09:14:14 -0700 (PDT) X-Received: by 10.180.90.41 with SMTP id bt9mr3671628wib.19.1365869654563; Sat, 13 Apr 2013 09:14:14 -0700 (PDT) Received: from [192.168.1.5] ([64.231.26.209]) by mx.google.com with ESMTPS id ek4sm3804007wib.11.2013.04.13.09.14.12 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 13 Apr 2013 09:14:13 -0700 (PDT) Message-ID: <51698452.1050202@ca.afilias.info> Date: Sat, 13 Apr 2013 12:14:10 -0400 From: Steve Singer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: Jeff Janes CC: "pgsql-performance@postgresql.org" Subject: Re: slow bitmap heap scans on pg 9.2 References: <51656E03.7000701@ca.afilias.info> <5165FBA1.90704@ca.afilias.info> <5166C69B.1010505@ca.afilias.info> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQmQOtgAxUJkT5XzQmlZchcOIUyrsv5usqtSbmW5fmlV/nDZCS+vQK0tPziWLZI2+GN9z33S4j34BCaR/m8rr/ghGOz6naBf2KnwapAW6UHnOZOvC5CJynuMa+Ik1IsIy1oxcDnTHdcYRC7/KvnQ5UhrN03aZ5KaX2ASspa0SfdLq/hzQTc= 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 13-04-12 09:20 PM, Jeff Janes wrote: > On Thursday, April 11, 2013, Steve Singer wrote: > > > I think the reason why it is picking the hash join based plans is > because of > > Index Scan using table_b_1_ptid_orgid_ym_unq on table_b_1 b > (cost=0.00..503.86 rows=1 width=10) (actual time=0.016..0.017 rows=1 > loops=414249) > Index Cond: ((a.id = a_id) AND > (organization_id = 2) AND (year = 2013) AND (month = 3)) > Filter: (product_id = 1) > > > > Trying to reason about how the planner estimates costs for the inner > side of nested loops makes my head hurt. > So before doing that, could you run explain (analyze,buffers) on both of > these much simpler (but hopefully morally equivalent to this planner > node) sql: > > select * from table_b_1_b where a_id = and > organization_id=2 and year=2013 and month=3 > > select * from table_b_1_b where a_id = and > organization_id=2 and year=2013 and month=3 and product_id=1 > table_b_1 is a partition of table_b on product_id so when querying table table_b_1 directly they are equivalent explain (analyze,buffers) select * FROM table_b_1 where a_id=1128944 and organization_id=2 and year=2013 and month=3; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------- ----------- Index Scan using table_b_1_ptid_orgid_ym_unq on table_b_1 (cost=0.00..50.73 rows=1 width=56) (actual time=60.328..60.330 rows= 1 loops=1) Index Cond: ((a_id = 1128944) AND (organization_id = 2) AND (year = 2013) AND (month = 3)) Buffers: shared hit=1 read=5 Total runtime: 60.378 ms (4 rows) The plans are the same if I do or do not specify the product_id in the where clause (if I query the parent table and neglect to query the query clause it of course queries all the other partitions) > > Of particular interest here is whether the estimate of 1 row is due to > the specificity of the filter, or if the index clauses alone are > specific enough to drive that estimate. (If you get many rows without > the product_id filter, that would explain the high estimate.). The index clauses alone , we normally expect 1 row back for a query like that. > > Please run with the default cost parameters, or if you can't get the > right plan with the defaults, specify what the used parameters were. indexTotalCost += index->pages * spc_random_page_cost / 100000.0; Is driving my high costs on the inner loop. The index has 2-5 million pages depending on the partition . If I run this against 9.2.2 with / 10000.0 the estimate is even higher. If I try this with this with the *indexTotalCost += log(1.0 + index->pages / 10000.0) * spc_random_page_cost; from 9.3 and I play I can make this work I can it pick the plan on some partitions with product_id=2 but not product_id=1. If I remove the fudge-factor cost adjustment line I get the nested-loop plan always. Breaking the index into smaller partial indexes for each year seems to be giving me the plans I want with random_page_cost=2 (I might also try partial indexes on the month). Even with the 9.3 log based fudge-factor we are seeing the fudge-factor being big enough so that the planner is picking a table scan over the index. A lot of loop iterations can be satisfied by cached pages of the index the fudge-factor doesn't really account for this. > > Cheers, > > Jeff -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance