There is no difference between the two statements, and the optimizer converts IN to = when IN has only one element in it.
Although, when you have such a question, just run both statements, run their execution plan and see the differences. You will not find here.
After a lot of searching on the Internet, I found a SQL document to support this (I assume it applies to all DBMSs):
If there is only one value in the parenthesis, this commend is equivalent to
WHERE "column_name" = 'value1
Here is the link to the document .
Here is the plan for executing both queries in Oracle (most DBMSs will handle the same):
EXPLAIN PLAN FOR select * from dim_employees t where t.identity_number = '123456789' Plan hash value: 2312174735 ----------------------------------------------------- | Id | Operation | Name | ----------------------------------------------------- | 0 | SELECT STATEMENT | | | 1 | TABLE ACCESS BY INDEX ROWID| DIM_EMPLOYEES | | 2 | INDEX UNIQUE SCAN | SYS_C0029838 | -----------------------------------------------------
And for IN() :
EXPLAIN PLAN FOR select * from dim_employees t where t.identity_number in('123456789'); Plan hash value: 2312174735 ----------------------------------------------------- | Id | Operation | Name | ----------------------------------------------------- | 0 | SELECT STATEMENT | | | 1 | TABLE ACCESS BY INDEX ROWID| DIM_EMPLOYEES | | 2 | INDEX UNIQUE SCAN | SYS_C0029838 | -----------------------------------------------------
As you can see, they are both the same. This is in the indexed column. The same goes for an unindexed column (just a full table scan).
sagi Jun 15 '16 at 7:13 2016-06-15 07:13
source share