I have a query as follows
SELECT ActivityId,
AnotherId,
PersonId,
StartTime AS MyAlias
FROM Activity
WHERE DeletedStatus='Active' AND
StartTime>='2018-02-01'AND StartTime<='2018-02-08'
The execution plan being used is here
Index1 is defined as:
CREATE NONCLUSTERED INDEX Index1 ON Activity
(
StartTime
)
Index 2 is defined as:
CREATE CLUSTERED INDEX Index2 ON Activity
(
EndTime
StartTime
)
The optimiser is using an index seek on Index1 and is then using a key lookup because ActivityId,AnotherId,PersonId, are in the SELECT
list but not in the index. This makes sense to me.
However, the following things puzzle me:
- Why is the optimiser able to use Index1 to do an index seek when DeletedStatus is not in the index but is in the
WHERE
clause? - Why does the output list in Index1 include EndTime when that column is not present in Index1?
- How is Index2 being used to output ActivityId,AnotherId,PersonId when none of those columns are in Index2?
Apologies, I have pseudo-anonymised the plan and the query so I hope I have done it correctly!