A view executed Select columns from view where col= "date range" (view contains calculation in it Col1+Col2*col3 AS Col4). It took 7 seconds for 500K rows to return, logical reads some 144k.
Added covering index and now after execution it says: logical reads = 8365 (some 17x times less) but the time of execution remained the same, some 7 seconds for 500k to return.
I would expect that reduction of logical reads would lower execution time too, or I am doing something wrong? Any advice?
Thanks.
@Craig, I tired what you told me and execution plan shows me that it was ignoring hints in both cases. It was index seek every time (index I added to help time execution). When I tried it without doing freeing cache it executed in almost the same time for all three of them and with no physical reads for the first execution. No need since all data was in the memory already. Here is the output of what you told me to try:
Warning: Index hints supplied for view 'Name of the view' will be ignored. Warning: Index hints supplied for view 'Name of the view' will be ignored.
SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms.
do not use any indexes
SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms. (100000 row(s) affected) Table 'Name'. Scan count 2, logical reads 2137, physical reads 7, read-ahead reads 6510, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times: CPU time = 156 ms, elapsed time = 939 ms.
let mssql choose what index to use
SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms. (100000 row(s) affected) Table 'Name'. Scan count 2, logical reads 2137, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times: CPU time = 94 ms, elapsed time = 799 ms.
force index name_of_index
SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms. (100000 row(s) affected) Table 'Name'. Scan count 2, logical reads 2137, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times: CPU time = 47 ms, elapsed time = 769 ms.