Re: Indexing question - Mailing list pgsql-performance

From Tom Lane
Subject Re: Indexing question
Date
Msg-id 4119.1087757106@sss.pgh.pa.us
Whole thread Raw
In response to Indexing question  (Stan Bielski <bielski@ece.cmu.edu>)
List pgsql-performance
Stan Bielski <bielski@ece.cmu.edu> writes:
>  Table "public.allflow_tv_mydoom"
>    Column   |  Type   | Modifiers
> ------------+---------+-----------
>  tv_s       | bigint  |
                ^^^^^^
> Indexes: allflow_tv_mydoom_x btree (tv_s)

> standb=# explain select * from allflow_tv_mydoom where tv_s < 1074200099
> and tv_s > 107506499;
> [ gives seqscan ]

This is a FAQ :-(.  Unadorned integer constants are taken to be int4
not int8 (unless they are too large for int4), and cross-data-type
comparisons are not indexable in existing releases.  So you have to
explicitly cast the comparison values to int8:

explain select * from allflow_tv_mydoom where tv_s < 1074200099::bigint
and tv_s > 107506499::bigint;

(or use the standard CAST syntax if you prefer).

7.5 will have a fix for this ancient annoyance.

BTW, is there a reason to be using tv_s+tv_us and not just a single
timestamptz column?

            regards, tom lane

pgsql-performance by date:

Previous
From: "Aaron"
Date:
Subject: Re: 50 000 000 Table entries and I have to do a keyword search HELP NEEDED
Next
From: Rod Taylor
Date:
Subject: Re: pg_fetch_array