Sql server: bottom function on indexed column

I found one big problem.

I added the Lower function to the indexed column of one of the tables to retrieve data. The table contains more than 100 thousand records.

When retrieving records, CPU utilization is 100% changed.

I could not understand how this drastic change can only happen due to the Lower () function.

Please, help!

+4
source share
2 answers

What you could do if you really need this query is to create a constant computed column that uses the LOWER () function. Index this column and you should be fine:

ALTER TABLE dbo.YourTableName ADD LowerFieldName AS LOWER(YourFieldName) PERSISTED CREATE NONCLUSTERED INDEX IX_YourTableName_LowerFieldName ON dbo.YourTableName(YourFieldName) 

This will maintain the representation of your field in your lower case, it is always relevant, and since it is stored, it is part of your table and is not responsible for the LOWER () function. Put an index on it and your search will be as fast as before.

References:

+8
source

When you add LOWER () (or any function) around a column, it is no longer possible to use an index (it is no longer available to SARG).

By default, SQL Server is not case sensitive, so you can remove it.

+6
source

All Articles