Bug in predicate indexes?

From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Bug in predicate indexes?
Date: 2005-11-18 03:57:43
Message-ID: 437D5137.6020903@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

It appears that predicate indexes won't uses indexes on int8 columns
unless they are casted:

test=# select count(*) from test_key ;
count
--------
120617
(1 row)

test=# alter table test_key ALTER column id set statistics 25;
ALTER TABLE
test=# analyze test_key ;
test=# create index foo on test_key (id) where id >= 50000;
CREATE INDEX
test=# analyze;
ANALYZE
test=# explain analyze select * from test_key where id > 50000;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------
Seq Scan on test_key (cost=0.00..2276.71 rows=69768 width=16) (actual
time=23.186..289.406 rows=70617 loops=1)
Filter: (id > 50000)
Total runtime: 516.917 ms
(3 rows)

test=# create index foo on test_key (id) where id >= 50000::bigint;
CREATE INDEX
test=# analyze;
ANALYZE
test=# explain analyze select * from test_key where id > 50000::bigint;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Index Scan using foo on test_key (cost=0.00..1602.88 rows=70806
width=16) (actual time=0.080..264.001 rows=70617 loops=1)
Index Cond: (id > 50000::bigint)
Total runtime: 496.160 ms
(3 rows)

test=# explain analyze select * from test_key where id > 50000;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Index Scan using foo on test_key (cost=0.00..1602.88 rows=70806
width=16) (actual time=0.116..262.952 rows=70617 loops=1)
Index Cond: (id > 50000)
Total runtime: 488.943 ms
(3 rows)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2005-11-18 04:13:39 Re: Improving count(*)
Previous Message Ferindo Middleton 2005-11-18 03:54:36 BUG #2052: Federal Agency Tech Hub Refuses to Accept Postgresql on Network because of Security Vulnerabilities