Re: Index not used - now me

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Christoph Haller <ch(at)rodos(dot)fzk(dot)de>
Cc: paul(at)tmsl(dot)demon(dot)co(dot)uk (Paul Thomas), pgsql-sql(at)postgresql(dot)org
Subject: Re: Index not used - now me
Date: 2004-02-09 15:43:21
Message-ID: 878yjcntra.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Christoph Haller <ch(at)rodos(dot)fzk(dot)de> writes:

> Why appear? If the Index Scan has a Total runtime: 2.46 msec and the Seq Scan
> a Total runtime: 46.19 msec, then the Index Scan is much faster.
> Or am I completely off the track reading the explain analyze output?

To estimate the relative costs of a sequential scan and an index scan Postgres
has to take into account the likelihood the blocks needed will be the disk
cache. In your example your database is otherwise idle and the entire table is
small enough that the entire index is probably in cache.

This means that the random access pattern of the index isn't really hurting
the index scan at all. Whereas in a busy database with less available RAM the
random access pattern makes a big difference.

You could try raising effective_cache_size to give postgres a better chance at
guessing that all the blocks will be in cache. But that may no longer be true
when the query is run on a busy database.

You could also try lowering random_page_cost. Some people find as low as 1.2
or so to be useful, but that would almost certainly be lying to postgres about
the costs of random access and would cause it to use index scans aggressively
even when they're not faster.

--
greg

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2004-02-09 16:02:40 Re: Index not used - now me
Previous Message Mark Roberts 2004-02-09 15:02:56 timestamptz - problems