Re: Doesn't use index, why?

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Marco Catunda <catunda(at)pobox(dot)com>, Dave Smith <dave(at)candata(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Doesn't use index, why?
Date: 2001-01-09 06:09:37
Message-ID: 200101090609.BAA26593@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> 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.

The only other workaround is to CLUSTER the table on an index, then
force an index scan. That _may_ be faster.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-01-09 06:36:04 Re: Advice on stored proc error handling versus Sybase?
Previous Message Bruce Momjian 2001-01-09 05:50:56 Re: 7.1 PL/pgSQL EXECUTE Command