Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id BBBA66350B0 for ; Fri, 27 Aug 2010 21:42:04 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 14776-07 for ; Sat, 28 Aug 2010 00:41:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com [209.85.216.181]) by mail.postgresql.org (Postfix) with ESMTP id B230F635096 for ; Fri, 27 Aug 2010 21:41:57 -0300 (ADT) Received: by qyk33 with SMTP id 33so3471836qyk.19 for ; Fri, 27 Aug 2010 17:41:56 -0700 (PDT) Received: by 10.229.95.66 with SMTP id c2mr1019710qcn.85.1282956115978; Fri, 27 Aug 2010 17:41:55 -0700 (PDT) Received: from Craig-Jamess-MacBook-Pro.local (wsip-70-167-124-126.sd.sd.cox.net [70.167.124.126]) by mx.google.com with ESMTPS id f15sm5220299qcr.13.2010.08.27.17.41.54 (version=SSLv3 cipher=RC4-MD5); Fri, 27 Aug 2010 17:41:55 -0700 (PDT) Message-ID: <4C785B51.1020105@emolecules.com> Date: Fri, 27 Aug 2010 17:41:53 -0700 From: Craig James User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Using Between References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201008/301 X-Sequence-Number: 40144 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* >