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

Re: Using Between

From: Craig James <craig_james(at)emolecules(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Using Between
Date: 2010-08-28 00:41:53
Message-ID: 4C785B51.1020105@emolecules.com (view raw or flat)
Thread:
Lists: pgsql-performance
On 8/27/10 5:21 PM, Ozer, Pam wrote:
> I have a query that
>
> Select Distinct VehicleId
>
>  From Vehicle
>
> Where VehicleMileage between 0 and 15000.
>
> I have an index on VehicleMileage. Is there another way to put an index on a between? The index is not being picked up. It does get picked up when I run
>
> Select Distinct VehicleId
>
>  From Vehicle
>
> Where VehicleMileage = 15000.
>
> I just want to make sure that there is not a special index I should be using.

You need to post EXPLAIN ANALYZE of your query. It could be that an index scan is actually not a good plan (for example, a sequential scan might be faster if most of your vehicles have low mileage).  Without the EXPLAIN ANALYZE, there's no way to say what's going on.

Did you ANALYZE your database after you loaded the data?

Craig

> Thanks
>
> *Pam Ozer*
>


In response to

Responses

pgsql-performance by date

Next:From: C├ędric VillemainDate: 2010-08-28 10:17:50
Subject: Re: write barrier question
Previous:From: Ozer, PamDate: 2010-08-28 00:21:48
Subject: Using Between

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