I have a simple query but i don't understand the behavior of the Top Clause.
SELECT Top (1) Timestmp
FROM DataTable
WHERE [LoadId] = 3104
AND [Temp1] > @Setpoint
AND [Temp2] > @Setpoint
AND [Temp3] > @Setpoint
AND [Temp4] > @Setpoint
AND [Temp5] > @Setpoint
ORDER BY Timestmp OPTION (RECOMPILE)
(*query is a easier version of the ones in the Execution Plan, but altogether the same)
- There is a common Non-Clustered Index on
(LoadId, Temp1, Temp2, Temp3, Temp4, Temp5)
- And a separate Non-clustered Index on
Timestmp
The query takes about 1 Min to finish. But if i write Top (100) then it takes some [ms] to finish.
Here are some statistics of the Queries:
- Top (1) :logical reads 25757671, physical reads 148582, read-ahead reads 17695
- Top (100) :logical reads 290703, physical reads 0, read-ahead reads 0
Top (1) : https://www.brentozar.com/pastetheplan/?id=B1zwx0klN
Top (100) : https://www.brentozar.com/pastetheplan/?id=Hkx5k0JgE
How can I get Top (1) as fast as Top (100) and why is it that slow? I never saw that behavior before on other Servers, maybe its something wrong on the SQLServer Settings?