I can can't create an index on this view
CCF.UserHistory.NEID is a calculated and persisted column.
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
Error:
Msg 1901, Level 16, State 1, Line 3
Cannot create index or statistics 'VIX_Card' on view 'Calais.vwBossDaily' because key column 'BossBossNEID' is imprecise, computed and not persisted.
Consider removing reference to column in view index or statistics key or changing column to be precise. If column is computed in base table consider marking it PERSISTED there.
A simpler repro of the issue is
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*/
Persistence is not the issue here. Preciseness is.
From Create Indexed Views:
Even if an expression is deterministic, if it contains float expressions, the exact result may depend on the processor architecture or version of microcode. To ensure data integrity, such expressions can participate only as nonkey columns of indexed views. Deterministic expressions that do not contain float expressions are called precise. Only precise deterministic expressions can participate in key columns and in WHERE or GROUP BY clauses of indexed views.
(precise emphasized my me)
Being imprecise, is reported as a possible cause of the error.
As I understand it, two floating point values may differ by such a little amount, relative to their absolute values, that they may be considered equal by some processor architectures or versions of microcode and be considered different by others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With