-2

I understand that the order of criteria in the where clause does not influence index usage.

Does parenthesis influence the index usage in SQL Server? Is there any example?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
variable
  • 8,262
  • 9
  • 95
  • 215
  • Parentheses will enforce the logical correctness of the query. If the query is not logically correct without parentheses then the usage of indexes is also logically irrelevant. – SMor May 30 '20 at 14:01
  • what is the motivation for this question? – Martin Smith May 30 '20 at 14:40

1 Answers1

1

Obviously. If I have an index on (y) and an expression like this:

 where y > 10 and x = 'a' or x = 'c'

then no index will be used.

If I put:

 where y > 10 and( x = 'a' or x = 'c')

Then the index will probably be used.

These do different things, but that is not part of your question. Parentheses can change the meaning of a SQL statement and that changes the use of indexes.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786