注意到Id=2的执行步骤的Operation列的值是“VIEW”,其对应的Name列的值是“VW_JF_SET$7C24F767”,和范例SQL一样,
这说明Oracle已经把视图view_jf的定义SQL语句中union all的公共部分表sales提了出来,然后用union all剩下的部分形成了
一个内嵌视图VW_JF_SET$7C24F767,即Oracle已经对范例SQL1做了连接因式分解。
有一条SQL在测试环境中能做连接因式分解,测试环境与生产环境完全全相同,同事说在生产环境中发现不能进行连接因式分解,说帮忙看看原因是因为生产环境中与该SQL相关的三张表原来的数据被清空了,而新导入的数据没有收集统计信息赞成的。下面来模拟测试一下这个问题。
下面的SQL在表sales,customers没有统计信息时不能进行连接因式分解
SQL> select t2.prod_id as prod_id
2 from sales t2,customers t3
3 where t2.cust_id=t3.cust_id
4 and t3.cust_gender='MALE'
5 union all
6 select t2.prod_id as prod_id
7 from sales t2,customers t3
8 where t2.cust_id=t3.cust_id
9 and t3.cust_gender='FEMALE';
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 4184572088
------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1837K| 28M| 1290 (2)| 00:00:16 | | |
| 1 | UNION-ALL | | | | | | | |
|* 2 | HASH JOIN | | 918K| 14M| 645 (2)| 00:00:08 | | |
|* 3 | VIEW | index$_join$_002 | 26739 | 182K| 119 (1)| 00:00:02 | | |
|* 4 | HASH JOIN | | | | | | | |
| 5 | BITMAP CONVERSION TO ROWIDS| | 26739 | 182K| 2 (0)| 00:00:01 | | |
|* 6 | BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX | | | | | | |
| 7 | INDEX FAST FULL SCAN | CUSTOMERS_PK | 26739 | 182K| 145 (0)| 00:00:02 | | |
| 8 | PARTITION RANGE ALL | | 918K| 8075K| 523 (1)| 00:00:07 | 1 | 28 |
| 9 | TABLE ACCESS FULL | SALES | 918K| 8075K| 523 (1)| 00:00:07 | 1 | 28 |
|* 10 | HASH JOIN | | 918K| 14M| 645 (2)| 00:00:08 | | |
|* 11 | VIEW | index$_join$_004 | 27750 | 189K| 119 (1)| 00:00:02 | | |
|* 12 | HASH JOIN | | | | | | | |
| 13 | BITMAP CONVERSION TO ROWIDS| | 27750 | 189K| 2 (0)| 00:00:01 | | |
|* 14 | BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX | | | | | | |
| 15 | INDEX FAST FULL SCAN | CUSTOMERS_PK | 27750 | 189K| 145 (0)| 00:00:02 | | |
| 16 | PARTITION RANGE ALL | | 918K| 8075K| 523 (1)| 00:00:07 | 1 | 28 |
| 17 | TABLE ACCESS FULL | SALES | 918K| 8075K| 523 (1)| 00:00:07 | 1 | 28 |
------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------