('xyz' != 'xyz') 和 NOT ('xyz' = 'xyz') 有什么区别
What difference between ('xyz' != 'xyz') and NOT ('xyz' = 'xyz')
('xyz' != 'xyz')
和NOT ('xyz' = 'xyz')
有区别吗
虽然我在 Oracle DB 的上下文中询问,但也想知道其他语言中的相同情况。
差异主要是 处理速度 和所有背景资料。
有什么不同吗?
测试用例:
SQL> SELECT * FROM dual
2 WHERE ('xyz' != 'xyz');
no rows selected
SQL>
SQL> SELECT * FROM dual
2 WHERE NOT ('xyz' = 'xyz');
no rows selected
在上述两个查询中,应用的过滤器相同 filter(NULL IS NOT NULL).
执行计划:
SQL> EXPLAIN PLAN FOR
2 SELECT * FROM dual
3 WHERE ('xyz' != 'xyz');
Explained.
SQL>
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3752461848
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 0 (0)| |
|* 1 | FILTER | | | | | |
| 2 | TABLE ACCESS FULL| DUAL | 1 | 2 | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
---------------------------------------------------
1 - filter(NULL IS NOT NULL)
14 rows selected.
SQL>
SQL> EXPLAIN PLAN FOR
2 SELECT * FROM dual
3 WHERE NOT ('xyz' = 'xyz');
Explained.
SQL>
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3752461848
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 0 (0)| |
|* 1 | FILTER | | | | | |
| 2 | TABLE ACCESS FULL| DUAL | 1 | 2 | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
---------------------------------------------------
1 - filter(NULL IS NOT NULL)
14 rows selected.
SQL>
没有区别。
('xyz' != 'xyz')
和NOT ('xyz' = 'xyz')
虽然我在 Oracle DB 的上下文中询问,但也想知道其他语言中的相同情况。
差异主要是 处理速度 和所有背景资料。
有什么不同吗?
测试用例:
SQL> SELECT * FROM dual
2 WHERE ('xyz' != 'xyz');
no rows selected
SQL>
SQL> SELECT * FROM dual
2 WHERE NOT ('xyz' = 'xyz');
no rows selected
在上述两个查询中,应用的过滤器相同 filter(NULL IS NOT NULL).
执行计划:
SQL> EXPLAIN PLAN FOR
2 SELECT * FROM dual
3 WHERE ('xyz' != 'xyz');
Explained.
SQL>
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3752461848
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 0 (0)| |
|* 1 | FILTER | | | | | |
| 2 | TABLE ACCESS FULL| DUAL | 1 | 2 | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
---------------------------------------------------
1 - filter(NULL IS NOT NULL)
14 rows selected.
SQL>
SQL> EXPLAIN PLAN FOR
2 SELECT * FROM dual
3 WHERE NOT ('xyz' = 'xyz');
Explained.
SQL>
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3752461848
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 0 (0)| |
|* 1 | FILTER | | | | | |
| 2 | TABLE ACCESS FULL| DUAL | 1 | 2 | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
---------------------------------------------------
1 - filter(NULL IS NOT NULL)
14 rows selected.
SQL>
没有区别。