Fortunately there are some options available to overcome this limitation.
INCLUDE COLUMNS
The first is to leverage the INCLUDE
1) The Index can fully cover a query if the SELECT statement contains columns that could otherwise not participate in the index key.
2) The overall size of the index would be reduced.
HASHBYTES
The second option would be to add a column to the table of interest that would contain the hash value of the column to be searched on. This new column can then be indexed to provide better performance for searching. SQL Server provides a function, HASHBYTES, that returns the hash of the input provided. Algorithms supported by HASHBYTES include MD2, MD4, MD5, SHA, and SHA1. More detail on hash functions can be found here from RSA Labs
Updating the new column with the hash value can be accomplished like this:
UPDATE Table XYZ set ColA_Hash = HASHBYTE('SHA1',ColA)
With an index in place, filtering in the WHERE clause using the HASHBYTE of the interested text should result in improved performance.
WHERE
HASHBYTE('SHA1',text) = ColA_Hash
The use of HASHBYTES is an alternative but it should be noted that this will not provide a solution to searches filtered using the LIKE operator.
No comments:
Post a Comment