Is there any differences (perf) writting this request:
Select * from T where PK = 1
or this
Select * from T where PK in (1)
I believe not but i realy don’t know how to dispay an execution plan that should assert my feeling.
Thx in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The IN expression:
Is internally rewritten into something very similar to:
You can tell this because, if you supply the name of a non-existent column, the number of errors reported (
Invalid Column name 'Blah') is equal to the number of values in the IN list. Of course, such re-writing only occurs for lists of literal values. Subqueries (as @oezi says) are handled differently.Of course, this particular optimization isn’t documented, and it is always preferable to write the clearest code possible.
I’m not sure if there’s an upper limit where it will not perform this expansion – it will certainly do it up to 100 values in the IN list (and I can’t be bothered to type in more).