Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YXYca-0000cq-W7 for pgsql-performance@arkaria.postgresql.org; Mon, 16 Mar 2015 17:16:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YXYca-0003PX-Cp for pgsql-performance@arkaria.postgresql.org; Mon, 16 Mar 2015 17:16:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YXYcY-0003Lw-E9 for pgsql-performance@postgresql.org; Mon, 16 Mar 2015 17:16:06 +0000 Received: from mx-out.zmailcloud.com ([192.198.85.98] helo=mx-out-1.zmailcloud.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YXYcQ-0001bo-D4 for pgsql-performance@postgresql.org; Mon, 16 Mar 2015 17:16:04 +0000 Received: from smtp.01.com (smtp.01.com [10.10.0.43]) by mx-out-1.zmailcloud.com (Postfix) with ESMTP id 9F40B56402D for ; Mon, 16 Mar 2015 12:15:55 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id 94712A044C for ; Mon, 16 Mar 2015 12:15:55 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-1.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-1.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rrDrOIisNfs5 for ; Mon, 16 Mar 2015 12:15:55 -0500 (CDT) Received: from smtp.01.com (localhost [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id 6E6B9A0453 for ; Mon, 16 Mar 2015 12:15:55 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id 4FD66A044C for ; Mon, 16 Mar 2015 12:15:55 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-1.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-1.01.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id VKikrdH8ug9j for ; Mon, 16 Mar 2015 12:15:55 -0500 (CDT) Received: from [172.47.23.102] (50-0-89-53.dsl.dynamic.fusionbroadband.com [50.0.89.53]) by smtp-out-1.01.com (Postfix) with ESMTPSA id 033C0A0456 for ; Mon, 16 Mar 2015 12:15:54 -0500 (CDT) Message-ID: <55070FC9.4010307@agliodbs.com> Date: Mon, 16 Mar 2015 10:15:53 -0700 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Bad cost estimate with FALSE filter condition References: <54F119A6.9080106@agliodbs.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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 So ... should I assume my diagnosis is correct? Haven't heard any other suggestions. On 02/27/2015 05:28 PM, Josh Berkus wrote: > All: > > This got posted to pgsql-bugs, but got no attention there[1], so I'm > sending it to this list. > > Test case: > > createdb bench > pgbench -i -s bench > \c bench > > bench=# explain select * from pgbench_accounts where aid = 2; > QUERY PLAN > --------------------------------------------------------------- > Index Scan using pgbench_accounts_pkey on pgbench_accounts > (cost=0.42..8.44 rows=1 width=97) > Index Cond: (aid = 2) > (2 rows) > > bench=# explain select * from pgbench_accounts where aid = 2 and false; > > QUERY PLAN > ------------------------------------------------- > Result (cost=0.00..26394.00 rows=1 width=97) > One-Time Filter: false > -> Seq Scan on pgbench_accounts (cost=0.00..26394.00 rows=1 width=97) > (3 rows) > > This seems like a special case of the "aborted plan cost", that is, when > the planner expects to abort a plan early, it nevertheless returns the > full cost for the non-aborted version of the query, rather than the > working cost, which is based on the abort. > > For example: > > bench=# create index on pgbench_accounts(bid); > CREATE INDEX > bench=# explain select * from pgbench_accounts where bid = 2; > QUERY PLAN > > ---------------------------------------------------------------------------------------------------------- > Index Scan using pgbench_accounts_bid_idx on pgbench_accounts > (cost=0.42..4612.10 rows=102667 width=97) > Index Cond: (bid = 2) > (2 rows) > > bench=# explain select * from pgbench_accounts where bid = 2 limit 1; > QUERY PLAN > > -------------------------------------------------------------------------------- > Limit (cost=0.00..0.28 rows=1 width=97) > -> Seq Scan on pgbench_accounts (cost=0.00..28894.00 rows=102667 > width=97) > Filter: (bid = 2) > (3 rows) > > So in this case, the top-level node returns a lower cost because the > planner knows that it will find a row with bid=2 fairly quickly in the > seq scan. But in the WHERE FALSE example, that scan *is* the top-level > node, so the planner returns a fictitious cost for the whole query. > > Or is there something else at work here? > > [1] > http://www.postgresql.org/message-id/20150225194953.2546.86836@wrigleys.postgresql.org > -- 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