Why when I JOIN to a casted field in an index view, the execution plan warns about “type conversion in expression”?

dba.stackexchange https://dba.stackexchange.com/questions/255438

سؤال

I thought an indexed view was materialized and therefor stored on disk. If that's the case, I would've thought that any type conversions I'm doing in the view would materialize as that datatype on disk and I wouldn't have to worry about casting issues while using those fields in JOIN and WHERE predicates against the view.

Why is this not so?

Type Conversion in Expression Warning

هل كانت مفيدة؟

المحلول

An indexed view is expanded during query compilation unless the NOEXPAND table hint is used. The warning is generated on that expansion. In Enterprise Edition, the optimizer may later match the expansion back to the materialized view. This is a cost-based decision.

In anything other than Enterprise Edition (or equivalent) you must use a NOEXPAND hint to use the index(es) on a materialized view.

In Enterprise Edition, there are still good reasons to use the NOEXPAND hint:

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى dba.stackexchange
scroll top