Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z7YGL-0000Sb-1a for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jun 2015 00:09:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Z7YGK-0005ip-Gd for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jun 2015 00:09:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Z7YFW-00052P-3s for pgsql-bugs@postgresql.org; Wed, 24 Jun 2015 00:09:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1Z7YFT-0000ly-Mr for pgsql-bugs@postgresql.org; Wed, 24 Jun 2015 00:09:05 +0000 MIME-Version: 1.0 Subject: BUG #13464: Optimizer fails to use partial index on boolean when selected via "IS" operator. To: pgsql-bugs@postgresql.org From: corey.huinker@gmail.com Date: Wed, 24 Jun 2015 00:08:36 +0000 Message-ID: <20150624000836.3876.241@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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