Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / June 2006

Tip: Looking for answers? Try searching our database.

Optimize UDF speed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tracy - 29 Jun 2006 10:14 GMT
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
mike - 29 Jun 2006 10:25 GMT
Have you compared the access-plans of the query with the inlined UDF
with the plain query  that does not use the UDF ?
Tracy - 30 Jun 2006 03:16 GMT
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 ?
Serge Rielau - 29 Jun 2006 20:22 GMT
> Dear all
>
[quoted text clipped - 8 lines]
> NO EXTERNAL ACTION
> DETERMINISTIC

show us the body of the udf :-)

Signature

Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ondemandbusiness/conf2006/

Tracy - 30 Jun 2006 04:10 GMT
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?
Serge Rielau - 30 Jun 2006 15:31 GMT
> 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
Signature

Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ondemandbusiness/conf2006/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.