dbTalk Databases Forums  

How big is my result set?

comp.databases.informix comp.databases.informix


Discuss How big is my result set? in the comp.databases.informix forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Scott Burns
 
Posts: n/a

Default How big is my result set? - 09-10-2003 , 09:49 PM







Hi,
I've a google search showed me this question has been mentioned, but
never seems to be asked or anwered directly:

I am running SE, and have made a select cursor I traverse using "Next"
and "Prev" buttons in my C application. I want my buttons to becomes
insesnsitive when I hit either the start or the end of the set ( cant go
further, and want the user to know that ).

I have a function that figures out if I'm at the start or end, even
taking into account any records I've deleted from my set ( but which
still have a blank entry ). My application skips over the blank
entries. Unfortunately, I need to know what the theoretically last
entry in the set is, or, in other words, how big is the set I just selected?

At the moment I traverse the list just after selection but before
display, counting as I go. For a set of 6500 odd records this takes
well over a minute on my hardware. I could use a count(*) but it would
have to be a seperate call. I'm worried that if an entry is added or
deleted my application may either never think it is at the end, or will
miss a record. Is there a way to embed the count(*) into my select
statement I use for my cursor, returning the total count of all rows on
each row?

My select statements are always in the form "SELECT <key value> FROM
<table> WHERE ..." with no order by, groups etc.


--
Scott Burns
Mirrabooka Systems

Tel +61 7 3857 7899
Fax +61 7 3857 1368


Reply With Quote
  #2  
Old   
Gorazd Hribar Rajteric
 
Posts: n/a

Default Re: How big is my result set? - 09-11-2003 , 02:27 AM






You can use SQLCA structure - more specific sqlca.sqlerrd[0], but this is
only an estimate(!). Documentation says, that actual number of rows in a
result set is not guaranteed to be accurate unless you've scrolled through
the whole result set. You can get more information on SQLCA record on:
http://www.dbcenter.cise.ufl.edu/tri...lc/11.fm3.html

Two more good sites are:
http://www.dbcenter.cise.ufl.edu/tri...ex/global.html and
http://www.docs.rinet.ru:8080/InforSmes/index.htm

Gorazd

"Scott Burns" <scott (AT) mirrabooka (DOT) com> wrote

Quote:
Hi,
I've a google search showed me this question has been mentioned, but
never seems to be asked or anwered directly:

I am running SE, and have made a select cursor I traverse using "Next"
and "Prev" buttons in my C application. I want my buttons to becomes
insesnsitive when I hit either the start or the end of the set ( cant go
further, and want the user to know that ).

I have a function that figures out if I'm at the start or end, even
taking into account any records I've deleted from my set ( but which
still have a blank entry ). My application skips over the blank
entries. Unfortunately, I need to know what the theoretically last
entry in the set is, or, in other words, how big is the set I just
selected?

At the moment I traverse the list just after selection but before
display, counting as I go. For a set of 6500 odd records this takes
well over a minute on my hardware. I could use a count(*) but it would
have to be a seperate call. I'm worried that if an entry is added or
deleted my application may either never think it is at the end, or will
miss a record. Is there a way to embed the count(*) into my select
statement I use for my cursor, returning the total count of all rows on
each row?

My select statements are always in the form "SELECT <key value> FROM
table> WHERE ..." with no order by, groups etc.


--
Scott Burns
Mirrabooka Systems

Tel +61 7 3857 7899
Fax +61 7 3857 1368




Reply With Quote
  #3  
Old   
Gorazd Hribar Rajteric
 
Posts: n/a

Default Re: How big is my result set? - 09-11-2003 , 04:32 AM



If you're using IDS 7.3x there is some very useful documentation available
at my site:
http://www.klimaexpert.com/gorazd/informix/index.html

Gorazd

"Scott Burns" <scott (AT) mirrabooka (DOT) com> wrote

Quote:
Gorazd Hribar Rajteric wrote:

You can use SQLCA structure - more specific sqlca.sqlerrd[0], but this is
only an estimate(!). Documentation says, that actual number of rows in a
result set is not guaranteed to be accurate unless you've scrolled
through
the whole result set. You can get more information on SQLCA record on:
http://www.dbcenter.cise.ufl.edu/tri...lc/11.fm3.html

Two more good sites are:
http://www.dbcenter.cise.ufl.edu/tri...ex/global.html
and
http://www.docs.rinet.ru:8080/InforSmes/index.htm

Gorazd



Thanks for the pointers. I'm actually using dead tree manuals from
version 4.0, so I missed that feild. My manual says that it is not used
at present...

Of course, it also has a handwritten note in it to the effect that the
structure is wrong, and I should look at the _old_ book

I'll have to experiment and see how accurate the estimate is.

--
Scott Burns
Mirrabooka Systems

Tel +61 7 3857 7899
Fax +61 7 3857 1368




Reply With Quote
  #4  
Old   
Mark D. Stock
 
Posts: n/a

Default Re: How big is my result set? - 09-11-2003 , 01:53 PM




Scott Burns wrote:

Quote:
Hi,
I've a google search showed me this question has been mentioned, but
never seems to be asked or anwered directly:

I am running SE, and have made a select cursor I traverse using "Next"
and "Prev" buttons in my C application. I want my buttons to becomes
insesnsitive when I hit either the start or the end of the set ( cant go
further, and want the user to know that ).

I have a function that figures out if I'm at the start or end, even
taking into account any records I've deleted from my set ( but which
still have a blank entry ). My application skips over the blank
entries. Unfortunately, I need to know what the theoretically last
entry in the set is, or, in other words, how big is the set I just selected?

At the moment I traverse the list just after selection but before
display, counting as I go. For a set of 6500 odd records this takes
well over a minute on my hardware. I could use a count(*) but it would
have to be a seperate call. I'm worried that if an entry is added or
deleted my application may either never think it is at the end, or will
miss a record. Is there a way to embed the count(*) into my select
statement I use for my cursor, returning the total count of all rows on
each row?
The last time I tested the performance of scrolling through the entire set
versus COUNT(*), the scrolling was faster. That could be because most of
the records were read in the first buffer, but then I wouldn't allow a user
to select 6500 odd records. Do they REALLY scroll through all 6500?

There are aesthetic tricks you can use to hide the time of the count.
Things like displaying the first record as soon as you get it, so that by
the time the user reads it and presses Next, the count is done, or the
delay is seen as a delay in the Next function and not the initial load. ;-)

Also, you don't need to know how many records are in the set to stop at the
end. You can just check the error code to see when you scroll off the end,
in either direction. If you have coded First and Last options, then that's
a different story.

Quote:
My select statements are always in the form "SELECT <key value> FROM
table> WHERE ..." with no order by, groups etc.
Good.

Cheers,
--
Mark.

+----------------------------------------------------------+-----------+
Quote:
Mark D. Stock mailto:mdstock (AT) MydasSolutions (DOT) com |//////// /|
Mydas Solutions Ltd http://MydasSolutions.com |///// / //|
+-----------------------------------+//// / ///|
|We value your comments, which have |/// / ////|
|been recorded and automatically |// / /////|
|emailed back to us for our records.|/ ////////|
+----------------------+-----------------------------------+-----------+

sending to informix-list


Reply With Quote
  #5  
Old   
preetinder dhaliwal
 
Posts: n/a

Default Re: How big is my result set? - 09-11-2003 , 04:09 PM




You can do a read ahead in your program, whenever user presses next ,
that is read not only the next, but next and next. This way you will
know when to disable the buttons. For start, it is easy, maintain a
count variable starting with zero and if count will become zero when
previous is pressed , disable previous button.

Just ur program needs to take care of this, this might decrease the
performance a bit, but since the cursor is already open, it should be
affordable. Also you can make up a bit in subsequent next button presses
as then you will already have the requested record in program.

Rgds
Preetinder

Scott Burns wrote:

Quote:
Hi,
I've a google search showed me this question has been mentioned, but
never seems to be asked or anwered directly:

I am running SE, and have made a select cursor I traverse using "Next"
and "Prev" buttons in my C application. I want my buttons to becomes
insesnsitive when I hit either the start or the end of the set ( cant go
further, and want the user to know that ).

I have a function that figures out if I'm at the start or end, even
taking into account any records I've deleted from my set ( but which
still have a blank entry ). My application skips over the blank
entries. Unfortunately, I need to know what the theoretically last
entry in the set is, or, in other words, how big is the set I just selected?

At the moment I traverse the list just after selection but before
display, counting as I go. For a set of 6500 odd records this takes
well over a minute on my hardware. I could use a count(*) but it would
have to be a seperate call. I'm worried that if an entry is added or
deleted my application may either never think it is at the end, or will
miss a record. Is there a way to embed the count(*) into my select
statement I use for my cursor, returning the total count of all rows on
each row?

My select statements are always in the form "SELECT <key value> FROM
table> WHERE ..." with no order by, groups etc.




sending to informix-list


Reply With Quote
  #6  
Old   
Robert A. Reissaus
 
Posts: n/a

Default Re: How big is my result set? - 09-12-2003 , 08:23 AM



Keep in mind that whenever you use a count(*) to determine how many
records comply to the selection criteria you performace degrades
tremendously because the count(*) needs to go thru the entire table to
do it's job, just as the 'select' would. And there is no need for it.

*Assuming* you are using a limited array to fill every time 'next
(page)' is hit you can simply do a ' fetch next' to determin whether
you are at the end of your 'fille array' selection. If so set a flag
(i.e. ' end_of_table' to true) and use that to disable your keys.
Don't forget to do a ' fetch previous' if you DID NOT reach the end of
the table.

Success
Robert A. Reissaus
RISDI
Ibm/Informix consultants
Amsterdam, the Netherlands
ra.reissaus (AT) risdi (DOT) com
www.risdi.com

Reply With Quote
  #7  
Old   
Scott Burns
 
Posts: n/a

Default Re: How big is my result set? - 09-14-2003 , 06:53 PM



Robert A. Reissaus wrote:

Quote:
Keep in mind that whenever you use a count(*) to determine how many
records comply to the selection criteria you performace degrades
tremendously because the count(*) needs to go thru the entire table to
do it's job, just as the 'select' would. And there is no need for it.

*Assuming* you are using a limited array to fill every time 'next
(page)' is hit you can simply do a ' fetch next' to determin whether
you are at the end of your 'fille array' selection. If so set a flag
(i.e. ' end_of_table' to true) and use that to disable your keys.
Don't forget to do a ' fetch previous' if you DID NOT reach the end of
the table.



Mostly. It's made a little bit more tricky because if one of the
records in my reult set is deleted, there is still a place holder for
it. I don't recall exactly what sits there as I worked around it
several months ago. My problem is that just because fetch next returns
a record doesn't mean that it's a real record or that it's valid for my
program to leave the next button sensitive. I worked around this by
storing a linked list of the indexes I delete and checking against this,
possibly moving on another record in the result set (which in turn may
have been deleted, and so on).

What we end up with is a series of checks, which while it won't be as
bad as running through all possible records and then back again, it
still has to be done every time the user moves forward. Admissibly, I
still have to check against my deleted list when I know the max size,
though. The program is quite intensive when changing records anyway.
All I have in the result set is the key of the table, and I then go
through and run a second SQL to get the current data and populate the
screen. This SQL is dynamically generated depending on what fields are
being displayed in the application.

I've redone my procedure to run through all records in the set, counting
as it goes, and it's down to 3 seconds for 6500 records, and I can
probably halve that if I go straight to the first record rather than
scanning backwards. This is still ( I think ) slower than a count(*)
but it's liable to be more accurate if people are adding or deleteing
regularly.

Whichever way I do it, though, I'm duplicating work that Informix did
when it went through and made the result set for me. While tears are a
while off, the time for Mr Keyboard to meet Mr Monitor is drawing near.


--
Scott Burns
Mirrabooka Systems

Tel +61 7 3857 7899
Fax +61 7 3857 1368




Reply With Quote
  #8  
Old   
Gorazd Hribar Rajteric
 
Posts: n/a

Default Re: How big is my result set? - 09-15-2003 , 03:22 AM



[clipped]
Quote:
Mostly. It's made a little bit more tricky because if one of the
records in my reult set is deleted, there is still a place holder for
it. I don't recall exactly what sits there as I worked around it
several months ago. My problem is that just because fetch next returns
a record doesn't mean that it's a real record or that it's valid for my
program to leave the next button sensitive.
[clipped]

What kind of isolation level are you using?

Gorazd




Reply With Quote
  #9  
Old   
Scott Burns
 
Posts: n/a

Default Re: How big is my result set? - 09-15-2003 , 05:42 PM



Gorazd Hribar Rajteric wrote:

Quote:
[clipped]


Mostly. It's made a little bit more tricky because if one of the
records in my reult set is deleted, there is still a place holder for
it. I don't recall exactly what sits there as I worked around it
several months ago. My problem is that just because fetch next returns
a record doesn't mean that it's a real record or that it's valid for my
program to leave the next button sensitive.


[clipped]

What kind of isolation level are you using?

Gorazd




To be honest, I have no idea. We never tweak those sorts of things
here. The database has always been up to the job with default setings.
Of course, even with our clients in full swing I doubt they do more
than 10 update/insert/delete operations each minute. In the middle of
the night, it might be as low as 1 per minute...

--
Scott Burns
Mirrabooka Systems

Tel +61 7 3857 7899
Fax +61 7 3857 1368



Reply With Quote
  #10  
Old   
Obnoxio The Clown
 
Posts: n/a

Default Re: How big is my result set? - 09-15-2003 , 06:44 PM



Does my result set look big in this?

--
"C'est pas parce qu'on n'a rien à dire qu'il faut fermer sa gueule"
- Coluche

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.