Re: Index not used - now me

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: Index not used - now me
Дата
Msg-id 878yjcntra.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на Re: Index not used - now me  (Christoph Haller <ch@rodos.fzk.de>)
Ответы Re: Index not used - now me  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Christoph Haller <ch@rodos.fzk.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



В списке pgsql-sql по дате отправления:

Предыдущее
От: "Mark Roberts"
Дата:
Сообщение: timestamptz - problems
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Implementation of a bag pattern using rules