Re: index speed and failed expectations? - Mailing list pgsql-general

From Tom Lane
Subject Re: index speed and failed expectations?
Date
Msg-id 4322.1217859613@sss.pgh.pa.us
Whole thread Raw
In response to Re: index speed and failed expectations?  ("Adam Rich" <adam.r@sbcglobal.net>)
List pgsql-general
"Adam Rich" <adam.r@sbcglobal.net> writes:
>> This query from the console:
>> select * from stats order by start_time;
>> takes 8 seconds before starting its output. Am I wrong in assuming that
>> the index on start_time should make ORDER BY orders of magnitude
>> faster?

> Postgresql won't use the index for queries like this.

"won't" -> "might not".  It all depends on the relative cost estimates
for indexscan vs seqscan + sort.  For a large table it's quite likely
that the latter will be cheaper, because it has a better-localized
access pattern.

> (What postgresql lacks is a first_row/all_rows hint like oracle)

That's spelled "LIMIT" ;-).  Also, you can bias the choice in favor
of a fast-start plan if you use a cursor rather than a plain SELECT.
In that case the planner makes some allowance for the idea that
you might not want all the rows, or might be more interested in
getting the first ones quickly than minimizing the total time to
fetch all the rows.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: bytea encode performance issues
Next
From: Glyn Astill
Date:
Subject: Re: index speed and failed expectations?