Hi,
I'm trying to do a query on a database that will find me the owner of an IP address I've stored. I have IP addresses and hostnames; and the corresponding Regular Expressions. My query is taking about 7 seconds per lookup and I have hundreds of lookups; any tips to speed this up would be great.
First off, it just tries to identify if it is an IP address or a hostname with the regular expression... by using IF statements, will choose the corresponding SELECT statement to use...
if (dbo.find_regular_expression('hostnameoripaddress, '^([0-9]|[1-9][0-9]|1[0-9][0-9]|2[-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[-4][0-9]|25[0-5])', 0) = 1)
SELECT top 1 *
FROM sampledata
where (ip_low != '0.0.0.0' and dbo.ipstringtoint('hostnameoripaddress') between dbo.ipstringtoint(ip_low) and dbo.ipstringtoint(ip_high))
else
select top 1 *
from sampledata
where (ip_low != '0.0.0.0' and dbo.ipstringtoint('hostnameoripaddress') between dbo.ipstringtoint(ip_low) and dbo.ipstringtoint(ip_high))
dbo.ipstringtoint converts the IP string such as 192.168.1.1 to its corresponding integer value such as 425897585.
dbo.find_regular_expression is a UDF I found on the Web; I suspect this may be slowing things up so suggestions on how to compare against regular expression or a better function would be great.
The database has no null values; that is why there is '0.0.0.0' as default value in ip_low or ip_high if only hostname and hostname regular expression are known.
Thanks in advance.
I'm trying to do a query on a database that will find me the owner of an IP address I've stored. I have IP addresses and hostnames; and the corresponding Regular Expressions. My query is taking about 7 seconds per lookup and I have hundreds of lookups; any tips to speed this up would be great.
First off, it just tries to identify if it is an IP address or a hostname with the regular expression... by using IF statements, will choose the corresponding SELECT statement to use...
if (dbo.find_regular_expression('hostnameoripaddress, '^([0-9]|[1-9][0-9]|1[0-9][0-9]|2[-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[-4][0-9]|25[0-5])', 0) = 1)
SELECT top 1 *
FROM sampledata
where (ip_low != '0.0.0.0' and dbo.ipstringtoint('hostnameoripaddress') between dbo.ipstringtoint(ip_low) and dbo.ipstringtoint(ip_high))
else
select top 1 *
from sampledata
where (ip_low != '0.0.0.0' and dbo.ipstringtoint('hostnameoripaddress') between dbo.ipstringtoint(ip_low) and dbo.ipstringtoint(ip_high))
dbo.ipstringtoint converts the IP string such as 192.168.1.1 to its corresponding integer value such as 425897585.
dbo.find_regular_expression is a UDF I found on the Web; I suspect this may be slowing things up so suggestions on how to compare against regular expression or a better function would be great.
The database has no null values; that is why there is '0.0.0.0' as default value in ip_low or ip_high if only hostname and hostname regular expression are known.
Thanks in advance.