Chapter 17. Build your own index
Consider this SQL query:
You can immediately tell that the only way the SQL Server can evaluate this query is to look through every single email address, be that by scanning the table or by scanning an index on the email column. If the table is large, say, ten million rows, you can expect an execution time of at least a minute.
Imagine now that there is a requirement that in most cases the response time for a search should be only a few seconds. How could you solve this? Regular indexes do not help, nor do full-text indexes; to be efficient both require that there is no leading wildcard in the search string.
There is one way out: you have to build your own index. In this chapter I will look at three ways to do this. The first two methods more or less require SQL 2005 or later, whereas the last method is easily implementable on SQL 2000.
In this chapter we will work with the persons table shown in listing 1.