Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XV36Z-0000GT-SQ for pgsql-performance@arkaria.postgresql.org; Fri, 19 Sep 2014 18:40:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XV36Z-0000HW-77 for pgsql-performance@arkaria.postgresql.org; Fri, 19 Sep 2014 18:40:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XV36Y-0000HL-3f for pgsql-performance@postgresql.org; Fri, 19 Sep 2014 18:40:26 +0000 Received: from 01.zmailcloud.com ([192.198.85.104] helo=mx-out-1.zmailcloud.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XV36T-0006Vy-TX for pgsql-performance@postgresql.org; Fri, 19 Sep 2014 18:40:24 +0000 Received: from smtp.01.com (smtp.01.com [10.10.0.43]) by mx-out-1.zmailcloud.com (Postfix) with ESMTP id 991205647E2; Fri, 19 Sep 2014 13:40:19 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 907056043B; Fri, 19 Sep 2014 13:40:19 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a_Yxfe9lzCBL; Fri, 19 Sep 2014 13:40:19 -0500 (CDT) Received: from smtp.01.com (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 71ED260448; Fri, 19 Sep 2014 13:40:19 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 5BB7B60440; Fri, 19 Sep 2014 13:40:19 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id l-NOMbsIGJ5E; Fri, 19 Sep 2014 13:40:19 -0500 (CDT) Received: from [172.47.23.104] (70-36-143-82.dsl.dynamic.sonic.net [70.36.143.82]) by smtp-out-2.01.com (Postfix) with ESMTPSA id DC8BB6043B; Fri, 19 Sep 2014 13:40:18 -0500 (CDT) Message-ID: <541C7891.7000902@agliodbs.com> Date: Fri, 19 Sep 2014 11:40:17 -0700 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Merlin Moncure CC: "pgsql-performance@postgresql.org" Subject: Re: Yet another abort-early plan disaster on 9.3 References: <541A2335.3060100@agliodbs.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.2 (/) 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 09/19/2014 10:15 AM, Merlin Moncure wrote: > On Wed, Sep 17, 2014 at 7:11 PM, Josh Berkus wrote: >> This is the core issue with abort-early plans; they depend on our >> statistics being extremely accurate, which we know they are not. And if >> they're wrong, the execution time climbs by 1000X or more. Abort-early >> plans are inherently riskier than other types of query plans. >> >> What I'm not clear on is why upgrading from 9.1 to 9.3 would bring about >> this change. The stats are no more than 10% different across the >> version change. > > Amusingly on-topic rant I happened to read immediately after this by chance: > > http://wp.sigmod.org/?p=1075 > > Is there a canonical case of where 'abort early' plans help? (I'm new > to that term -- is it a recent planner innovation...got any handy > links?) Yeah, here's an example of the canonical case: Table t1 ( a, b, c ) - "b" is low-cardinality - "c" is high-cardinality - There are separate indexes on both b and c. SELECT a, b, c FROM t1 WHERE b = 2 ORDER BY c LIMIT 1; In this case, the fastest plan is usually to use the index on C and return the first row where the filter condition matches the filter on b. This can be an order of magnitude faster than using the index on b and then resorting by c and taking the first row, if (b=2) happens to match 20% of the table. This is called an "abort early" plan because we expect to never finish the scan on the index on c. We expect to scan the index on c, find the first row that matches b=2 and exit. The problem with such plans is that they are "risky". As in, if we are wrong about our (b=2) stats, then we've just adopted a query plan which will be 10X to 1000X slower than the more conventional plan. We can see this in the bad plan I posted: Limit (cost=1.00..2641.10 rows=20 width=202) (actual time=9.933..711.372 rows=20 loops=1) -> Nested Loop Semi Join (cost=1.00..9641758.39 rows=73041 width=202) (actual time=9.931..711.361 rows=20 loops=1) -> Index Scan Backward using index_categories_on_recorded_on on categories (cost=0.43..406943.98 rows=4199200 width=202) (actual time=0.018..275.020 rows=170995 loops=1) Notice how the total cost of the plan is a fraction of the cost of the two steps which preceeded it? This is an indication that the planner expects to be able to abort the index scan and nestloop join before it's more than 2% through it. -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance