sql - Is dateadd() slow in on-conditions compared to where-clauses? -


i have situation in select, gets faster if move dateadd() on-condition where-clause.

but may not possible move on-condition , where-clause. solution move dateadd() on-condition temporary table instead, , sped entire stored procedure.

but left wondering; can true dateadd() slower in on-condition elsewhere?

i'll answer references sql server unless can find exact sybase references query optimisers work similarly

to start, dateadd function on predicate invalidates index usage (see number 2 here).

the on clause form of predicate of course (think of old implicit-join-in-where syntax) same applies.

now, queries honour logical processing step (if not actual, that's why "query optimisers" called so). on before 1 of them.

with dateadd in clause, residual filter because main work has been done in on clause restrict rows. if dateadd in on clause, gets processed "sooner" clause.

this per sybase join docs state

...the optimizer can consider indexes on column names. type of operator or expression in combination column name means optimizer not evaluate using index on column possible access method. if columns in join of incompatible datatypes, optimizer can consider index on 1 of columns.

the query processing order hinted @ in sybase doc

the same thing applies outer table filters in left joins, really: in case clause late after left join. or why not exists beats left join .. null. see sybase outer joins

dateadd isn't problem: logical query processing order makes appear one


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -