473,480 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Slow running sql stored procedure

5 New Member
I have a sql stored procedure that wraps a query that joins 2 tables and uses several UDFs that call other stored procedures. The performance of the procedure is slow,
it takes about 5 min to complete.
To troubleshoot the problem, I copied the query into iNavigator 6 (db2 iSeries v5R4). I substituted the parameters with static values. This query returns results in 5 - 10 seconds. I now replaced the parameters in the sp with static values; the procedure still takes about 5 minutes to return results.
Why does the sp run so slow? What should I modify to improve performance ot this sql sp
Aug 30 '10 #1
9 7340
Oralloy
988 Recognized Expert Contributor
Is the only thing in the stored procedure your query?

It would help a lot, if you'd post the code.

Cheers!
Aug 30 '10 #2
tomaszp
5 New Member
-- Generate SQL
-- Version: V5R4M0 060210
-- Generated on: 08/30/10 11:21:30
-- Relational Database: CAPM01
-- Standards Option: DB2 UDB iSeries


CREATE PROCEDURE SHIPPED_VS_ALLOCATE_TEST3 (
IN BEGIN_DATE DATE ,
IN END_DATE DATE ,
IN REPORTTYPE CHAR(1) )
DYNAMIC RESULT SETS 1
LANGUAGE SQL
SPECIFIC SHIPPED_VS_ALLOCATE_TEST3
NOT DETERMINISTIC
MODIFIES SQL DATA
CALLED ON NULL INPUT
SET OPTION ALWBLK = *ALLREAD ,
ALWCPYDTA = *OPTIMIZE ,
COMMIT = *NONE ,
DECRESULT = (31, 31, 00) ,
DFTRDBCOL = *NONE ,
DYNDFTCOL = *NO ,
DYNUSRPRF = *USER ,
SRTSEQ = *HEX
BEGIN


DECLARE BDATE DECIMAL ( 8 , 0 ) ;
DECLARE EDATE DECIMAL ( 8 , 0 ) ;
DECLARE SQL_SMT1 CHAR ( 2000 ) ;
DECLARE SQL_SMT2 CHAR ( 2000 ) ;
DECLARE SQL_SMT CHAR ( 5000 ) ;

DECLARE C1 CURSOR WITH RETURN FOR
SELECT PHPCTL "Pickticket #" , SUBSTR ( PDCREX , 1 , 35 ) "SAP Order #" , PDPKLN "Line #" , PDSTYL || PDSSFX || PDCOLR "SKU"
,
UDF_NUMBEROFHOLIDAYDAYS ( PHPDCR ) "Holidays" ,
UDF_DECIMALTODATE ( PHPDCR ) "CREATED DATE" ,
UDF_DECIMALTOTIME ( PHPTCR ) "CREATED TIME" ,
UDF_DECIMALTODATE ( PHSHDT ) "SHIP DATE" ,
UDF_DECIMALTOTIME ( PHPTLM ) "SHIP TIME",
UDF_DECIMALTOTIME ( 183000 ) "CutOff Time" ,
PHSOCN "Country" ,
PDPIQT , PDMIS5 || PDMIS6 "Seibel#" , PHORDS "Condition" , PHSVIA "Ship Via" ,
PHPTCR , PDPAKU , PHPTLM ,
PHDIV , PHPSTF , PHPDCR , PHSHDT ,
UDF_DECIMALTODATE ( UDF_SHIPDATEDECIMAL ( PHPDCR , PHPTCR , PHSOCN , CHAR ( 'E' ) ) ) "Required Ship Date" ,
CASE
WHEN PHSHDT > UDF_SHIPDATEDECIMAL ( PHPDCR , PHPTCR , PHSOCN , CHAR ( 'E' ) ) THEN 'LATE'
WHEN PHSHDT = 0 AND CURRENT_DATE <= UDF_DECIMALTODATE ( UDF_SHIPDATEDECIMAL ( PHPDCR , PHPTCR , PHSOCN , CHAR ( 'E' ) ) ) THEN ''
WHEN PHSHDT = 0 AND CURRENT_DATE > UDF_DECIMALTODATE ( UDF_SHIPDATEDECIMAL ( PHPDCR , PHPTCR , PHSOCN , CHAR ( 'E' ) ) ) THEN 'LATE'
ELSE '' END "LATE STATUS"


FROM PhOrder00 INNER JOIN PdOrder00 ON ( ( PHCO = PDCO ) AND ( PHDIV = PDDIV ) ) AND ( PHPCTL = PDPCTL )
WHERE PHCO = 'ZZ' AND PHDIV = '999' AND PHPSTF < '99' AND ( PHPDCR >= 20100816 AND PHPDCR <= 20100817 ) AND PHORDS NOT IN ( '66' , '77' , '88' ) AND PDCO = 'ZZ' AND PDDIV = '999' ;

OPEN C1;

Return;


END ;
Aug 31 '10 #3
Oralloy
988 Recognized Expert Contributor
Ok, I don't see anything obvious, but a few small things. I am ignorant of a number of things with db2, so if I make a mistake or state something stupid, let me know, please.

One, the header states "MODIFIES SQL DATA". That may have some affect.

There are three declares for SQL_SMT variables. Unless these are necessary, they can be removed.

Have you tried temporarily removing "LATE STATUS" and/or "Required Ship Date" to see if they affect the query processing?

Did you double check that the join condition is on indexed columns?
Aug 31 '10 #4
tomaszp
5 New Member
I recompiled all of my user defined functions and stored procedures with the following settings: READ SQL DATA, DETERMINISTIC, and NOT FENCED. DETERMINISTIC directs DB2 to store the results of a UDF, it will return this same result without re-executing the UDF whenever the function is executed with same parameter as previously used during same process. NOT FENCED, used in the iSeries environment, directs DB2 to execute all called functions and procedures in same thread. Since I’m calling several UDFs and stored procedures, these setting have made a big difference. Processing time has dropped to 30 seconds. This is slower than running this query in iNavigator, but it is acceptable. I don’t have the time to test each one of these settings individually to determine which setting contributes the most to the much improved processing time, but I will be playing with this more over time. Thanks for your response.
Sep 1 '10 #5
Oralloy
988 Recognized Expert Contributor
@tomasazp,

Thanks for letting us know how things turned out. I learned something.

Cheers!
Sep 1 '10 #6
tomaszp
5 New Member
I was too quick to celebrate. After recompiling all of my UDFs and SPs with the new settings I called the main store procedure, but forgot to uncomment all of the lines with references to the UDFs before recompiling. I’m back to scratching my head. The solution I implemented had no effect. To summarize, my stored procedure runs very slow; when I take the sql statement out of the sp and run it directly in iNavigator the result set is generated in less than 10 seconds. When I take out all references to UDFs result set is returned as expected.
Any ideas?
Sep 2 '10 #7
Oralloy
988 Recognized Expert Contributor
@tomasazp,

Well, drat.

Unfortunately I am out of ideas. Hopefully I can pass the batton to one of the other experts here who is more qualified with DB2.

Is it possible to compute a preliminary result set, then walk that cursor and apply the UDFs?

Or maybe use a temporary table to hold the basic result and then return the UDF processed version of that table?
Sep 2 '10 #8
tomaszp
5 New Member
Those are good ideas I’ll examine those approaches. I’ve been focused on identifying the settings that allow the sql statement to execute in a few seconds while the same statement require between 4 – 10 minutes to return results when wrapped in a stored procedure.
Thanks for your suggestions.
Sep 2 '10 #9
Oralloy
988 Recognized Expert Contributor
@tomaszp,

When you get it figured out, please let me know.

Cheers!
Sep 2 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4762
by: Gary Homewood | last post by:
I have an ASP page calling a stored procedure. I have set the connection and command timeouts and I have error checking so I can trap a timeout from the stored proc (as detailed here)...
0
1204
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))...
7
2533
by: Samantha Penhale | last post by:
Hello, Thanks in advance for any insight you can offer. I've a ASP.NET project written in C#, two web forms, a lovely gob of using statements. I originally had one webform with all my fields and...
2
3026
by: Paul Hale | last post by:
Hi all, being new to c# I'm trying to find the best way of passing multiple records to insert into a sql database via a stored procedure. I'm using visual studio 2005 RC SQL server 2005 and C# of...
0
1089
by: Indira | last post by:
I am facing a problem. I have a long running Stored procedure. As per what I have read, if OleDbCommand.CommandTimeout is not set, as is in my case, the query should be timed out in 30 seconds...
3
2068
by: Eddie Suey | last post by:
I've created a console app that runs several SPROCs. While running the app if I access a CD or check my email, I get a timeout error. I'm not sure why. Is there a way to set a wait variable or...
5
5068
by: Nesa | last post by:
I have a stored procedure that wraps a moderately complex query over 5, 6 related tables. The performance of the procedure is unacceptably slow as it takes on average 5-10 min to complete. To...
7
3238
by: Jerry | last post by:
I'm trying to execute a stored procedure in a loop while paging through database table records but the stored procedure isn't running. I get the folowing error: The component 'adodb.connection'...
0
1617
by: eRTIS SQL | last post by:
hi, I want to use a stored procedure inside a stored procedure simulteanously changing the database. this is my base store procedure alter PROCEDURE create_file @dbname sysname AS declare...
1
7847
by: eRTIS SQL | last post by:
hi, I want to use a stored procedure inside a stored procedure simulteanously changing the database. this is my base store procedure alter PROCEDURE create_file @dbname sysname AS declare...
0
7048
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
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6743
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...
0
6966
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
5344
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,...
1
4787
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
4488
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
1303
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 ...
0
185
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...

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.