473,386 Members | 1,864 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.

UDF table advice needed

Hello, I am relatively new to DB2 and i would appreciate if anybody
can give me advice on UDF table.

My question is :
1) Is performance an issue when using UDF table?

2) I read from previous post that SQL UDF work great when you can
reduce them to only RETURN. But if I have a function as followed will
i have performance issues? :

CREATE FUNCTION FUNC_TO_TBL(VAL1 VARCHAR(128), VAL2 BIGINT, VAL3
CHAR(23))
RETURNS TABLE( TEST1 VARCHAR(128), TEST1 VARCHAR(128))
NO EXTERNAL ACTION
F1: BEGIN
DECLARE VARCHAR(128) FIELD1;
DECLARE VARCHAR(128) FIELD1;

// sql query + business logic to set value to Field1
SET FIELD1 = ....
// sql query + business logic to set value to Field2
SET FIELD2 = ....

RETURN VALUES(FIELD1 , FIELD2 );
END

3) How do I optimize the UDF table?

Any advice would be much appreciated!

Feb 5 '07 #1
2 1288
Regarding the performance/one return only question: If you have only a
return in your UDF, the optimizer will merge the SQL into your
existing SQL code (just like it does with views) and perform it's
rewriting on it. So if you have only one return, there is no
performance impact in comparison to views or direct SQL.

I don't know how large the performance impact is, if you procedural
statements in your UDF, IMO it would depend on the queries you use,
and if and how the optimizer could rewrite and optimize them.

You can rewrite your function to contain only one return as follows:
--
CREATE FUNCTION FUNC_TO_TBL(VAL1 VARCHAR(128), VAL2 BIGINT, VAL3
CHAR(23))
RETURNS TABLE( TEST1 VARCHAR(128), TEST1 VARCHAR(128))
NO EXTERNAL ACTION

RETURN
VALUES ((subquery business logic for field1) , (subquery business
logic for field2))
--

Regards,
Janick

Feb 5 '07 #2
eviewcs wrote:
Hello, I am relatively new to DB2 and i would appreciate if anybody
can give me advice on UDF table.

My question is :
1) Is performance an issue when using UDF table?
It depends...
2) I read from previous post that SQL UDF work great when you can
reduce them to only RETURN.
The DB2 optimizer is specifically tailored to optimize set-oriented SQL
statements. As soon as you introduce procedural logic, it just becomes
harder to rearrange operations because the optimizer may not know how to
break-down the procedural steps. Thus, procedural logic may slow down
things. (I'm using a lot of "may"s and "if"s because the real answer
depends you the specific situation/function/query.)

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Feb 5 '07 #3

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

Similar topics

1
by: Steven Burn | last post by:
I know I could probably write something along the lines of the below to do this but, am hoping there's an easier way. Basically what I am wanting to do is, select an entry in 1 table, then move...
5
by: Jean Pion | last post by:
Dear readers, Can anyone explain how to set column width of a table in ccs. I use the following style in an external stylesheet: table.tbl { table-layout:fixed; border-top: 5px solid #333;...
16
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables...
3
by: ChadDiesel | last post by:
Hello everyone. I need some advice on table structure for a new project I've been given. One of our customers sends us an Excel spreadsheet each week containing their order. Currently, someone...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
12
by: mantrid | last post by:
Hello Can anyone point me in the right direction for the way to read a text file a line at a time and separate the fields on that line and use them as data in an INSERT to add a record to a mysql...
1
by: christodde | last post by:
Hi group, I am going through some exercises regarding DB2 Administration and I found the below: How many extents are allocated when the following Employee table is created in the DMS tablespace...
7
by: stevewy | last post by:
I'm looking to manipulate/check the state of various checkboxes and radios in a form. Because I don't want to access all of the checkboxes in the form, only a specific section, I am trying to...
2
by: servantofone | last post by:
I'm running Access 2003 on Windows XP. This is more of a developmental/implementation type of question. I have a form which requires answers to 35 different questions. All questions are answered...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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,...
0
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...

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.