SELECT SUM(AMT) FROM TB_TMP_TR GROUP BY ACCNO
SELECT SUM(AMT) FROM TB_TMP_TR2 GROUP BY ACCNO
The only different thing is TB_TMP_TR has ACC as clustered index and TB_TMP_TR2 has ACC as non-clustered index.
Execution plan show that the 1st is take 65% and 2nd take 35% (batch relative)
but with
SELECT * FROM TB_TMP_TR WHERE ACCNO = @acc
SELECT * FROM TB_TMP_TR2 WHERE ACCNO = @acc
the 1st is faster
I’m wondering why ?
A covering non-clustered index will likely be narrower than the clustered index, since the clustered index must include all columns. Being narrower it means it has fewer pages, which means fewer reads (both physical and logical). Hence, it will be faster. Covering being the key word.
Please run the two queries with