Re: WHERE with ORDER not using the best index - Mailing list pgsql-performance

From Tom Lane
Subject Re: WHERE with ORDER not using the best index
Date
Msg-id 32497.1391097641@sss.pgh.pa.us
Whole thread Raw
In response to Re: WHERE with ORDER not using the best index  (jugnooken <ken@jugnoo.com>)
List 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 by date:

Previous
From: Jim Treinen
Date:
Subject: Slow query on join with Date >=
Next
From: Sergey Konoplev
Date:
Subject: Re: trick the query optimiser to skip some optimisations