Re: shouldn't postgres know the numer of rows in a (sorted) result-set before returning the first row? - Mailing list pgsql-general

From Thies C. Arntzen
Subject Re: shouldn't postgres know the numer of rows in a (sorted) result-set before returning the first row?
Date
Msg-id C6F3D82E-3A37-426A-BD5B-913510CFA3CF@thieso.net
Whole thread Raw
In response to Re: shouldn't postgres know the numer of rows in a (sorted) result-set before returning the first row?  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: shouldn't postgres know the numer of rows in a (sorted) result-set before returning the first row?  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general

Am 16.11.2005 um 14:49 schrieb Martijn van Oosterhout:


i understand that postgres has to read every row from the heap to make 

sure that they are all still valid and count. but from my understanding 

query (a) would have something like an uncorrected count (somewhere 

internally) for the whole query as it has to performed an "order by" on 

the result-set before returning the first row.


Not if you have an index on "found_time". In that case it can return

the top 50 without even looking at most of the table. That's what

indexes are for. The only estimate it has is the one in EXPLAIN, and it

can find that without running the query at all.


hey martijn,

my question is more in the line of


whereby my special case is all about beeing able to provide an [possible inaccuate] count for a query if possible: my understanding is that would be the case if the "where clase" and the "order by" clause have been satisfied from the indices and the only step left is to validate the records in the result by reading them from the heap. 

and -again- i'm not asking for a new feature but i'd like to play with it and am asking for hackers advice;-)

what am i missing?
re, thies

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: shouldn't postgres know the numer of rows in a (sorted) result-set before returning the first row?
Next
From: Andreas Seltenreich
Date:
Subject: Re: Wrong rows selected with view