Re: [HACKERS] Solution for LIMIT cost estimation
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Chris <chris@bitmead.com>
Cc: pgsql-hackers@postgreSQL.org
Date: 2000-02-13T16:53:49Z
Lists: pgsql-hackers
Chris <chris@bitmead.com> writes: > Could it _ever_ be faster to sort the tuples when there is already an > index that can provide them in sorted order? Yes --- in fact usually, for large tables. Once your table gets too big for the disk cache to be effective, indexscan performance approaches one random-access page fetch per tuple. Sort performance behaves more or less as p*log(p) accesses for p pages; and a far larger proportion of those accesses are sequential than in the indexscan case. So the sort will win if you have more than log(p) tuples per page. Do the arithmetic... The optimizer's job would be far simpler if no-brainer rules like "indexscan is always better" worked. regards, tom lane