我无法在此视图上创建索引
CCF.UserHistory.NEID
是一个计算并保留的列。
CREATE VIEW [Calais].[vwBossDaily]
WITH SCHEMABINDING
AS
SELECT SUM(ISNULL(Score, 0)) AS Score,
SUM(ISNULL(DivideBy, 0)) AS DivideBy,
COUNT_BIG(*) AS Count,
ReportDefGroupID,
ImportDate,
MetricID,
ISNULL(Calais.Card.BossNEID, 0) AS BossNEID,
ISNULL(CCF.UserHistory.BossNEID, 0) AS BossBossNEID
FROM Calais.Card
INNER JOIN CCF.UserHistory
ON Calais.Card.BossNEID = CCF.UserHistory.NEID
AND Calais.Card.ImportDate = CCF.UserHistory.keyDate
GROUP BY ReportDefGroupID,
ImportDate,
MetricID,
ISNULL(Calais.Card.BossNEID, 0),
ISNULL(CCF.UserHistory.BossNEID, 0)
GO
/****** Object: Index [VIX_Card] Script Date: 10/24/2013 11:28:01 ******/
CREATE UNIQUE CLUSTERED INDEX [VIX_Card]
ON [Calais].[vwBossDaily] (
[ReportDefGroupID] ASC,
[ImportDate] ASC,
[MetricID] ASC,
[BossNEID] ASC,
[BossBossNEID] ASC )
WITH (PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB = OFF,
IGNORE_DUP_KEY = OFF,
DROP_EXISTING = OFF,
ONLINE = OFF,
ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
错误:
Msg 1901,Level 16,State 1,Line 3
无法在视图'Calais.vwBossDaily'上创建索引或统计信息'VIX_Card',因为密钥 列'BossBossNEID'是不精确的,计算的而不是持久的 请考虑在视图索引或统计信息键中删除对列的引用 或者更改列是准确的。如果列是以base计算的 表考虑将其标记为PERSISTED那里。
问题的一个简单问题是
CREATE TABLE T
(
id int,
BossNEID AS CAST(id as float) PERSISTED
)
GO
CREATE VIEW V
WITH SCHEMABINDING
AS
SELECT ISNULL(BossNEID, 0) AS BossNEID
FROM dbo.T
GROUP BY ISNULL(BossNEID, 0)
GO
CREATE UNIQUE CLUSTERED INDEX IX ON V(BossNEID) /*Fails*/
答案 0 :(得分:3)
持久性不是问题所在。 准确性是。
即使表达式是确定性的,如果它包含浮点表达式,确切的结果可能取决于处理器体系结构或微代码的版本。为确保数据完整性,此类表达式只能作为索引视图的非键列参与。不包含浮点表达式的确定性表达式称为精确。只有精确的确定性表达式才能参与索引视图的键列和WHERE或GROUP BY子句。
(精确地强调了我)
不精确,被报告为可能的错误原因。
据我了解,两个浮点值相对于它们的绝对值可能会有一点点差异,它们可能被某些处理器架构或微码版本视为相同,并被视为与众不同。