Advertisement
ExaGridDba

Self join elimination in 11.2, and a hint that does not work

Jul 1st, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BY: Brian Fitzgerald
  2.  
  3.  
  4. [oracle@waipio1 wailua20 optimizer]$ sqlplus oe/oe @ self.join.elimination.SQL
  5.  
  6. SQL*Plus: RELEASE 12.1.0.1.0 Production ON Wed Jul 2 00:38:38 2014
  7.  
  8. Copyright (c) 1982, 2013, Oracle.  ALL rights reserved.
  9.  
  10. LAST SUCCESSFUL login TIME: Wed Jul 02 2014 00:37:57 -04:00
  11.  
  12. Connected TO:
  13. Oracle DATABASE 12c Enterprise Edition RELEASE 12.1.0.1.0 - 64bit Production
  14. WITH the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
  15. AND REAL Application Testing options
  16.  
  17. SQL> ALTER SESSION SET optimizer_features_enable = '11.1.0.7';
  18.  
  19. SESSION altered.
  20.  
  21. SQL> SET termout off
  22. SQL> SELECT * FROM TABLE( dbms_xplan.display_cursor(NULL, NULL, 'projection') );
  23.  
  24. PLAN_TABLE_OUTPUT
  25. ------------------------------------------------------------------------------------------------------------------------
  26. SQL_ID  8hynqpxakhr75, child NUMBER 0
  27. -------------------------------------
  28. SELECT s2.order_id, s1.order_mode, s2.order_mode FROM orders s1 join
  29. orders s2 ON s1.order_id = s2.order_id
  30.  
  31. PLAN hash VALUE: 915117078
  32.  
  33. -----------------------------------------------------------------------------------------
  34. | Id  | Operation                    | Name     | ROWS  | Bytes | COST (%CPU)| TIME     |
  35. -----------------------------------------------------------------------------------------
  36. |   0 | SELECT STATEMENT             |          |       |       |     7 (100)|          |
  37. |   1 |  MERGE JOIN                  |          |   105 |  2310 |     7  (15)| 00:00:01 |
  38. |   2 |   TABLE ACCESS BY INDEX ROWID| ORDERS   |   105 |  1155 |     2   (0)| 00:00:01 |
  39. |   3 |    INDEX FULL SCAN           | ORDER_PK |   105 |       |     1   (0)| 00:00:01 |
  40. |*  4 |   SORT JOIN                  |          |   105 |  1155 |     5  (20)| 00:00:01 |
  41. |   5 |    TABLE ACCESS FULL         | ORDERS   |   105 |  1155 |     4   (0)| 00:00:01 |
  42. -----------------------------------------------------------------------------------------
  43.  
  44. Predicate Information (IDENTIFIED BY operation id):
  45. ---------------------------------------------------
  46.  
  47.    4 - ACCESS("S1"."ORDER_ID"="S2"."ORDER_ID")
  48.        filter("S1"."ORDER_ID"="S2"."ORDER_ID")
  49.  
  50. COLUMN Projection Information (IDENTIFIED BY operation id):
  51. -----------------------------------------------------------
  52.  
  53.    1 - "S2"."ORDER_ID"[NUMBER,22], "S1"."ORDER_MODE"[VARCHAR2,8],
  54.        "S2"."ORDER_MODE"[VARCHAR2,8]
  55.    2 - "S1"."ORDER_ID"[NUMBER,22], "S1"."ORDER_MODE"[VARCHAR2,8]
  56.    3 - "S1".ROWID[ROWID,10], "S1"."ORDER_ID"[NUMBER,22]
  57.    4 - (#keys=1) "S2"."ORDER_ID"[NUMBER,22], "S2"."ORDER_MODE"[VARCHAR2,8]
  58.    5 - "S2"."ORDER_ID"[NUMBER,22], "S2"."ORDER_MODE"[VARCHAR2,8]
  59.  
  60.  
  61. 34 ROWS selected.
  62.  
  63. SQL>
  64. SQL> ALTER SESSION SET optimizer_features_enable = '11.2.0.1';
  65.  
  66. SESSION altered.
  67.  
  68. SQL> SET termout off
  69. SQL> SELECT * FROM TABLE( dbms_xplan.display_cursor(NULL, NULL, 'projection') );
  70.  
  71. PLAN_TABLE_OUTPUT
  72. ------------------------------------------------------------------------------------------------------------------------
  73. SQL_ID  8hynqpxakhr75, child NUMBER 1
  74. -------------------------------------
  75. SELECT s2.order_id, s1.order_mode, s2.order_mode FROM orders s1 join
  76. orders s2 ON s1.order_id = s2.order_id
  77.  
  78. PLAN hash VALUE: 1275100350
  79.  
  80. ----------------------------------------------------------------------------
  81. | Id  | Operation         | Name   | ROWS  | Bytes | COST (%CPU)| TIME     |
  82. ----------------------------------------------------------------------------
  83. |   0 | SELECT STATEMENT  |        |       |       |     4 (100)|          |
  84. |   1 |  TABLE ACCESS FULL| ORDERS |   105 |  1155 |     4   (0)| 00:00:01 |
  85. ----------------------------------------------------------------------------
  86.  
  87. COLUMN Projection Information (IDENTIFIED BY operation id):
  88. -----------------------------------------------------------
  89.  
  90.    1 - "S1"."ORDER_ID"[NUMBER,22], "ORDER_MODE"[VARCHAR2,8]
  91.  
  92.  
  93. 19 ROWS selected.
  94.  
  95. SQL>
  96. SQL> -- a hint that is not working
  97. SQL> SET termout off
  98. SQL> SELECT * FROM TABLE( dbms_xplan.display_cursor(NULL, NULL, 'projection') );
  99.  
  100. PLAN_TABLE_OUTPUT
  101. ------------------------------------------------------------------------------------------------------------------------
  102. SQL_ID  596y43af1t1xh, child NUMBER 0
  103. -------------------------------------
  104. SELECT /*+ NO_ELIMINATE_JOIN */ s2.order_id, s1.order_mode,
  105. s2.order_mode FROM orders s1 join orders s2 ON s1.order_id = s2.order_id
  106.  
  107. PLAN hash VALUE: 1275100350
  108.  
  109. ----------------------------------------------------------------------------
  110. | Id  | Operation         | Name   | ROWS  | Bytes | COST (%CPU)| TIME     |
  111. ----------------------------------------------------------------------------
  112. |   0 | SELECT STATEMENT  |        |       |       |     4 (100)|          |
  113. |   1 |  TABLE ACCESS FULL| ORDERS |   105 |  1155 |     4   (0)| 00:00:01 |
  114. ----------------------------------------------------------------------------
  115.  
  116. COLUMN Projection Information (IDENTIFIED BY operation id):
  117. -----------------------------------------------------------
  118.  
  119.    1 - "S1"."ORDER_ID"[NUMBER,22], "ORDER_MODE"[VARCHAR2,8]
  120.  
  121.  
  122. 19 ROWS selected.
  123.  
  124. SQL>
  125. SQL>
  126. SQL> quit
  127. Disconnected FROM Oracle DATABASE 12c Enterprise Edition RELEASE 12.1.0.1.0 - 64bit Production
  128. WITH the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
  129. AND REAL Application Testing options
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement