Fixed execution plan using Oracle SQL profile

Source: Internet
Author: User

Experiment with SQL profile fixed execution plan

Oracle has outlines before 10 Gb, and SQL profile after 10 Gb is one of the new features.

Outlines is insufficient for SQL statements that are not bound to variables.

The following is the experiment process.

  1. -- 1. preparation stage
  2. SQL> select * from v $ version;
  3. BANNER
  4. ----------------------------------------------------------------
  5. Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Prod
  6. PL/SQL Release 10.2.0.1.0-Production
  7. CORE 10.2.0.1.0 Production
  8. TNS for 32-bit Windows: Version 10.2.0.1.0-Production
  9. NLSRTL Version 10.2.0.1.0-Production
  10. SQL> createtable test_raugher asselect * from dba_objects;
  11. The table has been created.
  12. SQL> createindex ind_objectid on test_raugher (object_id );
  13. The index has been created.
  14. SQL> select object_id from test_raugher where rownum <2;
  15. OBJECT_ID
  16. ----------
  17. 20
  18. SQL> exec dbms_stats.gather_table_stats (user, 'test _ RAUGHER ', cascade => true );
  19. The PL/SQL process is successfully completed.
  20. -- Original SQL Execution Plan
  21. SQL> set autot trace explain
  22. SQL> select * from test_raugher where object_id = 20;
  23. Execution Plan
  24. ----------------------------------------------------------
  25. Plan hash value: 800879874
  26. Bytes --------------------------------------------------------------------------------------------
  27. | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
  28. Bytes --------------------------------------------------------------------------------------------
  29. | 0 | select statement | 1 | 95 | 2 (0) | 00:00:01 |
  30. | 1 | table access byindex rowid | TEST_RAUGHER | 1 | 95 | 2 (0) | 00:00:01 |
  31. | * 2 | index range scan | IND_OBJECTID | 1 | 1 (0) | 00:00:01 |
  32. Bytes --------------------------------------------------------------------------------------------
  33. Predicate Information (identified by operation id ):
  34. ---------------------------------------------------
  35. 2-access ("OBJECT_ID" = 20)
  36. SQL>
  37. -- New SQL Execution Plan
  38. SQL> select/* + full (test_raugher) */* from test_raugher where object_id = 20;
  39. Execution Plan
  40. ----------------------------------------------------------
  41. Plan hash value: 3725671026
  42. ----------------------------------------------------------------------------------
  43. | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
  44. ----------------------------------------------------------------------------------
  45. | 0 | select statement | 1 | 95 | 166 (2) | 00:00:02 |
  46. | * 1 | table access full | TEST_RAUGHER | 1 | 95 | 166 (2) | 00:00:02 |
  47. ----------------------------------------------------------------------------------
  48. Predicate Information (identified by operation id ):
  49. ---------------------------------------------------
  50. 1-filter ("OBJECT_ID" = 20)
  51. -- 2. Obtain the SQL _id of the new SQL statement.
  52. SQL> col SQL _id for a20
  53. SQL> col SQL _text for a100
  54. SQL> select SQL _id, SQL _text from v $ SQL where SQL _text like '% full (test_raugher) % ';
  55. SQL _ID SQL _TEXT
  56. -------------------- Success ------------------------------------------------------------------------------------------------------------------------
  57. 5nkhk1_705z3 select SQL _id, SQL _text from v $ SQL where SQL _text like '% full (test_raugher) %'
  58. G23hbdmcsdahc select/* + full (test_raugher) */* from test_raugher where object_id = 20
  59. Dqp79vx5pmw0k explain plan set STATEMENT_ID = 'plus4294967295 'FORselect/* + full (test_raugher) */* from test_raug
  60. Her where object_id = 20
  61. -- 3. Obtain the outline of the new SQL statement
  62. SQL> set pagesize 1000
  63. SQL> select * fromtable (dbms_xplan.display_cursor ('g23hbdmcsdahc ', null, 'outline '));
  64. PLAN_TABLE_OUTPUT
  65. Bytes -----------------------------------------------------------------------------------------------
  66. Bytes -----------------------------------------------------------------------------------------------
  67. SQL _ID g23hbdmcsdahc, child number 0
  68. -------------------------------------
  69. Select/* + full (test_raugher) */* from test_raugher where object_id = 20
  70. Plan hash value: 3725671026
  71. ----------------------------------------------------------------------------------
  72. | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
  73. ----------------------------------------------------------------------------------
  74. | 0 | select statement | 166 (100) |
  75. | * 1 | table access full | TEST_RAUGHER | 1 | 95 | 166 (2) | 00:00:02 |
  76. ----------------------------------------------------------------------------------
  77. Outline Data
  78. -------------
  79. /* +
  80. BEGIN_OUTLINE_DATA
  81. IGNORE_OPTIM_EMBEDDED_HINTS
  82. OPTIMIZER_FEATURES_ENABLE ('10. 2.0.1 ')
  83. ALL_ROWS
  84. OUTLINE_LEAF (@ "SEL $1 ")
  85. FULL (@ "SEL $1" "TEST_RAUGHER" @ "SEL $1 ")
  86. END_OUTLINE_DATA
  87. */
  88. Predicate Information (identified by operation id ):
  89. ---------------------------------------------------
  90. 1-filter ("OBJECT_ID" = 20)
  91. 31 rows have been selected.
  92. -- 4. Create an SQL profile (SQLPROFILE_001)
  93. SQL> declare
  94. 2 v_hints sys. sqlprof_attr;
  95. 3 begin
  96. 4 v_hints: = sys. sqlprof_attr (
  97. 5 'begin_outline_data ',
  98. 6 'ignore _ OPTIM_EMBEDDED_HINTS ',
  99. 7 'optimizer _ FEATURES_ENABLE (''10. 2.0.1 '')',
  100. 8 'all _ ROWS ',
  101. 9 'outline _ LEAF (@ "SEL $1 ")',
  102. 10 'full (@ "SEL $1" "TEST_RAUGHER" @ "SEL $1 ")',
  103. 11 'end _ OUTLINE_DATA ');
  104. 12 dbms_sqltune.import_ SQL _profile (
  105. 13 'select * from test_raugher where object_id = 20 ',
  106. 14 v_hints, 'sqlprofile _ 001 ',
  107. 15 force_match => true, replace => false );
  108. 16 end;
  109. 17/
  110. The PL/SQL process is successfully completed.
  111. -- 5. Check whether SQL profile is used
  112. SQL> set autot trace explain
  113. SQL> select * from test_raugher where object_id = 20;
  114. Execution Plan
  115. ----------------------------------------------------------
  116. Plan hash value: 3725671026
  117. ----------------------------------------------------------------------------------
  118. | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
  119. ----------------------------------------------------------------------------------
  120. | 0 | select statement | 1 | 95 | 166 (2) | 00:00:02 |
  121. | * 1 | table access full | TEST_RAUGHER | 1 | 95 | 166 (2) | 00:00:02 |
  122. ----------------------------------------------------------------------------------
  123. Predicate Information (identified by operation id ):
  124. ---------------------------------------------------
  125. 1-filter ("OBJECT_ID" = 20)
  126. Note
  127. -----
  128. -SQL profile "SQLPROFILE_001" used for this statement
  129. SQL> select * from test_raugher where object_id = 200;
  130. Execution Plan
  131. ----------------------------------------------------------
  132. Plan hash value: 3725671026
  133. ----------------------------------------------------------------------------------
  134. | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
  135. ----------------------------------------------------------------------------------
  136. | 0 | select statement | 1 | 95 | 166 (2) | 00:00:02 |
  137. | * 1 | table access full | TEST_RAUGHER | 1 | 95 | 166 (2) | 00:00:02 |
  138. ----------------------------------------------------------------------------------
  139. Predicate Information (identified by operation id ):
  140. ---------------------------------------------------
  141. 1-filter ("OBJECT_ID" = 200)
  142. Note
  143. -----
  144. -SQL profile "SQLPROFILE_001" used for this statement
  • 1
  • 2
  • 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.