Re: select distinct and index usage - Mailing list pgsql-general

From Stephen Denne
Subject Re: select distinct and index usage
Date
Msg-id F0238EBA67824444BC1CB4700960CB4805110074@dmpeints002.isotach.com
Whole thread Raw
In response to Re: select distinct and index usage  ("David Wilson" <david.t.wilson@gmail.com>)
Responses Re: select distinct and index usage  ("David Wilson" <david.t.wilson@gmail.com>)
List pgsql-general
> Still doing the sequential scan on the table, but at least it's
> avoiding the expensive disk merge sort. It still seems as if I ought
> to be able to coax it into using an index for this type of query,
> though- especially since it's using one on the other table. Is there
> perhaps some way to reformulate the index in such a way as to make it
> more useful to the planner?

You're asking postgres to examine EVERY visible row (hence the sequential scan makes good sense), and tell you what
fieldvalues there are. 

You may be able to make use of an index by rearranging your query to generate a series between your min & max values,
testingwhether each value is in your table. 

You've got 4252 distinct values, but what is the range of max - min? Say it's 5000 values, you'd do 5000 lookups via an
index,unless postgres thought that the number of index based lookups where going to be more expensive than reading the
entiretable. 

Regards,
Stephen Denne.

Disclaimer:
At the Datamail Group we value team commitment, respect, achievement, customer focus, and courage. This email with any
attachmentsis confidential and may be subject to legal privilege.  If it is not intended for you please advise by reply
immediately,destroy it and do not copy, disclose or use it in any way. 
__________________________________________________________________
  This email has been scanned by the DMZGlobal Business Quality
              Electronic Messaging Suite.
Please see http://www.dmzglobal.com/dmzmessaging.htm for details.
__________________________________________________________________



pgsql-general by date:

Previous
From: Colin Wetherbee
Date:
Subject: Re: Most Occurring Value
Next
From: Manuel Sugawara
Date:
Subject: Cannot use a standalone backend to VACUUM in "postgres""