pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedCursor rowcount
5+ messages / 3 participants
[nested] [flat]
* Cursor rowcount
@ 2003-01-13 21:33 typea@l-i-e.com
0 siblings, 1 reply; 5+ messages in thread
From: typea@l-i-e.com @ 2003-01-13 21:33 UTC (permalink / raw)
To: pgsql-performance
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"...
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Cursor rowcount
@ 2003-01-13 22:22 Tom Lane <tgl@sss.pgh.pa.us>
parent: typea@l-i-e.com
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2003-01-13 22:22 UTC (permalink / raw)
To: typea@l-i-e.com; +Cc: pgsql-performance
<typea@l-i-e.com> writes:
> 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.
regression=# begin;
BEGIN
regression=# declare c cursor for select * from int8_tbl;
DECLARE CURSOR
regression=# move all in c;
MOVE 5 <-----------------------
regression=# end;
COMMIT
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Cursor rowcount
@ 2003-01-14 01:05 typea@l-i-e.com
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: typea@l-i-e.com @ 2003-01-14 01:05 UTC (permalink / raw)
To: pgsql-performance
> <typea@l-i-e.com> writes:
>> 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.
>
> regression=# begin;
> BEGIN
> regression=# declare c cursor for select * from int8_tbl;
> DECLARE CURSOR
> regression=# move all in c;
> MOVE 5 <-----------------------
> regression=# end;
> COMMIT
>
> regards, tom lane
Yes, but as noted in my longer version, that number does not seem to "come
through" the PHP API.
I've tried calling just about every function I can in the PHP API in a
test script, and none of them give me that number.
At least, none that I can find...
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Cursor rowcount
@ 2003-01-14 04:19 Tom Lane <tgl@sss.pgh.pa.us>
parent: typea@l-i-e.com
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2003-01-14 04:19 UTC (permalink / raw)
To: typea@l-i-e.com; +Cc: pgsql-performance
<typea@l-i-e.com> writes:
> Yes, but as noted in my longer version, that number does not seem to "come
> through" the PHP API.
Perhaps not, but you'd have to ask the PHP folk about it. This question
surely doesn't belong on pgsql-performance ...
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Cursor rowcount
@ 2003-01-14 09:12 Ron Johnson <ron.l.johnson@cox.net>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Ron Johnson @ 2003-01-14 09:12 UTC (permalink / raw)
To: pgsql-performance
On Mon, 2003-01-13 at 22:19, Tom Lane wrote:
> <typea@l-i-e.com> writes:
> > Yes, but as noted in my longer version, that number does not seem to "come
> > through" the PHP API.
>
> Perhaps not, but you'd have to ask the PHP folk about it. This question
> surely doesn't belong on pgsql-performance ...
Wellllll, maybe it does, since the /performance/ of a SELECT COUNT(*)
followed by a cursor certainly is lower than getting the count from
a system variable.
But still I agree, the PHP list seems more appropriate...
--
+------------------------------------------------------------+
| Ron Johnson, Jr. mailto:ron.l.johnson@cox.net |
| Jefferson, LA USA http://members.cox.net/ron.l.johnson |
| |
| "Basically, I got on the plane with a bomb. Basically, I |
| tried to ignite it. Basically, yeah, I intended to damage |
| the plane." |
| RICHARD REID, who tried to blow up American Airlines |
| Flight 63 |
+------------------------------------------------------------+
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2003-01-14 09:12 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-01-13 21:33 Cursor rowcount typea@l-i-e.com
2003-01-13 22:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-01-14 01:05 ` typea@l-i-e.com
2003-01-14 04:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-01-14 09:12 ` Ron Johnson <ron.l.johnson@cox.net>
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