Re: WHERE with ORDER not using the best index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jugnooken <ken(at)jugnoo(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: WHERE with ORDER not using the best index
Date: 2014-01-30 16:00:41
Message-ID: 32497.1391097641@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

jugnooken <ken(at)jugnoo(dot)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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Dattaram Porob 2014-01-30 17:43:37 Re: Increased memory utilization by pgsql backend after upgrade from 9.1.3 to 9.2.6
Previous Message jugnooken 2014-01-30 01:47:19 Re: WHERE with ORDER not using the best index