sql server - T-SQL - Do more conditions help the query proceed faster? -
lets consider simple table 2 relevant columns:
bit isdownloaded not null datetime datedownloaded null
i know isdownloaded 1 when datedownloaded has value (this example understand isdownloaded not neccessary then).
is there performance difference between:
select * files isdownloaded = 1 , datedownloaded not null , datedownloaded > '2010-01-01'
and
select * files datedownloaded not null , datedownloaded > '2010-01-01'
therefore to:
- add "easier evaluate" conditions (such conditions on boolean datetypes)
- add mode conditions in general
consider there no indexes applied on columns.
tl;dr
indexes, , selectivity of query. in case above, ensuring there index on datedownloaded
drive performance of query - is not null
, isdownloaded
checks won't (if flag correlated date).
explanation
no indexes @ all, there no alternative sql other iterate through rows in table evaluating predicate (full scan).
with index on datedownloaded
, option exists use index exclude rows evaluation against remainder of predicate (provided not files
have datedownloaded > '2010-01-01'
)
(indexing isdownloaded
flag not idea if has 2 states, , if neither state represents less couple of % of data).
so yes, in general case, should use additional information available, further reduce number of rows evaluated (although in truth automatic process, since query otherwise return wrong results).
but in case here, given isdownloaded
flag set if there datedownloaded
date, redundant include in predicate (as not null
) not exclude additional rows > 2010-01-01
criterion.
Comments
Post a Comment