我有一个带有唯一索引的表,该索引针对非空值进行了过滤。在查询计划中,使用了distinct。是否有一个原因?
USE tempdb
CREATE TABLE T1( Id INT NOT NULL IDENTITY PRIMARY KEY ,F1 INT , F2 INT )
go
CREATE UNIQUE NONCLUSTERED INDEX UK_T1 ON T1 (F1,F2) WHERE F1 IS NOT NULL AND F2 IS NOT NULL
GO
INSERT INTO T1(f1,F2) VALUES(1,1),(1,2),(2,1)
SELECT DISTINCT F1,F2 FROM T1 WHERE F1 IS NOT NULL AND F2 IS NOT NULL
SELECT F1,F2 FROM T1 WHERE F1 IS NOT NULL AND F2 IS NOT NULL
查询计划: