Bug #848: Index on bigint column is unused in selects - Mailing list pgsql-bugs

From pgsql-bugs@postgresql.org
Subject Bug #848: Index on bigint column is unused in selects
Date
Msg-id 20021214203300.DCDD04758E6@postgresql.org
Whole thread Raw
Responses Re: Bug #848: Index on bigint column is unused in selects  (Neil Conway <neilc@samurai.com>)
List pgsql-bugs
Peter Roozemaal (mathfox@xs4all.nl) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
Index on bigint column is unused in selects

Long Description
PostgreSQL 7.2 will allways do a full table scan when the index field is a bigint. even with a "where bigkey = 99"
clause.

CREATE TABLE test1 (
    een     bigint  PRIMARY KEY,
    twee    int     UNIQUE NOT NULL,
    data    text);

peter=> explain select * from test1 where een > 0 and een < 1000;
NOTICE:  QUERY PLAN:
Seq Scan on test1  (cost=0.00..25.00 rows=5 width=44)
EXPLAIN

peter=> explain select * from test1 where een = 99;
NOTICE:  QUERY PLAN:
Seq Scan on test1  (cost=0.00..22.50 rows=1 width=44)
EXPLAIN

I expected two index scans here.

The same bug/feature is present in version 7.3

Sample Code
peter=> CREATE TABLE test1 (
    een     bigint  PRIMARY KEY,
    twee    int     UNIQUE NOT NULL,
    data    text);

-- fill table with 100000 rows --

peter=> explain select * from test1 where twee < 1000;
NOTICE:  QUERY PLAN:
Seq Scan on test1  (cost=0.00..22.50 rows=333 width=44)
EXPLAIN

peter=> explain select * from test1 where twee > 0 and twee < 1000;
NOTICE:  QUERY PLAN:
Index Scan using test1_twee_key on test1  (cost=0.00..17.08 rows=5 width=44)
EXPLAIN

peter=> explain select * from test1 where twee = 99;
NOTICE:  QUERY PLAN:
Index Scan using test1_twee_key on test1  (cost=0.00..4.82 rows=1 width=44)
EXPLAIN

peter=> explain select * from test1 where een > 0 and een < 1000;
NOTICE:  QUERY PLAN:
Seq Scan on test1  (cost=0.00..25.00 rows=5 width=44)
EXPLAIN

peter=> explain select * from test1 where een = 99;
NOTICE:  QUERY PLAN:
Seq Scan on test1  (cost=0.00..22.50 rows=1 width=44)
EXPLAIN

peter=> ANALYSE;
-- output --

peter=> explain select * from test1 where twee < 1000;
NOTICE:  QUERY PLAN:
Index Scan using test1_twee_key on test1  (cost=0.00..3.13 rows=10 width=99)
EXPLAIN

No file was uploaded with this report

pgsql-bugs by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: postmaster segfaults when pg_hba.cof is missing
Next
From: Frank van Vugt
Date:
Subject: v7.3 : \encoding doesn't show changes in client encoding that are not done with \encoding itself (i.e. set names/set client_encoding)