From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Guillaume Lelarge <guillaume(at)lelarge(dot)info> |
Cc: | Luca Ferrari <fluca1978(at)infinito(dot)it>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: help understanding explain output |
Date: | 2011-02-15 23:23:44 |
Message-ID: | 14287.1297812224@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Guillaume Lelarge <guillaume(at)lelarge(dot)info> writes:
> Le 15/02/2011 15:49, Luca Ferrari a crit :
>> So a sequential scan. I know that the optimizer will not consider an index if
>> it is not filtering, but I don't understand exactly why in this case.
> Accessing a page in an index is way costier then accessing a page in an
> table with a sequential scan. By default, random_page_cost is 4 times
> seq_page_cost. So it's not really surprising that when you want to get
> half the table, PostgreSQL won't use the index. You would need to have a
> really selective query to make an index scan interesting to use.
As a rough rule of thumb, a regular indexscan is useful when the query
selects not more than about 1% of rows, while a bitmap indexscan is
useful up to about 10% of the table. More than that, a seqscan is the
right thing to use. If the table's row ordering is very well correlated
with the index, or if you've reduced random_page_cost, the cutoff
percentages are higher. But in no case is it likely to be a win to use
an index to fetch half of a table.
(BTW, in the given test case, the reason the planner isn't using the
index even with seqscan off is that it *can't*. You got the WHERE
condition backwards.)
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | David Johnston | 2011-02-16 00:14:04 | Re: subset of attributes |
Previous Message | Chris | 2011-02-15 23:08:52 | Re: help understanding explain output |