Given below script is the simplified example of a situation I am facing -
CREATE TABLE #tmp(pk bigint IDENTITY(1,1),id bigint, dt datetime)
DECLARE @X BIGINT=1
WHILE (@X<9223372036854775807)
BEGIN
INSERT INTO #tmp VALUES (@X,GETDATE())
SET @x=@x+1
END
CREATE INDEX idx on #tmp(id,dt)
SELECT id,max(dt) from #tmp GROUP BY id
Execution plan of this SP is scanning created index, how it can be moved to SEEK?
Thanks in advance!