How to search millions of record in SQL table faster?

user737063 picture user737063 · May 4, 2011 · Viewed 34.7k times · Source

I have SQL table with millions of domain name. But now when I search for let's say

SELECT * 
  FROM tblDomainResults 
 WHERE domainName LIKE '%lifeis%'

It takes more than 10 minutes to get the results. I tried indexing but that didn't help.

What is the best way to store this millions of record and easily access these information in short period of time?

There are about 50 million records and 5 column so far.

Answer

Igor Nazarenko picture Igor Nazarenko · May 4, 2011

Most likely, you tried a traditional index which cannot be used to optimize LIKE queries unless the pattern begins with a fixed string (e.g. 'lifeis%').

What you need for your query is a full-text index. Most DBMS support it these days.