January 30, 2014 at 12:44 pm
Which one of these three (3) WHERE clauses is BEST for PERFORMANCE?[/b]
1) where databasename ='myDBname'
and charindex ('SQLAgent', applicationname)=0
and charindex ('SQL Server Log Shipping', applicationname )=0
and charindex ('Spotlight Diagnostic',applicationname )=0
2) where databasename =my'DBname'
and applicationname NOT LIKE 'SQLAgent'
and applicationname NOT LIKE ' SQL Server Log Shipping'
and applicationname NOT LIKE 'Spotlight Diagnostic'
3) where databasename ='myDBname'
and applicationname
NOT IN (''SQLAgent' ', ' SQL Server Log Shipping', 'Spotlight Diagnostic')
Likes to play Chess
January 30, 2014 at 12:58 pm
Tell us - try them.
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
January 30, 2014 at 1:03 pm
I agree with Chris, you should try them.
However, you might note that No.1 is using a function so it's not SARGable and No.2 is using LIKE with no wildcards, so LIKE operator is not needed.
January 30, 2014 at 1:16 pm
Sorry I missed the % in LIKEs. Of course I meant wildcards..
As far as the clause with FUNCTION being NOT SARGeable - what do you mean? why not?
THANKS !!!
Likes to play Chess
January 30, 2014 at 1:19 pm
This explains the basics: http://bit.ly/1aKPF3N
January 30, 2014 at 4:11 pm
VoldemarG (1/30/2014)
Sorry I missed the % in LIKEs. Of course I meant wildcards..
If that's true, then the best solution (Option 3) cannot be accomplished.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 31, 2014 at 12:22 am
VoldemarG (1/30/2014)
Sorry I missed the % in LIKEs. Of course I meant wildcards..
In that case option 2 and option 3 are not equivalent and hence cannot be compared for performance.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 31, 2014 at 9:28 am
so from everything I heard/read, would that be fair to conclude that option 2 is the way to go in the majority of cases?
2) where databasename ='myDBname'
and applicationname NOT LIKE 'SQLAgent%'
and applicationname NOT LIKE ' SQL Server Log Shipping%'
and applicationname NOT LIKE 'Spotlight Diagnostic%'
Likes to play Chess
January 31, 2014 at 9:43 am
VoldemarG (1/31/2014)
so from everything I heard/read, would that be fair to conclude that option 2 is the way to go in the majority of cases?2) where databasename ='myDBname'
and applicationname NOT LIKE 'SQLAgent%'
and applicationname NOT LIKE ' SQL Server Log Shipping%'
and applicationname NOT LIKE 'Spotlight Diagnostic%'
If you need the wildcard then yes that would be the best way. Option 1 is nonSARGable and option 3 is not the same thing.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 31, 2014 at 9:49 am
Sean Lange (1/31/2014)
VoldemarG (1/31/2014)
so from everything I heard/read, would that be fair to conclude that option 2 is the way to go in the majority of cases?2) where databasename ='myDBname'
and applicationname NOT LIKE 'SQLAgent%'
and applicationname NOT LIKE ' SQL Server Log Shipping%'
and applicationname NOT LIKE 'Spotlight Diagnostic%'
If you need the wildcard then yes that would be the best way. Option 1 is nonSARGable and option 3 is not the same thing.
Note that you have a leading space on your second condition and that if you add a leading wildcard it will become nonSARGable as well. So, what's the best option? I can't give a definite answer.
January 31, 2014 at 9:52 am
Leading space was just my finger tapping the keyboard too intensely..
typo..
Likes to play Chess
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply