pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jugnooken <ken@jugnoo.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: WHERE with ORDER not using the best index
Date: Thu, 30 Jan 2014 11:00:41 -0500
Message-ID: <32497.1391097641@sss.pgh.pa.us> (raw)
In-Reply-To: <1391046439075-5789624.post@n5.nabble.com>
References: <1391030357379-5789581.post@n5.nabble.com>
	<9852.1391037355@sss.pgh.pa.us>
	<1391046439075-5789624.post@n5.nabble.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (4+ messages)

Message-ID: <32497.1391097641@sss.pgh.pa.us>
Permalink:  ../32497.1391097641@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/32497.1391097641@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ken@jugnoo.com
  Subject: Re: WHERE with ORDER not using the best index
  In-Reply-To: <32497.1391097641@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox