执行计划-CONCATENATION释疑

来源:互联网 发布:php怎样保持登录状态 编辑:程序博客网 时间:2024/06/05 11:53
SQL> set linesize 200
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         10SQL> select e.empno,e.deptno  2    from scott.emp e   3   where empno >7900 ;     EMPNO     DEPTNO---------- ----------      7902         20      7934         10SQL> select e.empno,e.deptno  2    from scott.emp e   3   where deptno=10;     EMPNO     DEPTNO---------- ----------      7782         10      7839         10      7934         10


原创粉丝点击