Re: WHERE with ORDER not using the best index

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: WHERE with ORDER not using the best index
Дата
Msg-id 32497.1391097641@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: WHERE with ORDER not using the best index  (jugnooken <ken@jugnoo.com>)
Список pgsql-performance
jugnooken <ken@jugnoo.com> writes:
> Unfortunately, pg still thinks using
> index_social_feed_feed_items_on_social_feed_id is faster although they are
> about the same size :(. Any idea?

On further reflection, the cost estimate that is weird for this number of
rows is not the large one for your preferred index, but the small estimate
for the one the planner likes.  My guess is that that must be happening
because the latter index is nearly perfectly correlated with the table's
physical order, whereas yours is more or less random relative to table
order.

The fact that the former index is actually faster in use means that in
your environment, random access into the table is pretty cheap, which
means you should consider decreasing random_page_cost.  But first it'd
be a good idea to confirm that your test case is actually representative
of production behavior --- it's very easy to get fooled by all-in-cache
measurements, which are not reliable guides unless your database does in
fact fit in RAM.

            regards, tom lane


В списке pgsql-performance по дате отправления:

Предыдущее
От: Jim Treinen
Дата:
Сообщение: Slow query on join with Date >=
Следующее
От: Sergey Konoplev
Дата:
Сообщение: Re: trick the query optimiser to skip some optimisations