From: abrashears@justin.tv
To: pgsql-bugs@postgresql.org
Subject: BUG #12805: Planner estimates query at higher cost when execution can be skipped
Date: Wed, 25 Feb 2015 19:49:53 +0000
Message-ID: <20150225194953.2546.86836@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 12805
Logged by: Aaron Brashears
Email address: abrashears@justin.tv
PostgreSQL version: 9.3.5
Operating system: Linux kernel 3.13.0-73 64 bit
Description:
The issue appears to be when a SQL statement contains a clause which causes
no rows to be returned and the planner detects this condition, the returned
plan is more expensive than a plan that actually has to run and read
things.
To reproduce the issue:
create table trivial_plans (
id integer primary key
);
insert into trivial_plans (id) values (1),(2),(3),(4),(5),(6),(7);
-- simple query
explain select * from trivial_plans where id = 5;
QUERY PLAN
---------------------------------------------------------------------------------------------
Index Only Scan using trivial_plans_pkey on trivial_plans (cost=0.15..6.17
rows=1 width=4)
Index Cond: (id = 5)
-- query which never returns a row because of "0=1" where clause which is
always false.
explain select * from trivial_plans where id = 5 and 0 = 1;
QUERY PLAN
--------------------------------------------------------------------
Result (cost=0.00..34.00 rows=1 width=4)
One-Time Filter: false
-> Seq Scan on trivial_plans (cost=0.00..34.00 rows=1 width=4)
Note that the cost of the query which will never need to execute or read
rows is estimated at a cost of 0.00..34.0 -- higher than a plan that
actually has to do work and estimated with a cost cap of 6.17. I would
expect the cost of the second query cost to be 0.00..0.01 or 0.00..0.0 and
even rows = 0.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: abrashears@justin.tv
Subject: Re: BUG #12805: Planner estimates query at higher cost when execution can be skipped
In-Reply-To: <20150225194953.2546.86836@wrigleys.postgresql.org>
References: <20150225194953.2546.86836@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox