I have a table with 8.2 million entries in a SQL Server 2005 database. This table stores basic past customer details (referrer, ip, whether they entered via an advertisement, etc) for every customer we have had come to the site. Unfortunately, whoever designed the table (way before I was here, I'm a lowly intern) used a varchar(50)
field for the ip address field in the table.
Now, I have been tasked with finding a way to run a query to see if we have an entry for a given ip address. This is the first time I've had to deal with a data set this large and no matter what I do, I can't seem to improve the result speed much.
Here is an example query from what I was running:
SELECT TOP(1) [ID]
FROM [dbo].[SiteVisit]
WHERE [IPAddress] = '61.135.249.118'
This query ran for over 2 min and 31 seconds before I cancelled it. Is there any way to improve the speed of this look up or would it be more advisable to create a new index in the table that stores the INET_ATON values and perform the look up on that?
Thanks!