473,503 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

First iteration of stored procedure is slow.


Running DB2 8.2 on aix.

Similar problem to this thread.

http://groups.google.com/group/comp....9ffd1e725f0380

May have something to do with the sql package cache. The snapshots
show it's not a buffer pool issue.

The SP uses it's arguments instead of parameter markers in the sql.

eg.g i_last_name

SET sql_where = sql_where CONCAT ' PNAM.LAST_NAME LIKE
UPPER(REPLACE( ' ;
SET sql_where = sql_where CONCAT '''' CONCAT i_last_name CONCAT ''''
CONCAT ', '' '', '''')) AND ' ;

Stripping out the SQL from the SP and testing the statement from the
command line................

PNAM.LAST_NAME LIKE UPPER(REPLACE( 'Murphy', ' ', ''))
The first time the statement runs with "Murphy" it takes 20 seconds.
Subsequent executions take 24 milleseconds. If I change Murphy to
"Finnegan" the sql takes 20 seconds. Subsequent executions take 24
milleseconds. And so on. So I am wondering if DB2 thinks the SQL
statement is brand new when the argument changes i.e. "Murphy" changes
to "Finnegan" and it recompiles the SQL statemennt.

Any ideas?
Aug 12 '08 #1
2 2820
"Patrick Finnegan" <fi**************@gmail.comwrote in message
news:90**********************************@m44g2000 hsc.googlegroups.com...
>
Running DB2 8.2 on aix.

Similar problem to this thread.

http://groups.google.com/group/comp....9ffd1e725f0380

May have something to do with the sql package cache. The snapshots
show it's not a buffer pool issue.

The SP uses it's arguments instead of parameter markers in the sql.

eg.g i_last_name

SET sql_where = sql_where CONCAT ' PNAM.LAST_NAME LIKE
UPPER(REPLACE( ' ;
SET sql_where = sql_where CONCAT '''' CONCAT i_last_name CONCAT ''''
CONCAT ', '' '', '''')) AND ' ;

Stripping out the SQL from the SP and testing the statement from the
command line................

PNAM.LAST_NAME LIKE UPPER(REPLACE( 'Murphy', ' ', ''))
The first time the statement runs with "Murphy" it takes 20 seconds.
Subsequent executions take 24 milleseconds. If I change Murphy to
"Finnegan" the sql takes 20 seconds. Subsequent executions take 24
milleseconds. And so on. So I am wondering if DB2 thinks the SQL
statement is brand new when the argument changes i.e. "Murphy" changes
to "Finnegan" and it recompiles the SQL statemennt.

Any ideas?
Your problem may be the UPPER function. DB2 will not use an index on that
column with that function (and most other functions). Try creating a
separate column in the table which is automatically generated as the UPPER
value of the LAST_NAME and search on that column (without the UPPER).
Aug 12 '08 #2
Mark A wrote:
"Patrick Finnegan" <fi**************@gmail.comwrote in message
news:90**********************************@m44g2000 hsc.googlegroups.com...
>Running DB2 8.2 on aix.

Similar problem to this thread.

http://groups.google.com/group/comp....9ffd1e725f0380

May have something to do with the sql package cache. The snapshots
show it's not a buffer pool issue.

The SP uses it's arguments instead of parameter markers in the sql.

eg.g i_last_name

SET sql_where = sql_where CONCAT ' PNAM.LAST_NAME LIKE
UPPER(REPLACE( ' ;
SET sql_where = sql_where CONCAT '''' CONCAT i_last_name CONCAT ''''
CONCAT ', '' '', '''')) AND ' ;

Stripping out the SQL from the SP and testing the statement from the
command line................

PNAM.LAST_NAME LIKE UPPER(REPLACE( 'Murphy', ' ', ''))
The first time the statement runs with "Murphy" it takes 20 seconds.
Subsequent executions take 24 milleseconds. If I change Murphy to
"Finnegan" the sql takes 20 seconds. Subsequent executions take 24
milleseconds. And so on. So I am wondering if DB2 thinks the SQL
statement is brand new when the argument changes i.e. "Murphy" changes
to "Finnegan" and it recompiles the SQL statemennt.

Any ideas?

Your problem may be the UPPER function. DB2 will not use an index on that
column with that function (and most other functions). Try creating a
separate column in the table which is automatically generated as the UPPER
value of the LAST_NAME and search on that column (without the UPPER).
Actually that can't be it because the expression.
Now DB2 can't use a start stop key here because it has to compute the
pattern. But why not use = instead of LIKE?

Anyway..this would explain the big time difference only if the table
were stored on a tape-recorder given the orders of magnitude involved... ;-)

Every new literal indeed means a brand new statement to DB2. So yes a
recompile happnes.
But why 20 seconds? What's the rest of the SQL statement like? Any SQL
functions, triggers, RI constraints, nested views?

When all is said and done you should use a CAST(? AS VARCHAR(...))
instead of plugging in Murphy directly. Then use the USING clause to
bind the value in.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Aug 12 '08 #3

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

Similar topics

3
2957
by: PipHans | last post by:
Hi, Plz, I need some info (SQL2000) :) A stored procedure is like this: "Select table1.id, table1.txt, (select table2.nr from table2 where table2.fk_table1=table1.id) as nr where...
11
2606
by: Bă§TăRĐ | last post by:
I have been working on this particular project for a little over 2 weeks now. This product contains between 700-900 stored procedures to handle just about all you can imagine within the product. I...
1
1273
by: divyeshkhatri | last post by:
Hi I have written following stored procedure but it take way too long to complete. I will be processing thousands of records and it is slow. I am importing data from a source table and adding...
4
4947
by: Robin Tucker | last post by:
Hi, I'm trying to determine with my program whether or not a given database supports a given feature set. To do this I'm querying for certain stored procedures in the sysobjects table and if...
0
1207
by: Anthony Robinison | last post by:
I'm seeing some really messed up behavior from a stored procedure. Here is the DDL: CREATE PROCEDURE AIM.GetUserIDRetrievals (IN strUserID VARCHAR(64), IN decAIMConnectionID DECIMAL(13,0))...
5
1472
by: Guoqi Zheng | last post by:
Dear sir, I am about to finish a new asp.net application, I used a lot of ms sql stored procedure. Those stored procudure I think is the most important part of the application. Now I am about...
75
5538
by: Sathyaish | last post by:
Can every problem that has an iterative solution also be expressed in terms of a recursive solution? I tried one example, and am in the process of trying out more examples, increasing their...
5
4183
by: Lennart | last post by:
Here is a problem I would like some opinions on. I have a stored procedure (I suspect that the problem exists for other procedures as well, but I haven't verified it). First time it runs (each day)...
7
8183
by: E11esar | last post by:
Hi there. I have written a C# web service that calls an Oracle stored procedure. The SP is a simple select-max query and the table it is getting the value from has about 2.8 million rows in it. ...
0
7205
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
7093
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
7287
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,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5023
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
4689
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...
0
3180
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...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.