Re: [HACKERS] Solution for LIMIT cost estimation - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: [HACKERS] Solution for LIMIT cost estimation
Date
Msg-id 38A6DADB.D355E3C9@tm.ee
Whole thread Raw
In response to Solution for LIMIT cost estimation  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] Solution for LIMIT cost estimation  (Don Baccus <dhogaza@pacifier.com>)
List pgsql-hackers
Chris wrote:
> 
> Tom Lane wrote:
> >
> >         SELECT * FROM table WHERE x > 100 ORDER BY x LIMIT 1;
> 
> Could it _ever_ be faster to sort the tuples when there is already an
> index that can provide them in sorted order?

This has been discussed on this list several times, and it appears that
select+sort is quite often faster than index scan, mainly due to the fact 
that tables live on disk and disk accesses are expensive, and when doing 
index scans:

1- you have to scan two files (index and data), when they are on the same   disk it is much more 2 times slower than
sacnninga single file even  when doing it sequentially
 

2- scans on the both files are random access, so seek and latency times   come into play and readahead is useless

3- you often read the same data page many times

-------------
Hannu


pgsql-hackers by date:

Previous
From: Don Baccus
Date:
Subject: Re: [HACKERS] Solution for LIMIT cost estimation
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] Solution for LIMIT cost estimation