I have an user scalar-valued function which takes NVARCHAR(MAX) and returns NVARCHAR(MAX). To increase perfomance of GROUP BY command utilizing this function I wanted to create an index also based on it. But documentation says what CREATE INDEX command only takes columns not expressions, so this is illegal:
CREATE INDEX an_index ON a_table (foo(a_column))
Are any workarounds?
Thank you!
You’ll need to create a computed column:
In order to be indexable, the function
foomust, of course, meet certain demands:You cannot build an index on a non-deterministic function like
GETDATEthat changes its return value every time you call it.It will be even easier to solve your case if you post the function you want to index on.