Re: Cursors: getting the number of tuples; moving backwards - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Cursors: getting the number of tuples; moving backwards
Date
Msg-id 20021102023916.GC2571@svana.org
Whole thread Raw
In response to Re: Cursors: getting the number of tuples; moving backwards  (am@fx.ro)
Responses Re: Cursors: getting the number of tuples; moving backwards  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Fri, Nov 01, 2002 at 08:14:33PM +0200, am@fx.ro wrote:
> On Fri, Nov 01, 2002 at 07:23:29PM +1100, Martijn van Oosterhout wrote:
> > That would work. But why do you need to know the total beforehand? You could
> > just do a FETCH ALL and then use PQntuples to get the number.
>
> If the table has, let's say, 10000 rows, it's unlikely that the user
> will ever browse all of them ( my program permits the user to set some
> filters ; the interface is ncurses-based).  Fetching everything
> would be unnecessary.
>
> So, for speed reasons, i prefer to fetch maximum 500 rows.
> But i want to display in the screen's corner the total number
> of rows .

Maybe do what google does. If there's lots of rows, give an estimate. I
don't know how they do it but if there are more than 1000 rows then the user
probably won't care if you wrote 1000, 2000 or a million.

Maybe some whacky curve fitting. If there's still a 98% match after 100
matches, there must be around 5000 matches.

> > Interesting idea. I'm not sure whether MOVE actually executes the query or
> > not.
>
> I guess it doesn't execute the whole query. MOVE ALL is *much*
> faster than FETCH ALL + PQcmdTuples

Curious. I wonder how it does it then.

--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> There are 10 kinds of people in the world, those that can do binary
> arithmetic and those that can't.

Attachment

pgsql-general by date:

Previous
From: Mike Mascari
Date:
Subject: Re: how to terminate a process when kill fails
Next
From: Tom Lane
Date:
Subject: Re: Cursors: getting the number of tuples; moving backwards