473,671 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(VAL 1 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 1298
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(VAL 1 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
1252
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 it to another. However, at the same time, in the second table, find all the entries marked "Yes" in the "New" field, and change the oldest one to "No". What I was thinking, was something along the lines of; '// 1st table
5
169723
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; border-collapse: collapse; background: #fff; width: 95%} table.tbl td { border-bottom: 1px dashed #33ccff; padding: 2px 5px; text-overflow:ellipsis; overflow:hidden; white-space:nowrap; }
16
2447
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 (se below) then I run a query giving me a running total, which give me the first stock in the batch purchased by an individual, then I use this number and add the number of shares in order to find the number of the individuals' last share. So...
3
3165
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 formats the spreadsheet, prints it out, and manually picks out the products we need to ship. I want to import this into an Access table. Basically, the sheet with some data examples looks something like this: ...
10
5715
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 form the control is on? Basically I have a number of controls in a form that are required, and to check it I am setting the Validation Rule to "<>"IsNull" so that when the user tries to tab through/click out of a required area without entering...
12
4414
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 table. Then read the second line in text file and repeat. Thanks for your time Ian
1
4116
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 TBS03? create table employee ( ID smallint not null, name varchar(9), DEPT smallint check (dept between 10 and 100),
7
3388
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 narrow down the list of elements to check. I thought I could place those elements within a named DIV or a table, and then reference that DIV or table by its ID. But it's not working. Say for instance I wanted Javascript to issue an alert (just...
2
1362
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 by checkbox and two text fields. This makes for a total of 105 fields (35*3=105) just for question answering. Since all questions require the same Yes/No answer and two text fields, is there a way I can cut down the size of my table? Should I...
0
8476
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8914
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8820
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8670
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7433
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6223
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5695
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2051
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.