('xyz' != 'xyz')
和NOT ('xyz' = 'xyz')
虽然我在Oracle DB的上下文中提问,但也想知道其他语言中的相同情况。
差异主要与处理速度和所有背景材料有关。
答案 0 :(得分:0)
你看到有什么不同吗?
测试用例:
SQL> SELECT * FROM dual
2 WHERE ('xyz' != 'xyz');
no rows selected
SQL>
SQL> SELECT * FROM dual
2 WHERE NOT ('xyz' = 'xyz');
no rows selected
在上述两个查询中,应用的过滤器都是相同的过滤器(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>
没有区别。