473,581 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cursor - how does it behave

Hi all,
I have a peculiar problem. I have a query which returns multiple rows.
I want to perform some operations on the output row by row. For that, i
declared a cursor and fetching the rows. Now the problem is, that if
run the query on DB2 command, I am getting the output in 11 minutes and
as soon as i put the query in SP in cursor and i do a simple OPEN
<cursorname>, it takes more than 2 hrs.

I am running DB2 v8.2 on AIX.

Culd somebody tell me what happens when a cursor is opened??

Sep 3 '06 #1
8 3361
spider007 wrote:
Hi all,
I have a peculiar problem. I have a query which returns multiple rows.
I want to perform some operations on the output row by row. For that, i
declared a cursor and fetching the rows. Now the problem is, that if
run the query on DB2 command, I am getting the output in 11 minutes and
as soon as i put the query in SP in cursor and i do a simple OPEN
<cursorname>, it takes more than 2 hrs.

I am running DB2 v8.2 on AIX.

Culd somebody tell me what happens when a cursor is opened??
The biggest influencer for cursor performance is it's BLOCKING behavior.
That is whether DB2 will ship the result set row-by-row or in blocks to
be dispensed by the client.
Blocking can be influenced through a variety of bind options.
Try BLOCKING ALL and STATIC READ ONLY.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 3 '06 #2
Actually, my entire business logic has been built in SP. I call the SP
from SQC and then SP takes over and does all the processing.
What I think might be the cause of the problem is that the SP is by
default FENCED. So the memory (or bufferpool) taken by the cursor is
FENCED memory which is less than the instance memory. Now I dont know
how much memory has been allocated to FENCED user. Is there any way to
find out that?

Also, where can I find the documentation for the BLOCKING in cursor.

Regards
Saurabh Jain

Serge Rielau wrote:
spider007 wrote:
Hi all,
I have a peculiar problem. I have a query which returns multiple rows.
I want to perform some operations on the output row by row. For that, i
declared a cursor and fetching the rows. Now the problem is, that if
run the query on DB2 command, I am getting the output in 11 minutes and
as soon as i put the query in SP in cursor and i do a simple OPEN
<cursorname>, it takes more than 2 hrs.

I am running DB2 v8.2 on AIX.

Culd somebody tell me what happens when a cursor is opened??
The biggest influencer for cursor performance is it's BLOCKING behavior.
That is whether DB2 will ship the result set row-by-row or in blocks to
be dispensed by the client.
Blocking can be influenced through a variety of bind options.
Try BLOCKING ALL and STATIC READ ONLY.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 4 '06 #3
spider007 wrote:
Actually, my entire business logic has been built in SP. I call the SP
from SQC and then SP takes over and does all the processing.
What I think might be the cause of the problem is that the SP is by
default FENCED. So the memory (or bufferpool) taken by the cursor is
FENCED memory which is less than the instance memory. Now I dont know
how much memory has been allocated to FENCED user. Is there any way to
find out that?

Also, where can I find the documentation for the BLOCKING in cursor.
Have you searched for the options I posted? That should lead to all the
docs?
Anyway I am suspicious that FENCED is the cause for your problem.
Can you give more background? You note "multiple rows". Multiple to me
means < 10. Is this a complex cursor? How many rows are read vs fetched?
(see e.g. statement monitor)?

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 4 '06 #4
I have searched for the option "BLOCKING" on google but couldnt find
something appropriate. I would be thankful to you if you could send me
some docs or post a link where I could find more info about the option
which you specified.

"Multiple rows" can vary from thousand to millions of rows on which I
have to perform some business operations.
It is not a complex cursor. I mean the query for the cursor comes out
in approx 10 minutes but the cursor takes around 3 hrs.
Rows read are almost comparable to rows fetched. Also i have run
db2expln on the query and it shows the query is taking all the indexes
which can also be seen by the fact that query run outside SP is taking
11 minutes.

Regards
Saurabh

Serge Rielau wrote:
spider007 wrote:
Actually, my entire business logic has been built in SP. I call the SP
from SQC and then SP takes over and does all the processing.
What I think might be the cause of the problem is that the SP is by
default FENCED. So the memory (or bufferpool) taken by the cursor is
FENCED memory which is less than the instance memory. Now I dont know
how much memory has been allocated to FENCED user. Is there any way to
find out that?

Also, where can I find the documentation for the BLOCKING in cursor.
Have you searched for the options I posted? That should lead to all the
docs?
Anyway I am suspicious that FENCED is the cause for your problem.
Can you give more background? You note "multiple rows". Multiple to me
means < 10. Is this a complex cursor? How many rows are read vs fetched?
(see e.g. statement monitor)?

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 5 '06 #5
With "BLOCKING" if you mean "Isolation levels" then I have defined the
select query for the cursor in SP as RS

spider007 wrote:
I have searched for the option "BLOCKING" on google but couldnt find
something appropriate. I would be thankful to you if you could send me
some docs or post a link where I could find more info about the option
which you specified.

"Multiple rows" can vary from thousand to millions of rows on which I
have to perform some business operations.
It is not a complex cursor. I mean the query for the cursor comes out
in approx 10 minutes but the cursor takes around 3 hrs.
Rows read are almost comparable to rows fetched. Also i have run
db2expln on the query and it shows the query is taking all the indexes
which can also be seen by the fact that query run outside SP is taking
11 minutes.

Regards
Saurabh

Serge Rielau wrote:
spider007 wrote:
Actually, my entire business logic has been built in SP. I call the SP
from SQC and then SP takes over and does all the processing.
What I think might be the cause of the problem is that the SP is by
default FENCED. So the memory (or bufferpool) taken by the cursor is
FENCED memory which is less than the instance memory. Now I dont know
how much memory has been allocated to FENCED user. Is there any way to
find out that?
>
Also, where can I find the documentation for the BLOCKING in cursor.
Have you searched for the options I posted? That should lead to all the
docs?
Anyway I am suspicious that FENCED is the cause for your problem.
Can you give more background? You note "multiple rows". Multiple to me
means < 10. Is this a complex cursor? How many rows are read vs fetched?
(see e.g. statement monitor)?

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 5 '06 #6
spider007 wrote:
With "BLOCKING" if you mean "Isolation levels" then I have defined the
select query for the cursor in SP as RS
http://publib.boulder.ibm.com/infoce...6f%63%6b%22%20

Between a thousand an millions is a difference of three magnitudes.
The question si whether a plan that's good for 1000 rows is also good
for 1000000 rows.
Note that unless DB2 injects SORT or TEMP operations the cursor is NOT
materialized on OPEN. Instead it is executed as you fetch.
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 5 '06 #7
spider007 wrote:
With "BLOCKING" if you mean "Isolation levels" then I have defined the
select query for the cursor in SP as RS
Unfortunately, there are two different things where the term "blocking" is
used. One refers to blocking an application/session due to locks; the
other means that rows of a cursor are collected in a single block and send
together over the wire to the client.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Sep 5 '06 #8
If you're able to, perhaps the easiest way to test the blocking theory
is to add 'FOR READ ONLY' to the end of your cursor's SQL, thus making
the cursor unambiguous and therefore blocking.

On another note, with all due respect, are you certain you need such a
(relatively) restrictive isolation level (RS)? I appreciate the phantom
read issue, but am wondering if perhaps in your situation you can
mitigate, obviate, or otherwise tolerate it (feel free to think of some
more apropos '-ate' words :-). Assuming your million-row-returning
query is running in a batch window, are there concurrent users that you
need to be concerned with? If you're running the query during the
normal (on-line) window, then I guess that's another story.

Regards,

--Jeff

spider007 wrote:
With "BLOCKING" if you mean "Isolation levels" then I have defined the
select query for the cursor in SP as RS

spider007 wrote:
I have searched for the option "BLOCKING" on google but couldnt find
something appropriate. I would be thankful to you if you could send me
some docs or post a link where I could find more info about the option
which you specified.

"Multiple rows" can vary from thousand to millions of rows on which I
have to perform some business operations.
It is not a complex cursor. I mean the query for the cursor comes out
in approx 10 minutes but the cursor takes around 3 hrs.
Rows read are almost comparable to rows fetched. Also i have run
db2expln on the query and it shows the query is taking all the indexes
which can also be seen by the fact that query run outside SP is taking
11 minutes.

Regards
Saurabh

Serge Rielau wrote:
spider007 wrote:
Actually, my entire business logic has been built in SP. I call the SP
from SQC and then SP takes over and does all the processing.
What I think might be the cause of the problem is that the SP is by
default FENCED. So the memory (or bufferpool) taken by the cursor is
FENCED memory which is less than the instance memory. Now I dont know
how much memory has been allocated to FENCED user. Is there any way to
find out that?

Also, where can I find the documentation for the BLOCKING in cursor.
Have you searched for the options I posted? That should lead to all the
docs?
Anyway I am suspicious that FENCED is the cause for your problem.
Can you give more background? You note "multiple rows". Multiple to me
means < 10. Is this a complex cursor? How many rows are read vs fetched?
(see e.g. statement monitor)?
>
Cheers
Serge
>
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
>
IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 5 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11254
by: sci | last post by:
Could someone help me by answering the questions below? What's a cursor? What's difference between Query and View? Is a RecordSet just part of a table? Can it be part of a query of view? If the content in a table changed, is it necessary for a old recordset to renew itself by do "Requery()"? Thanks for your help!
4
4472
by: P Adhia | last post by:
Hello, If the explain shows that DB2 needs to sort the result of a cursor, does that always happen? i.e. if the resultset of the cursor is empty, does the sort have any overhead? It appears that, majority of the time is spent in allocation and deallocation of the temporary file to hold the data for the sort. Do these activities still take...
0
968
by: Max | last post by:
I'm having some problems using SqlDataReader in the Microsoft.ApplicationBlocks.Data.SqlHelper class. In some cases it seems that the cursor does not move, and I'm not sure what is causing this. reader = SqlHelper.ExecuteReader(strConn, _ CommandType.StoredProcedure, "spGetSomeRecords", _ New SqlParameter("@id", id)) Do While...
3
3207
by: Mobile Boy 36 | last post by:
Maybe this is a very ridicules question. I 'm developing a vb.net compact framework application and I try to change the cursor to an hourglass with the following code: me.cursor = cursors.WaitCursor
1
1924
by: Vinit | last post by:
Hi I have a form in which there is a treeview alongside a listview. Now I have certain conditions when the Listview control is disabled. When this happens I would want the Cursor to be of type "NO" only when the mouse is over the ListView. It should be default over the other controls on the form. I have tried many things but nothing seems...
10
13172
by: scoonie999 | last post by:
I'm having a problem that I can't seem to find any solution for online. I'm using a cursor in a cobol program to fetch some data. I know for a fact that the select should return 2 rows. The fetch works as I would expect it to on the 2 rows, but then when I do my next fetch, the program ends abnormally. My next step is to check for...
2
3864
by: BilalGhazi | last post by:
Hi All, I have this strange problem. I am user of two different database (both are same version 9i). I created a procedure and within this procedure i used a cursor to select the values, this is working very fine. When i copy this procedure in other database and try to run the procedure, the procedure runs successful, but the cursor does not...
1
9172
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
We have some dumb and lazy people here, so I need help. To fix the dumb part: We have placed MaskedTextBoxes on the forms so they will stop entering the information incorrectly. Now the lazy part: When our people click on a blank MaskedTextBox field, the cursor does not automatically go to the first "non-filled" mask value. For Example:...
4
7070
antonopn
by: antonopn | last post by:
Hello there, this is my problem. I have a table in sql server. lets say it table_read. I use a cursor like this. DECLARE CUR CURSOR FOR SELECT * FROM TABLE_READ OPEN CUR WHILE @@FETCH_STATUS=0 BEGIN FETCH NEXT FROM CUR INTO
9
30978
by: Frank Swarbrick | last post by:
New to SQL here... We have a CURSOR declared thusly: EXEC SQL DECLARE ALL-ADJSTMTS-CSR CURSOR FOR SELECT ACCT.ACCOUNT_ID , ACCT.APPL_ID , ACCT.BRANCH_NUMBER , ACCT.CATEGORY_CODE
0
7862
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8169
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6551
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5361
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3803
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1400
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1132
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.