From: corey.huinker@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #13464: Optimizer fails to use partial index on boolean when selected via "IS" operator.
Date: Wed, 24 Jun 2015 00:08:36 +0000
Message-ID: <20150624000836.3876.241@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: 13464
Logged by: Corey Huinker
Email address: corey.huinker@gmail.com
PostgreSQL version: 9.4.2
Operating system: Ubuntu 14.04
Description:
Correct index is used on "WHERE y" and "WHERE y = true" but not "WHERE y IS
TRUE".
[local]:ubuntu@test# create table sample_table(x integer not null, y boolean
default false not null);
CREATE TABLE
Time: 6.025 ms
[local]:ubuntu@test# insert into sample_table(x) select t.n from
generate_series(1,100000) as t(n);
INSERT 0 100000
Time: 143.815 ms
[local]:ubuntu@test# create index sample_table_i1 on sample_table(x);
CREATE INDEX
Time: 46.622 ms
[local]:ubuntu@test# create index sample_table_i2 on sample_table(x) where
y;
CREATE INDEX
Time: 16.076 ms
[local]:ubuntu@test# update sample_table set y = true where x % 100 = 0;
UPDATE 1000
Time: 47.548 ms
[local]:ubuntu@test# explain select * from sample_table where x < 10000 and
y = true;
QUERY PLAN
------------------------------------------------------------------------------------
Index Scan using sample_table_i2 on sample_table (cost=0.28..1.29 rows=1
width=5)
Index Cond: (x < 10000)
(2 rows)
Time: 1.321 ms
[local]:ubuntu@test# explain select * from sample_table where x < 10000 and
y is true;
QUERY PLAN
--------------------------------------------------------------------------------------
Index Scan using sample_table_i1 on sample_table (cost=0.29..252.14 rows=1
width=5)
Index Cond: (x < 10000)
Filter: (y IS TRUE)
(3 rows)
Time: 0.369 ms
[local]:ubuntu@test# explain select * from sample_table where x < 10000 and
y;
QUERY PLAN
------------------------------------------------------------------------------------
Index Scan using sample_table_i2 on sample_table (cost=0.28..1.29 rows=1
width=5)
Index Cond: (x < 10000)
(2 rows)
--
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: corey.huinker@gmail.com
Subject: Re: BUG #13464: Optimizer fails to use partial index on boolean when selected via "IS" operator.
In-Reply-To: <20150624000836.3876.241@wrigleys.postgresql.org>
References: <20150624000836.3876.241@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