Re: Query not using index, please explain. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Query not using index, please explain.
Date
Msg-id 29777.984082783@sss.pgh.pa.us
Whole thread Raw
In response to Query not using index, please explain.  (Matthew Hagerty <mhagerty@voyager.net>)
List pgsql-hackers
Matthew Hagerty <mhagerty@voyager.net> writes:
> The query where the time_stamp < '03-01-2000' does not return any rows, the 
> 04-01-2000 date does return rows.  When I disable seqscan the query is 
> almost instant, but with it on, it takes about 3 or 4 minutes.  Why can't 
> the query planner use the index in the later case?

It *can* (and did, in two of the three examples you gave).  It just
doesn't think the indexscan is faster --- note the cost estimates.
Evidently the cost estimates are way off, probably because the estimated
number of selected rows is way off.

Have you done a VACUUM ANALYZE lately?  Not that that will help if the
distribution of timestamps is highly irregular :-(.  See the many past
discussions of these issues.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Checkpoint process signal handling seems wrong
Next
From: Richard Poole
Date:
Subject: Re: Query not using index, please explain.