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