我想根据两列是否相等进行快速查找。我尝试使用带有索引的计算列,但 SQL Server 似乎没有使用它。如果我只使用带有索引的静态填充位列,我会得到预期的索引查找。
似乎还有其他一些类似的问题,但没有一个关注为什么不使用索引。
测试表:
CREATE TABLE dbo.Diffs
(
Id int NOT NULL IDENTITY (1, 1),
DataA int NULL,
DataB int NULL,
DiffPersisted AS isnull(convert(bit, case when [DataA] is null and [DataB] is not null then 1 when [DataA] <> [DataB] then 1 else 0 end), 0) PERSISTED ,
DiffComp AS isnull(convert(bit, case when [DataA] is null and [DataB] is not null then 1 when [DataA] <> [DataB] then 1 else 0 end), 0),
DiffStatic bit not null,
Primary …
Run Code Online (Sandbox Code Playgroud)