In a query statement using a view or nested view, Oracle merges these views to obtain the optimal execution plan and connects the tables in the view to the tables in the external query.
- -- Example:
- SQL>SelectE. first_name, e. last_name, dept_locs_v.street_address, dept_locs_v.postal_code
- 2FromEmployees e,
- 3 (SelectD. department_id, d. department_name, l. street_address, l. postal_code
- 4FromSpecified ments d, locations l
- 5WhereD. location_id = l. location_id) dept_locs_v
- 6WhereDept_locs_v.department_id = e. department_id
- 7AndE. last_name ='Smith';
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 994428606
- Bytes ---------------------------------------------------------------------------------------------
- | Id | Operation |Name|Rows| Bytes | Cost (% CPU) |Time|
- Bytes ---------------------------------------------------------------------------------------------
- | 0 |SELECTSTATEMENT | 1 | 56 | 4 (0) | 00:00:01 |
- | 1 | nested loops | 1 | 56 | 4 (0) | 00:00:01 |
- | 2 | nested loops | 1 | 25 | 3 (0) | 00:00:01 |
- | 3 |TABLEACCESSBY INDEXROWID | EMPLOYEES | 1 | 18 | 2 (0) | 00:00:01 |
- | * 4 |INDEXRange scan | EMP_NAME_IX | 1 | 1 (0) | 00:00:01 |
- | 5 |TABLEACCESSBY INDEXROWID | ments | 1 | 7 | 1 (0) | 00:00:01 |
- | * 6 |INDEX UNIQUESCAN | DEPT_ID_PK | 1 | 0 (0) | 00:00:01 |
- | 7 |TABLEACCESSBY INDEXROWID | LOCATIONS | 1 | 31 | 1 (0) | 00:00:01 |
- | * 8 |INDEX UNIQUESCAN | LOC_ID_PK | 1 | 0 (0) | 00:00:01 |
- Bytes ---------------------------------------------------------------------------------------------
- Predicate Information (identifiedByOperation id ):
- ---------------------------------------------------
- 4-access ("E"."LAST_NAME"='Smith')
- 6-access ("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
- 8-access ("D"."LOCATION_ID"="L"."LOCATION_ID")
- -- Use no_merge to disable view Merging
- SQL>Select/* + No_merge (dept_locs_v) */e. first_name, e. last_name, dept_locs_v.street_address, dept_locs_v.postal_code
- 2FromEmployees e,
- 3 (SelectD. department_id, d. department_name, l. street_address, l. postal_code
- 4FromSpecified ments d, locations l
- 5WhereD. location_id = l. location_id) dept_locs_v
- 6WhereDept_locs_v.department_id = e. department_id
- 7AndE. last_name ='Smith';
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 842533999
- Bytes --------------------------------------------------------------------------------------------------
- | Id | Operation |Name|Rows| Bytes | Cost (% CPU) |Time|
- Bytes --------------------------------------------------------------------------------------------------
- | 0 |SELECTSTATEMENT | 1 | 61 | 7 (15) | 00:00:01 |
- | * 1 | HASHJOIN| 1 | 61 | 7 (15) | 00:00:01 |
- | 2 |TABLEACCESSBY INDEXROWID | EMPLOYEES | 1 | 18 | 2 (0) | 00:00:01 |
- | * 3 |INDEXRange scan | EMP_NAME_IX | 1 | 1 (0) | 00:00:01 |
- | 4 |VIEW| 27 | 1161 | 4 (0) | 00:00:01 |
- | 5 |TABLEACCESSBY INDEXROWID | ments | 1 | 7 | 1 (0) | 00:00:01 |
- | 6 | nested loops | 27 | 1026 | 4 (0) | 00:00:01 |
- | 7 |TABLEACCESSFULL| LOCATIONS | 23 | 713 | 3 (0) | 00:00:01 |
- | * 8 |INDEXRange scan | DEPT_LOCATION_IX | 4 | 0 (0) | 00:00:01 |
- Bytes --------------------------------------------------------------------------------------------------
- Predicate Information (identifiedByOperation id ):
- ---------------------------------------------------
- 1-access ("DEPT_LOCS_V"."DEPARTMENT_ID"="E"."DEPARTMENT_ID")
- 3-access ("E"."LAST_NAME"='Smith')
- 8-access ("D"."LOCATION_ID"="L"."LOCATION_ID")