[1] WHERE GETDATE() > [TimeStamp] | WHERE Expression > Column | WHERE Column < Expression are SARG predicates, and this means that a DBMS (such as SQL Server) can use Index Seek (or Index Seek + Key|RID Lookup ) to quickly find and return the required rows.
[2] WHERE GETDATE() > DATEADD(mi,0,[TimeStamp]) | WHERE Expression > ScalarFunction(Column) | WHERE ScalarFunction(Column) < Expression are not SARG-capable predicates, and this means that even if there is a valid index on [Timestamp] , the DBMS will not be able to use Seek . Instead, the operator Table|Index|Clustered Scan will be used, which has (usually , but not always ) lower performance than Index Seek (at least for OLTP systems).
So, DATEADD(mi,0,[TimeStamp]) forcibly uses the Scan data access operator, which is used to draw up a execution plan, even if there is an appropriate index. Without DATEADD DBMS can use the Seek operator, which might not be the optimal choice for some / most query parameter values. *
I would test both solutions (with and without DATEADD(MINUTE, 0, ...) ) to see if there are any differences in performance.
Note # 1: To force SQL2008R2 to scan, enter the FORCESCAN table hint (SQL2008 also comes with the FORCESEEK table FORCESEEK ) ( links ).
Note # 2: Basically, this function, used in the [Timestamp] column ( DATEADD(mi,0,[TimeStamp]) ), will also have consequences for optimizing query / query compilation, since no column statistics can be used. Instead, since the operation is not = , the predefined selectivity will be 33% (as far as I remember from the video presentation, it is not official / from documents).
Bogdan sahlean
source share