你推演基本上是正确的,但你必须考虑到不是每个优化可能也是实现。
Oracle 务实地观察潜力并决定应该在哪里扩展优化。
例如,有时谓词 where 1=1 and ... 可能会使优化器感到困惑,但由于这种“构造”被经常使用,在最近的版本中,优化器识别它并忽略它而没有副作用。
您的 outer 连接到子列的设置,而仅从父列中选择 distinct 可能不是很频繁,因此尚未涵盖。
这是一个类似的例子,Oracle 可以从视图中跳过一个表(注意 PK 和 FK 的定义,这是关键)
create table employees (
employee_id int primary key,
employee_name varchar2(10),
employee_active varchar2(10));
create table employee_info (
employee_id int,
marital_status varchar2(10));
alter table employee_info
add constraint emp_info_fk1 foreign key (employee_id)
references employees (employee_id);
create or replace view employee_view as
select e.EMPLOYEE_ID, e.employee_name, e.employee_active, ei.marital_status
from employees e
join employee_info ei on ei.employee_id = e.employee_id;
查询select marital_status from employee_view where employee_id = 13可以跳过employees(父)表,只访问子表
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMPLOYEE_INFO | 1 | 20 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("EI"."EMPLOYEE_ID"=13)
更多信息和链接在similar answer