Re: select distinct and index usage
От
Stephen Denne
Тема
Re: select distinct and index usage
Дата
Msg-id
F0238EBA67824444BC1CB4700960CB4805110074@dmpeints002.isotach.com
Ответ на
Re: select distinct and index usage (David Wilson)
Список
Дерево обсуждения
select distinct and index usage "David Wilson" <david.t.wilson@gmail.com>
Re: select distinct and index usage Martijn van Oosterhout <kleptog@svana.org>
Re: select distinct and index usage Craig Ringer <craig@postnewspapers.com.au>
Re: select distinct and index usage "David Wilson" <david.t.wilson@gmail.com>
Re: select distinct and index usage Alban Hertroys <dalroi@solfertje.student.utwente.nl>
Re: select distinct and index usage "David Wilson" <david.t.wilson@gmail.com>
Re: select distinct and index usage Alban Hertroys <dalroi@solfertje.student.utwente.nl>
Re: select distinct and index usage "Joshua D. Drake" <jd@commandprompt.com>
Re: select distinct and index usage "David Wilson" <david.t.wilson@gmail.com>
Re: select distinct and index usage Tom Lane <tgl@sss.pgh.pa.us>
Re: select distinct and index usage Alvaro Herrera <alvherre@commandprompt.com>
Re: select distinct and index usage Tom Lane <tgl@sss.pgh.pa.us>
Re: select distinct and index usage Gregory Stark <stark@enterprisedb.com>
Re: select distinct and index usage Alvaro Herrera <alvherre@commandprompt.com>
Re: select distinct and index usage Gregory Stark <stark@enterprisedb.com>
Re: select distinct and index usage "David Wilson" <david.t.wilson@gmail.com>
Re: select distinct and index usage Alvaro Herrera <alvherre@commandprompt.com>
Re: select distinct and index usage "Stephen Denne" <Stephen.Denne@datamail.co.nz>
Re: select distinct and index usage "David Wilson" <david.t.wilson@gmail.com>
Re: select distinct and index usage "Stephen Denne" <Stephen.Denne@datamail.co.nz>
> 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 field values 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, testing whether 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 entire table.
Regards,
Stephen Denne.
Disclaimer:
At the Datamail Group we value team commitment, respect, achievement, customer focus, and courage. This email with any attachments is 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 по дате отправления
От: Manuel Sugawara
Дата: