pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Stark <gsstark@mit.edu>
To: Carlos Benkendorf <carlosbenkendorf@yahoo.com.br>
Cc: pgsql-performance@postgresql.org
Subject: Re: Is the optimizer choice right?
Date: 19 Dec 2005 15:54:29 -0500
Message-ID: <87r788ajui.fsf@stark.xeocode.com> (raw)
In-Reply-To: <20051219202258.30740.qmail@web35510.mail.mud.yahoo.com>
References: <20051219202258.30740.qmail@web35510.mail.mud.yahoo.com>


Carlos Benkendorf <carlosbenkendorf@yahoo.com.br> writes:

> Hi,
>    
>   We´re running 8.03 and I´m trying to understand why the following SELECT doesn´t use iarchave05 index.
>    
>   If you disable seqscan then iarchave05 index is used and the total runtime
>   is about 50% less than when iarchave05 index is not used.
>    
>   Why is the optimizer not using iarchave05 index?

The optimizer is calculating that the index scan would require more i/o than
the sequential scan and be slower. The only reason it isn't is because most of
the data is cached from your previous tests.

If this test accurately represents the production situation and most of this
data is in fact routinely cached then you might consider lowering the
random_page_cost to represent this. The value of 4 is reasonable for actual
i/o but if most of the data is cached then you effectively are getting
something closer to 1. Try 2 or 1.5 or so.

Note that the sequential scan has to scan the entire table. The index scan has
to scan the entire table *and* the entire index, and in a pretty random order.
If the table didn't fit entirely in RAM it would end up reading the entire
table several times over.

-- 
greg




view thread (2+ messages)

Message-ID: <87r788ajui.fsf@stark.xeocode.com>
Permalink:  ../87r788ajui.fsf@stark.xeocode.com/
Also on:    postgresql.org/message-id/87r788ajui.fsf@stark.xeocode.com

 · 

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: gsstark@mit.edu, carlosbenkendorf@yahoo.com.br
  Subject: Re: Is the optimizer choice right?
  In-Reply-To: <87r788ajui.fsf@stark.xeocode.com>

* 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