Re: Index use in BETWEEN statement... - Mailing list pgsql-general

From Tom Lane
Subject Re: Index use in BETWEEN statement...
Date
Msg-id 1896.1127762243@sss.pgh.pa.us
Whole thread Raw
In response to Re: Index use in BETWEEN statement...  ("Cristian Prieto" <cristian@clickdiario.com>)
Responses Re: Index use in BETWEEN statement...
List pgsql-general
"Cristian Prieto" <cristian@clickdiario.com> writes:
> mydb=# explain analyze select locid from geoip_block where
> '216.230.158.50'::inet between start_block and end_block;

> As you see it still using a sequential scan in the table and ignores the
> index, any other suggestion?

That two-column index is entirely useless for this query; in fact btree
indexes of any sort are pretty useless.  You really need some sort of
multidimensional index type like rtree or gist.  There was discussion
just a week or three ago of how to optimize searches for intervals
overlapping a specified point, which is identical to your problem.
Can't remember if the question was about timestamp intervals or plain
intervals, but try checking the list archives.

            regards, tom lane

pgsql-general by date:

Previous
From: Raj Gupta
Date:
Subject: Re: Error migrating from 7.4.3 to 8.0.3
Next
From: Yonatan Ben-Nes
Date:
Subject: Re: How many insert + update should one transaction handle?