|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Yesterday @ 1:53 PM
Points: 785,
Visits: 1,534
|
|
Hi all,
Very basic question. I was reading the MCTS 70-433 training kit book from Microsoft, and fairly early on, they make a claim which I don't really fully believe.
In it, they claim that the use of the NOT operator makes indexes unusable for the query optimiser. However, I'm sure that I've regularly used NOT and had no problem with the optimiser using indexes. IE:
SELECT ID FROM Table WHERE ID NOT IN (1, 2, 3, 4, 5)
I have a feeling that the statement was just a generalized claim, since the following query clearly would not use an index seek:
SELECT ID FROM Table WHERE NOT (ID = 5 AND Name = 'Andrew')
Since, because of the NOT operator and the way boolean logic works, that query translates into an OR (WHERE ID <> 5 OR Name <> 'Andrew').
So, is the claim in the book incorrect?
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 9:29 AM
Points: 37,638,
Visits: 29,892
|
|
Yes, the claim in the book is incorrect and is a common myth.
p.s. Your second will be able to use indexes, but probably for a scan operation, not a seek (or for a ranged seek)
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|