Re: SELECT ignoring index even though ORDER BY and LIMIT present

Поиск
Список
Период
Сортировка
Искать
От
Matthew Wakeling
Тема
Re: SELECT ignoring index even though ORDER BY and LIMIT present
Дата
Msg-id
alpine.DEB.2.00.1006031110330.4083@aragorn.flymine.org
Ответ на
Список
Дерево обсуждения
SELECT ignoring index even though ORDER BY and LIMIT present Jori Jovanovich <jori@dimensiology.com>
Re: SELECT ignoring index even though ORDER BY and LIMIT present "Kevin Grittner" <Kevin.Grittner@wicourts.gov>
Re: SELECT ignoring index even though ORDER BY and LIMIT present Tom Lane <tgl@sss.pgh.pa.us>
Re: SELECT ignoring index even though ORDER BY and LIMIT present Bob Lunney <bob_lunney@yahoo.com>
Re: SELECT ignoring index even though ORDER BY and LIMIT present Jori Jovanovich <jori@dimensiology.com>
Re: SELECT ignoring index even though ORDER BY and LIMIT present Szymon Guz <mabewlun@gmail.com>
Re: SELECT ignoring index even though ORDER BY and LIMIT present Matthew Wakeling <matthew@flymine.org>
On Wed, 2 Jun 2010, Jori Jovanovich wrote:
> (2) Making the query faster by making the string match LESS specific (odd,
> seems like it should be MORE)

No, that's the way round it should be. The LIMIT changes it all. Consider 
if you have a huge table, and half of the entries match your WHERE clause. 
To fetch the ORDER BY ... LIMIT 20 using an index scan would involve 
accessing only on average 40 entries from the table referenced by the 
index. Therefore, the index is quick. However, consider a huge table that 
only has twenty matching entries. The index scan would need to touch every 
single row in the table to return the matching rows, so a sequential scan, 
filter, and sort would be much faster. Of course, if you had an index 
capable of answering the WHERE clause, that would be even better for that 
case.

Matthew

-- 
 Don't criticise a man until you have walked a mile in his shoes; and if
 you do at least he will be a mile behind you and bare footed.
В списке pgsql-performance по дате отправления
От: Joshua Tolley
Дата:
От: Merlin Moncure
Дата:
Сообщение: Re: Weird XFS WAL problem
FAQ