Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1URWww-0005Kw-AZ for pgsql-performance@arkaria.postgresql.org; Mon, 15 Apr 2013 00:07:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1URWwv-0003LW-Ns for pgsql-performance@arkaria.postgresql.org; Mon, 15 Apr 2013 00:07:09 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1URWwu-0003LQ-F8 for pgsql-performance@postgresql.org; Mon, 15 Apr 2013 00:07:08 +0000 Received: from outbound.afilias.info ([66.199.183.4]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1URWwr-0007Kr-Hh for pgsql-performance@postgresql.org; Mon, 15 Apr 2013 00:07:07 +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 1URWwe-0005Ty-49 for pgsql-performance@postgresql.org; Mon, 15 Apr 2013 00:06:52 +0000 Received: from mail-fa0-f71.google.com ([209.85.161.71]) by smtp.afilias.info with esmtps (TLSv1:RC4-SHA:128) (Exim 4.72) (envelope-from ) id 1URWwe-0007za-3f for pgsql-performance@postgresql.org; Mon, 15 Apr 2013 00:06:52 +0000 Received: by mail-fa0-f71.google.com with SMTP id u1so3285293fae.2 for ; Sun, 14 Apr 2013 17:06:46 -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=Vea4cWAg3+fJqzcB6GqB0amhaoIIuiL0GhfiPavAoLs=; b=cgdr4kZf7455cVfEXHISPdUBsvlfwfxKsp5U8evCr9Lpq4rbuHVJzQ17p8532roDl+ lrzMYsjMFHqWUtq9qtQVmIaPO/P8YEY72NWhLobP5rf3GJwhiYrXvpqFWFtbx4htOXZC gU6UHseHAGY9k/PiJIIGk/bNIkb7qXPPhYz7aK5Jx3MCPUGGiLTB8LR/muCfghizmLeM RJMcM2dpQ/eP4zA5KeGPujJuq+B5nptWG+4jBxjkM1U3gMrrG4hQSHDbWPLBYZrEJXsD P+RCD5fpp7ZKy/IRxUjuEdqpyvIpjTA9G7sWplVSqYjvfz5sIz9xSs3p3BUzM1DTL9QV 2AtQ== X-Received: by 10.194.89.169 with SMTP id bp9mr28641431wjb.57.1365984406005; Sun, 14 Apr 2013 17:06:46 -0700 (PDT) X-Received: by 10.194.89.169 with SMTP id bp9mr28641426wjb.57.1365984405880; Sun, 14 Apr 2013 17:06:45 -0700 (PDT) Received: from [192.168.1.5] ([64.231.26.209]) by mx.google.com with ESMTPS id t7sm10555943wij.2.2013.04.14.17.06.43 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 14 Apr 2013 17:06:45 -0700 (PDT) Message-ID: <516B4492.7090204@ca.afilias.info> Date: Sun, 14 Apr 2013 20:06:42 -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> <51698452.1050202@ca.afilias.info> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQkZYoxHGx71MAsh5ZcclqR9x1bJNHiHxjuDghmjhv8C+RMFMDSuwbGY+BUXzUuD7WYLFxlRrXfFCckZmkGpu857oo89iUYn6MpbObwctGRUjYFhlzKw/f1a+20qynaLFdv1IOqP+ztgo9iExoYH/PfpiexuXlOXGYe5mNTIlY95JSaq2nQ= X-Pg-Spam-Score: -2.6 (--) 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-13 04:54 PM, Jeff Janes wrote: > On Sat, Apr 13, 2013 at 9:14 AM, Steve Singer > wrote: > > > 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. > > > That was only temporarily the formula during 9.3dev. Tom re-did that > entire part of the code rather substantially in the current tip of 9.3 > (commit 31f38f28b00cbe2b). Now it is based on the number of tuples, and > the height, rather than pages, and is multiplied by the > cpu_operator_cost not the random_page_cost. > > descentCost = ceil(log(index->tuples) / log(2.0)) * cpu_operator_cost; > > ... > > descentCost = (index->tree_height + 1) * 50.0 * cpu_operator_cost; > > > 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. > > > Have you tried it under 9.3 HEAD, rather than just back-porting the > temporary > *indexTotalCost += log(1.0 + index->pages / 10000.0) * spc_random_page_cost; > code into 9.2? > > If you are trying to make your own private copy of 9.2, then removing > the fudge factor altogether is probably the way to go. But if you want > to help improve future versions, you probably need to test with the most > up-to-date dev version. I will do that in a few days. I don't have enough disk space on this dev server to have a 9.2 datadir and a 9.3 one for this database. Once I have a solution that I can use with 9.2 firmed up I can upgrade the datadir to 9.3 and test this. I am hoping I can get a set of partial indexes that will give good results with an unmodified 9.2, so far that looks promising but I still have more cases to verify (these indexes take a while to build). > > A lot of loop iterations can be satisfied by cached pages of the > index the fudge-factor doesn't really account for this. > > > > Setting random_page_cost to 2 is already telling it that most of fetches > are coming from the cache. Of course for the upper blocks of an index > even more than "most" are likely to be, but the latest dev code takes > care of that. > > 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