Re: [HACKERS] Solution for LIMIT cost estimation

From: Hannu Krosing <hannu(at)tm(dot)ee>
To: Chris <chris(at)bitmead(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] Solution for LIMIT cost estimation
Date: 2000-02-13 16:24:59
Message-ID: 38A6DADB.D355E3C9@tm.ee
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 sacnning a 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2000-02-13 16:53:49 Re: [HACKERS] Solution for LIMIT cost estimation
Previous Message Don Baccus 2000-02-13 14:51:37 Re: [HACKERS] Solution for LIMIT cost estimation