Re: Doesn't use index, why? - Mailing list pgsql-general

From Tom Lane
Subject Re: Doesn't use index, why?
Date
Msg-id 10310.978714015@sss.pgh.pa.us
Whole thread Raw
In response to Re: Doesn't use index, why?  (Marco Catunda <catunda@pobox.com>)
Responses Re: Doesn't use index, why?
List 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 by date:

Previous
From: martin.chantler@convergys.com
Date:
Subject: Re: ODBC failure
Next
From: Tom Lane
Date:
Subject: Re: PL/pgSQL NOT NULL variables