Всем привет.
Решили создать indexed view с использованием CLR функции. Все, вроде, нормльно, кластерный индекс на вьюшке создается, но при попытке создать некластерный индекс на CLR поле, говорит:
Cannot create index or statistics 'Ix_IndexedView_One' on view 'vwIndexedViewTest' because cannot verify key column 'idPlusOne' is precise and deterministic. Consider removing column from index or statistics key, marking column persisted in base table if it is computed, or using non-CLR-derived column in key.
БОЛ говорит, что CLR поля не могут быть частью кластерного индекса, но про некластерные ничего не говорит.
Кому интересно, могут попробовать:
create table [dbo].[IndexedViewTest](
[id] [int] identity(1,1) not null,
[name] [varchar](50) null
constraint PK_id primary key clustered
(
[id] asc
)
)
Метод помечен как deterministic и precise, что и требуется.
[Microsoft.SqlServer.Server.SqlFunction(IsDeterministic=true,IsPrecise=true, DataAccess=DataAccessKind.None, SystemDataAccess=SystemDataAccessKind.None)]
public static SqlInt32 AddOne(SqlInt32 number)
{
return number + 1;
}
create view dbo.vwIndexedViewTest
with schemabinding
as
select id, name, convert(int, dbo.AddOne(1)) as idPlusOne
from dbo.IndexedViewTest
go
create unique clustered index Ix_IndexedView on vwIndexedViewTest(id)
Теперь пытаемся создать ещё один некластерный индекс
create nonclustered index Ix_IndexedView_One on vwIndexedViewTest(idPlusOne)
Вот этого он делать не позволяет.