[英]Why does nonclustered index column still do index scan instead of index seek
我有下表
EmployeePatientLink
Id nvarchar(128) PK & clustered index
PatientId nvarchar(128) FK NULL -- nonclustered index created
EmployeeId int NULL-- nonclustered index created.
患者
Id nvarchar(128) PK & clustered index
Id PK & clustered Index -- this links to above table
PatientSchedule
PatientId nvarchar(128)NULL-創建非聚集索引
和這個查詢
select
Id, PatientId
from
PatientSchedule ps
Inner join
EmployeePatientLink ep on ps.PatientId = ep.PatientId
where ep.EmployeeId=1111
我確實有類似上述的查詢,並且其他人在執行計划和嵌套循環聯接中執行索引查找。
但是,此操作始終包括“合並聯接”,“排序和索引”掃描。
我想我已經創建了足夠的索引,並且一切都井井有條,應該執行索引查找。
查詢優化器選擇索引查找有特定原因嗎?
嘗試使用包含的列創建索引,以避免“鍵查找”(SQL Server在找到EmployeeId時需要搜索PatientId值)
CREATE INDEX IX_EmployeePatientLink_EmployeeId ON EmployeePatientLink(EmployeeId)
INCLUDE (PatientId)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.