Oracle SQL optimization: View Merging)

Source: Internet
Author: User

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.

  1. -- Example:
  2. SQL>SelectE. first_name, e. last_name, dept_locs_v.street_address, dept_locs_v.postal_code
  3. 2FromEmployees e,
  4. 3 (SelectD. department_id, d. department_name, l. street_address, l. postal_code
  5. 4FromSpecified ments d, locations l
  6. 5WhereD. location_id = l. location_id) dept_locs_v
  7. 6WhereDept_locs_v.department_id = e. department_id
  8. 7AndE. last_name ='Smith';
  9. Execution Plan
  10. ----------------------------------------------------------
  11. Plan hash value: 994428606
  12. Bytes ---------------------------------------------------------------------------------------------
  13. | Id | Operation |Name|Rows| Bytes | Cost (% CPU) |Time|
  14. Bytes ---------------------------------------------------------------------------------------------
  15. | 0 |SELECTSTATEMENT | 1 | 56 | 4 (0) | 00:00:01 |
  16. | 1 | nested loops | 1 | 56 | 4 (0) | 00:00:01 |
  17. | 2 | nested loops | 1 | 25 | 3 (0) | 00:00:01 |
  18. | 3 |TABLEACCESSBY INDEXROWID | EMPLOYEES | 1 | 18 | 2 (0) | 00:00:01 |
  19. | * 4 |INDEXRange scan | EMP_NAME_IX | 1 | 1 (0) | 00:00:01 |
  20. | 5 |TABLEACCESSBY INDEXROWID | ments | 1 | 7 | 1 (0) | 00:00:01 |
  21. | * 6 |INDEX UNIQUESCAN | DEPT_ID_PK | 1 | 0 (0) | 00:00:01 |
  22. | 7 |TABLEACCESSBY INDEXROWID | LOCATIONS | 1 | 31 | 1 (0) | 00:00:01 |
  23. | * 8 |INDEX UNIQUESCAN | LOC_ID_PK | 1 | 0 (0) | 00:00:01 |
  24. Bytes ---------------------------------------------------------------------------------------------
  25. Predicate Information (identifiedByOperation id ):
  26. ---------------------------------------------------
  27. 4-access ("E"."LAST_NAME"='Smith')
  28. 6-access ("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
  29. 8-access ("D"."LOCATION_ID"="L"."LOCATION_ID")
  30. -- Use no_merge to disable view Merging
  31. SQL>Select/* + No_merge (dept_locs_v) */e. first_name, e. last_name, dept_locs_v.street_address, dept_locs_v.postal_code
  32. 2FromEmployees e,
  33. 3 (SelectD. department_id, d. department_name, l. street_address, l. postal_code
  34. 4FromSpecified ments d, locations l
  35. 5WhereD. location_id = l. location_id) dept_locs_v
  36. 6WhereDept_locs_v.department_id = e. department_id
  37. 7AndE. last_name ='Smith';
  38. Execution Plan
  39. ----------------------------------------------------------
  40. Plan hash value: 842533999
  41. Bytes --------------------------------------------------------------------------------------------------
  42. | Id | Operation |Name|Rows| Bytes | Cost (% CPU) |Time|
  43. Bytes --------------------------------------------------------------------------------------------------
  44. | 0 |SELECTSTATEMENT | 1 | 61 | 7 (15) | 00:00:01 |
  45. | * 1 | HASHJOIN| 1 | 61 | 7 (15) | 00:00:01 |
  46. | 2 |TABLEACCESSBY INDEXROWID | EMPLOYEES | 1 | 18 | 2 (0) | 00:00:01 |
  47. | * 3 |INDEXRange scan | EMP_NAME_IX | 1 | 1 (0) | 00:00:01 |
  48. | 4 |VIEW| 27 | 1161 | 4 (0) | 00:00:01 |
  49. | 5 |TABLEACCESSBY INDEXROWID | ments | 1 | 7 | 1 (0) | 00:00:01 |
  50. | 6 | nested loops | 27 | 1026 | 4 (0) | 00:00:01 |
  51. | 7 |TABLEACCESSFULL| LOCATIONS | 23 | 713 | 3 (0) | 00:00:01 |
  52. | * 8 |INDEXRange scan | DEPT_LOCATION_IX | 4 | 0 (0) | 00:00:01 |
  53. Bytes --------------------------------------------------------------------------------------------------
  54. Predicate Information (identifiedByOperation id ):
  55. ---------------------------------------------------
  56. 1-access ("DEPT_LOCS_V"."DEPARTMENT_ID"="E"."DEPARTMENT_ID")
  57. 3-access ("E"."LAST_NAME"='Smith')
  58. 8-access ("D"."LOCATION_ID"="L"."LOCATION_ID")
  • 1
  • 2
  • 3
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.