SQL> set pagesize 20000
SQL> set autotrace trace
SQL> create table dao_objects as select * from dba_objects ;
Table created.
SQL> create index idx_obj_id on dao_objects (object_id) ;
create index idx_obj_type on dao_objects (object_type) ;
Index created.
SQL>
Index created.
SQL> select *
2 from dao_objects do
3 where do.object_id<2000
4 or do.object_type='VIEW';
Execution Plan
----------------------------------------------------------
Plan hash value: 3924143853
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 7479 | 1511K| 36 (0)| 00:00:01 |
| 1 | CONCATENATION | | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| DAO_OBJECTS | 5181 | 1047K| 20 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | IDX_OBJ_TYPE | 415 | | 5 (0)| 00:00:01 |
|* 4 | TABLE ACCESS BY INDEX ROWID| DAO_OBJECTS | 2298 | 464K| 16 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | IDX_OBJ_ID | 934 | | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("DO"."OBJECT_TYPE"='VIEW')
4 - filter(LNNVL("DO"."OBJECT_TYPE"='VIEW'))
5 - access("DO"."OBJECT_ID"<2000)
Note
-----
- dynamic sampling used for this statement (level=2)
請注意ID爲1的操作CONCATENATION.
CONCATENATION操作類似 union ,只不過與union 不同的是他並不對全部數據去重.
CONCATENATION操作只去除由OR引起的重複值.這點在我們做SQL改寫的時候一定要特別注意.
因爲empno爲7934的記錄 部門編號爲20
SQL> select e.empno,e.deptno
2 from scott.emp e
3 where empno >7900 or deptno=10 ;
EMPNO DEPTNO
---------- ----------
7782 10
7839 10
7902 20
7934 10
SQL> select e.empno,e.deptno
2 from scott.emp e
3 where empno >7900 ;
EMPNO DEPTNO
---------- ----------
7902 20
7934 10
SQL> select e.empno,e.deptno
2 from scott.emp e
3 where deptno=10;
EMPNO DEPTNO
---------- ----------
7782 10
7839 10
7934 10