473,411 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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 3350
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
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...
4
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...
0
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. ...
3
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 =...
1
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...
10
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...
2
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...
1
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...
4
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...
9
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.