Re: Cursors: getting the number of tuples; moving backwards

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: am(at)fx(dot)ro
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Cursors: getting the number of tuples; moving backwards
Date: 2002-11-02 02:39:16
Message-ID: 20021102023916.GC2571@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-jdbc

On Fri, Nov 01, 2002 at 08:14:33PM +0200, am(at)fx(dot)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(at)svana(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-11-02 03:03:17 Re: Cursors: getting the number of tuples; moving backwards
Previous Message Bruce Momjian 2002-11-02 02:35:40 Re: [GENERAL] What user to defaults execute as?

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-11-02 03:03:17 Re: Cursors: getting the number of tuples; moving backwards
Previous Message Bruce Momjian 2002-11-02 02:35:40 Re: [GENERAL] What user to defaults execute as?

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tom Lane 2002-11-02 03:03:17 Re: Cursors: getting the number of tuples; moving backwards
Previous Message miguel angel rojas aquino 2002-11-01 22:09:44 jbuilder and timestamps