Re: Doesn't use index, why?
| От | Tom Lane |
|---|---|
| Тема | Re: Doesn't use index, why? |
| Дата | |
| Msg-id | 10310.978714015@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Re: Doesn't use index, why? (Marco Catunda <catunda@pobox.com>) |
| Ответы |
Re: Doesn't use index, why?
|
| Список | pgsql-general |
Marco Catunda <catunda@pobox.com> writes:
> naslog=# explain select * from desconexao where time < '2000-12-10';
> NOTICE: QUERY PLAN:
> Seq Scan on desconexao (cost=0.00..19547.71 rows=231489 width=103)
> naslog=# explain select * from desconexao where time >=
> '2000-12-10';
> NOTICE: QUERY PLAN:
> Seq Scan on desconexao (cost=0.00..19547.71 rows=427128 width=103)
> The number of records are:
> naslog=# select count(*) from desconexao where time >= '2000-12-10';
> count
> --------
> 585789
> (1 row)
> naslog=# select count(*) from desconexao where time < '2000-12-10';
> count
> -------
> 72828
> (1 row)
In this case the planner is doing *exactly* the right thing; it is
smarter than you are. If you want to prove it, force the planner to
use an indexscan by doing SET ENABLE_SEQSCAN TO OFF. Then time the
query, and compare the runtime against the seqscan version.
The bottom line here is that a query that needs to touch more than a
few percent of the rows in a table is better off being done as a
seqscan.
regards, tom lane
В списке pgsql-general по дате отправления: