我将json内容存储在nvarchar(max)
列中。我也有deleted
数据的概念我现在使用特殊位列deleted
,而不是使用额外的列我可以使用nullable nvarchar(max)
但是在这种情况下我会松开索引该字段的能力。在这方面,我有几个问题:
nvarchar(max)
字段编入可以为空的事实deleted
仅用于一个时态查询:@from bigint = 0,
@till bigint = 8639999999999999 -- Max JavaScript unix timestamp in milliseconds
...
SELECT item.Id,
item.PreviousId,
item.UUID,
CASE
WHEN @from < item.UpdatedOnCurr AND item.UpdatedOnCurr <= @till AND @till < item.UpdatedOnNext
THEN item.Json
ELSE NULL
END AS Json,
item.TableName,
item.PermissionId,
item.UpdatedOnCurr
FROM Computed item
WHERE item.Deleted = 0 AND ( -- <------------- HERE IS DELETED
(@from < item.UpdatedOnCurr AND item.UpdatedOnCurr <= @till AND @till < item.UpdatedOnNext)
OR (item.UpdatedOnCurr <= @from AND @from < item.UpdatedOnNext AND item.UpdatedOnNext <= @till)
);