473,386 Members | 1,710 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,386 software developers and data experts.

Optimize UDF speed

Dear all

I am trying to parameterize a SQL query by re-writing it as a UDF.
However, I find the execution time for my UDF unacceptably long. It
takes 60 times longer than running an equivalent SQL query with
hardcoded parameter values. (e.g. 6 min for UDF Versus 30s for SQL).

My specified options for the UDF are:
LANGUAGE SQL
READS SQL DATA
NO EXTERNAL ACTION
DETERMINISTIC

I am rather puzzled by such difference. Would anyone shed me some
lights on how to identify performance bottleneck of UDFs?

Thanks
Tracy

Jun 29 '06 #1
5 2130
Have you compared the access-plans of the query with the inlined UDF
with the plain query that does not use the UDF ?

Jun 29 '06 #2
Tracy wrote:
Dear all

I am trying to parameterize a SQL query by re-writing it as a UDF.
However, I find the execution time for my UDF unacceptably long. It
takes 60 times longer than running an equivalent SQL query with
hardcoded parameter values. (e.g. 6 min for UDF Versus 30s for SQL).

My specified options for the UDF are:
LANGUAGE SQL
READS SQL DATA
NO EXTERNAL ACTION
DETERMINISTIC

show us the body of the udf :-)
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Jun 29 '06 #3
As I am not familiar with DB2 explain facility, I haven't tried this
yet. Need some time to study how to compare access plans =P

Thanks Mike~

mike 寫道:
Have you compared the access-plans of the query with the inlined UDF
with the plain query that does not use the UDF ?


Jun 30 '06 #4
My query goes sth like this:

I have a table named "attendance", which records each shift and the
associated # of hours worked by every part-time staff each day.

The table's size is very large (over 1,000,000 rows) and keeps growing
every day.

Sample data for "attendance":

staff rdate shiftid hour
====================================
ABC 2006-05-01 1 2
ABC 2006-05-01 2 3
DEF 2006-05-01 1 3

My query is "Check how many hours worked by each staff per day during
'2006-05-01' AND '2006-05-02'.

Plain SQL
=================================

SELECT
staff,
rdate,
SUM(hour)
FROM
attendance
WHERE
rdate BETWEEN '2006-05-01' AND '2006-05-02'

GROUP BY
staff,
rdate
;
UDF Body
=========

CREATE FUNCTION query (csdate DATE,cedate DATE)
RETURNS TABLE
(
staff VARCHAR(20),
rdate DATE,
ttlhour INTEGER
)

SPECIFIC query
LANGUAGE SQL
READS SQL DATA
NO EXTERNAL ACTION
DETERMINISTIC
RETURN

SELECT
staff,
rdate,
SUM(hour)
FROM
attendance
WHERE
rdate BETWEEN csdate AND cedate

GROUP BY
staff,
rdate
;

UDF sample invocation
=====================
select * from table(query(DATE('2006-05-01'),DATE('2006-05-02'))) as T1

Have I coded something wrong that causes such a long execution time
with UDF?

Jun 30 '06 #5
Tracy wrote:
My query goes sth like this:

I think there's your problem. Somewhere in the "something".
The query you posted is trivial DB2 for LUW will completely dissolve it.
When you check db2exfmt you will not find it anymore.
But I suspect your real function isn't like that.
If you don't want to post the real thing, fee free to send it to me in
an email.

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

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Jun 30 '06 #6

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

Similar topics

4
by: mjuricek | last post by:
I'm having some problems to optimize my stored procedure (select statement with joins) What I'm trying to do is calculate total work. My situation: I have 3 tables I'm using -Input (char...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
5
by: Markus Dehmann | last post by:
Profiling has shown that during runtime of my program, 100 million objects of class X are constructed and destructed. What is the best way to optimize in such a case, both for memory and speed...
11
by: Michael B. | last post by:
I'm still learning C so I've written a simple app which lets you make a contact list (stored as a linked list of structs), write it to a file, and read it back. It works fine, but I notice in my...
3
by: Gaffar | last post by:
Hello, I am Handling a project in ( ASP.NET with C#.NET) in which a module is slow and inefficient. How to optimize the code. Please give me some suggestions regarding this. If you know any...
3
by: Reddy | last post by:
The sql query for my datagrid returns 100, 000 records. But the datagrid should display 20 records per page. I am using datagrid paging, but it is taking too much time for the page to load. Is...
3
by: zhangyue.zl | last post by:
For a source file ,which optimize option can make gcc generate a smaller object file,O2 or O3? Thanks!
13
by: Frank Swarbrick | last post by:
IBM has a product for the VSE operating system called the VSAM Redirector. It allows you to use VSAM to access RDBMS tables/views as if they were actual VSAM files. We're doing a comparison right...
15
by: kenneth | last post by:
I was trying to use multiple thread to optimize my following code, but met some problems, anyone can help me? k are initialized. int computePot() { int i, j; for( i=0; i<500; i++ ) { for(...
2
by: pavanip | last post by:
Hi, I have an application like Optimize System Performance by using Memory speed, cpu speed and Disk speed. How to optimize memory speed,disk optimization and CPU optimization. Please provide me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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,...

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.