pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: typea@l-i-e.com
To: pgsql-performance@postgresql.org
Subject: Cursor rowcount
Date: Mon, 13 Jan 2003 13:33:19 -0800 (PST)
Message-ID: <49456.216.80.95.13.1042493599.squirrel@www.l-i-e.com> (raw)

Short Version:

I've read the idocs and Notes and Googled a fair amount, honest. :-)

What's the most efficient way of determining the number of rows in a
cursor's result set if you really *DO* need that?  (Or, rather, if your
client specifically asked for features that require that.)


Long Version:
I'm not finding any way in the docs of asking a cursor how many rows total
are in the result set, even if I do "move 1000000 in foo", knowing a
priori that 1000000 is far more than could be returned.

Oracle docs seem to have a SQL.%ROWCOUNT which gives the answer, provided
one has moved beyond the last row...  If I'm reading the Oracle docs
right...

Anyway.  I could find nothing similar in PostgreSQL, even though it seems
reasonable, even for a Portal, provided one is willing to do the "move X"
for X sufficiently high -- And, in fact, psql outputs the precise number
of rows when I do that in the psql monitor, so at some level PostgreSQL
"knows" the answer I want, but I can't get that "MOVE XX" output into PHP,
as far as I can tell.  (Can I?)

I suppose I could, in theory, use PHP to fire up psql, but that's not
exactly going to be efficient, much less pleasant. :-)

Using PHP, if it matters.  I guess it does since maybe other APIs have
some way to access that number I want -- psql sure seems to print it out
when one goes over the edge.

Given that the count(*) queries take just as long as the actual
data-retrieval queries, and that some of my queries take too long as it is
(like, a minute for a 4-term full text search)...

I've written and am about to benchmark a binary search using a bunch of
"move X" "fetch 1" "move backward 1" "move backward X" and then using Ye
Olde Low/High guessing game algorithm to find the number of rows, but I'm
hoping for something better from the optimization experts.

Sorry this got a bit long, but I wanted to be clear about where I've been
and gone, rather than leave you guessing. :-)

Hope I didn't miss some obvious solution/documentation "out there"...






view thread (5+ messages)  latest in thread

Message-ID: <49456.216.80.95.13.1042493599.squirrel@www.l-i-e.com>
Permalink:  ../49456.216.80.95.13.1042493599.squirrel@www.l-i-e.com/
Also on:    postgresql.org/message-id/49456.216.80.95.13.1042493599.squirrel@www.l-i-e.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: typea@l-i-e.com
  Subject: Re: Cursor rowcount
  In-Reply-To: <49456.216.80.95.13.1042493599.squirrel@www.l-i-e.com>
  References: <49456.216.80.95.13.1042493599.squirrel@www.l-i-e.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox