Andy Brownsword speeds up a query:
Bad code smells can run through a system, and one instance can quickly spread when code is recycled. Simon recently looked at a non-sargable example and was able to fix it by using an index and refactoring the query.
I wanted to consider an alternative approach if we saw the same issue repeated consistently. We don’t want to fix each instance, we want a single fix. We’ll solve this with indexed computed column.
We can index computed columns to help resolve deterministic (i.e. won’t change, no
GETDATE()
allowed) clauses. Let’s get started.
Read on to learn more. This is a powerful approach to the problem of needing to perform some sort of data transformation before filtering your data.