Skip site navigation (1) Skip section navigation (2)

Index use in BETWEEN statement...

From: "Cristian Prieto" <cristian(at)clickdiario(dot)com>
To: <pgsql-performance(at)postgresql(dot)org>
Subject: Index use in BETWEEN statement...
Date: 2005-09-23 22:03:11
Message-ID: 20050923220857.3A0841001E@mail.clickdiario.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-performance
Hello pals, I have the following table in Postgresql 8.0.1

Mydb# \d geoip_block
Table "public.geoip_block"
   Column    |  Type  | Modifiers
-------------+--------+-----------
 locid       | bigint |
 start_block | inet   |
 end_block   | inet   |

mydb# explain analyze select locid from geoip_block where
'216.230.158.50'::inet between start_block and end_block;
                                                      QUERY PLAN
----------------------------------------------------------------------------
-------------------------------------------
 Seq Scan on geoip_block  (cost=0.00..142772.86 rows=709688 width=8) (actual
time=14045.384..14706.927 rows=1 loops=1)
   Filter: (('216.230.158.50'::inet >= start_block) AND
('216.230.158.50'::inet <= end_block))
 Total runtime: 14707.038 ms

Ok, now I decided to create a index to "speed" a little the query

Mydb# create index idx_ipblocks on geoip_block(start_block, end_block);
CREATE INDEX

clickad=# explain analyze select locid from geoip_block where
'216.230.158.50'::inet between start_block and end_block;
                                                      QUERY PLAN
----------------------------------------------------------------------------
------------------------------------------
 Seq Scan on geoip_block  (cost=0.00..78033.96 rows=230141 width=8) (actual
time=12107.919..12610.199 rows=1 loops=1)
   Filter: (('216.230.158.50'::inet >= start_block) AND
('216.230.158.50'::inet <= end_block))
 Total runtime: 12610.329 ms
(3 rows)

I guess the planner is doing a sequential scan in the table, why not use the
compound index? Do you have any idea in how to speed up this query?

Thanks a lot!


Responses

pgsql-performance by date

Next:From: Mark KirkwoodDate: 2005-09-24 01:40:25
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
Previous:From: Tom LaneDate: 2005-09-23 21:12:49
Subject: Re: Query slower on 8.0.3 (Windows) vs 7.3 (cygwin)

pgsql-general by date

Next:From: hildebardoDate: 2005-09-24 00:55:32
Subject: question about to return two diferent tables from a function
Previous:From: Tony WassonDate: 2005-09-23 21:46:52
Subject: Re: Getting the amount of overlap when using OVERLAPS

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group