sql - Why does nonclustered index column still do index scan instead of index seek -
i have following tables
employeepatientlink
id nvarchar(128) pk & clustered index patientid nvarchar(128) fk null -- nonclustered index created employeeid int null-- nonclustered index created. patient
id nvarchar(128) pk & clustered index id pk & clustered index -- links above table patientschedule
patientid nvarchar(128) null -- nonclustered index created
and query
select id, patientid patientschedule ps inner join employeepatientlink ep on ps.patientid = ep.patientid ep.employeeid=1111 i have have similar queries above , others perform index seek in execution plan , nested loop joins.
however 1 includes merge join , sort , index scan.
i guess have sufficient indexes created , in order , should doing index seek.
is there specific reason why query optimizer chooses index seek?
try create index included columns avoid "key lookup" (sql server need search patientid value when employeeid found)
create index ix_employeepatientlink_employeeid on employeepatientlink(employeeid) include (patientid)
Comments
Post a Comment