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

UDF Performance Question

I've got a UDF that is used on the publishing side of a data warehouse:
when the data is headed out to a mart. It works fine for sets of a few
thousand rows, but really slows for sets of a few million rows: a
query will go from one to thirty minutes due to two calls on each row.
Any suggestions or advise?

-----------------------------------------------------------------------------
-- convert ip from integer format to string format
-- ex: from 3232235621 to 192.168.0.101
-----------------------------------------------------------------------------
create function IP2STRING(IP_BIGINT bigint)
returns varchar(15)
deterministic
no external action
begin atomic
declare node_1 bigint;
declare node_2 bigint;
declare node_3 bigint;
declare node_4 bigint;
SET node_1 = MOD(BIGINT(ip_bigint / 16777216), 256);
SET node_2 = MOD(INTEGER(ip_bigint / 65536), 256);
SET node_3 = MOD(INTEGER(ip_bigint / 256), 256);
SET node_4 = MOD(ip_bigint, 256);
return RTRIM(CHAR(node_1)) || '.' || RTRIM(CHAR(node_2)) || '.' ||
RTRIM(CHAR(node_3)) || '.' || RTRIM(CHAR(node_4));
end

Am I missing any good opportunities to speed this up?
Any faster algorithm or functions to switch to?
Or should I consider a java routine with bitfiddling (yuck)?
Or give up on this approach and move the logic out of the database
(dang)?
Thanks in advance!

Ken

Jan 24 '06 #1
3 2100
kenfar wrote:
I've got a UDF that is used on the publishing side of a data warehouse:
when the data is headed out to a mart. It works fine for sets of a few
thousand rows, but really slows for sets of a few million rows: a
query will go from one to thirty minutes due to two calls on each row.
Any suggestions or advise?

-----------------------------------------------------------------------------
-- convert ip from integer format to string format
-- ex: from 3232235621 to 192.168.0.101
-----------------------------------------------------------------------------
create function IP2STRING(IP_BIGINT bigint)
returns varchar(15)
deterministic
no external action
begin atomic
declare node_1 bigint;
declare node_2 bigint;
declare node_3 bigint;
declare node_4 bigint;
SET node_1 = MOD(BIGINT(ip_bigint / 16777216), 256);
SET node_2 = MOD(INTEGER(ip_bigint / 65536), 256);
SET node_3 = MOD(INTEGER(ip_bigint / 256), 256);
SET node_4 = MOD(ip_bigint, 256);
return RTRIM(CHAR(node_1)) || '.' || RTRIM(CHAR(node_2)) || '.' ||
RTRIM(CHAR(node_3)) || '.' || RTRIM(CHAR(node_4));
end

Am I missing any good opportunities to speed this up?
Any faster algorithm or functions to switch to?
Or should I consider a java routine with bitfiddling (yuck)?
Or give up on this approach and move the logic out of the database
(dang)?

Today SQL UDF which include BEGIN ATOMIC are serialized.
In a DPF enviroment (which I presuem you're in) this means that got
yourself a bottlenck. It will also limit the optimization capabilities
of the optimizer

SQL UDF work great when you can reduce them to only RETURN:

create function IP2STRING(IP_BIGINT bigint)
returns varchar(15)
deterministic
no external action
contains sql
return RTRIM(CHAR(MOD(BIGINT(ip_bigint / 16777216), 256)))
|| '.' || RTRIM(CHAR(MOD(INTEGER(ip_bigint / 65536), 256)))
|| '.' || RTRIM(CHAR(MOD(INTEGER(ip_bigint / 256), 256)))
|| '.' || RTRIM(CHAR(MOD(ip_bigint, 256)))

Enjoy
Serge
--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Jan 24 '06 #2
Serge,
SQL UDF work great when you can reduce them to only RETURN:
Thanks! That worked perfect.

Today SQL UDF which include BEGIN ATOMIC are serialized.
In a DPF enviroment (which I presuem you're in) this means that got
yourself a bottlenck. It will also limit the optimization capabilities
of the optimizer


Any suggestions for reference material on this subject? Is Paul Yip's
book the best resource?
Ken Farmer

Jan 24 '06 #3
kenfar wrote:
Serge,

SQL UDF work great when you can reduce them to only RETURN:

Thanks! That worked perfect.
Today SQL UDF which include BEGIN ATOMIC are serialized.
In a DPF enviroment (which I presuem you're in) this means that got
yourself a bottlenck. It will also limit the optimization capabilities
of the optimizer

Any suggestions for reference material on this subject? Is Paul Yip's
book the best resource?

Not sure how much he has on this topic. Assuming your email address
works I just sent you and (aged) DBM Tech presentation.
If you want to get really into things you can read up the patents:
http://patft.uspto.gov/netahtml/search-bool.html

5,987,455 Intelligent compilation of procedural functions for query
processing systems
5,963,934 Intelligent compilation of scripting language for query
processing systems

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Jan 24 '06 #4

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

Similar topics

7
by: Randell D. | last post by:
Folks, I have a Javascript performance question that I might have problems explaining... In PHP, better performance can be obtained dealing directly with a variable, as opposed to an element...
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
4
by: Martin | last post by:
I am using graphics as backgrounds for forms,buttons,labels etc. The question is: is it faster to load all graphics from files on app start or to use it embeded (places in editor during design)....
13
by: bjarne | last post by:
Willy Denoyette wrote; > ... it > was not the intention of StrousTrup to the achieve the level of efficiency > of C when he invented C++, ... Ahmmm. It was my aim to match the performance...
6
by: Mike | last post by:
Lets just say my app is done HOO HOO. Now, I'm accessing the database via a web service and one thing i noticed that my app is running real slow. When I first started working on the app is ran...
18
by: Rune B | last post by:
Hi Group I was considering using a Generic Dictionary<> as a value container inside my business objects, for the reason of keeping track of fields changed or added and so on. - But how...
5
by: Varangian | last post by:
Hi, I have a performance issue question? which is best (in terms of efficiency and performance, I don't care neatness in code)... building an ArrayList of Object Instances using SqlDataReader...
5
by: Markus Ernst | last post by:
Hello A class that composes the output of shop-related data gets some info from the main shop class. Now I wonder whether it is faster to store the info in the output class or get it from the...
5
by: toton | last post by:
Hi, I want a few of my class to overload from a base class, where the base class contains common functionality. This is to avoid repetition of code, and may be reducing amount of code in binary,...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
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: 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...

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.