如何对Oracle中Struct和Array进行Explain Plan--深入篇

上一篇文章中介绍了如何对Oracle中Struct和Array进行Explain Plan

  1. EXPLAIN PLAN FOR        
  2.   SELECT * FROM TABLE(DEPT_ARRAY(DEPARTMENT_TYPE(
  3.                                 1, --DNO NUMBER (10),
  4.                                 'NAME', --NAME VARCHAR2 (50),
  5.                                 'LOCATION' --LOCATION VARCHAR2 (50)
  6.                                 ))) T
  7.                 JOIN TABLE2 T2 ON T.DNO = T2.DNO;      
  8. SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY); 

运行出来的结果中会有这样的数据:

  1.     PLAN_TABLE_OUTPUT
  2. 1   Plan hash value: 1748000095
  3. 2    
  4. 3   ----------------------------------------------------------------------------------------------
  5. 4   | Id  | Operation                             | Name | Rows  | Bytes | Cost (%CPU)| Time     |
  6. 5   ----------------------------------------------------------------------------------------------
  7. 6   |   0 | SELECT STATEMENT                      |      |  8168 | 16336 |    24   (0)| 00:00:01 |
  8. 7   |   1 |  COLLECTION ITERATOR CONSTRUCTOR FETCH|      |       |       |            |          |
  9. 8   ----------------------------------------------------------------------------------------------

optimizer默认Array中数据行数为8168, 但是由于情景不同,放在Array中数据的行数不尽相同。使用cardinality hint来让optimizer知道Array中数据的行数。

  1. EXPLAIN PLAN FOR        
  2.   SELECT /*+ cardinality(t 10 ) */ * FROM TABLE(DEPT_ARRAY(DEPARTMENT_TYPE(
  3.                                 1, --DNO NUMBER (10),
  4.                                 'NAME', --NAME VARCHAR2 (50),
  5.                                 'LOCATION' --LOCATION VARCHAR2 (50)
  6.                                 ))) T
  7.                 JOIN TABLE2 T2 ON T.DNO = T2.DNO;      
  8. SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY); 

运行出来的结果:

  1.     PLAN_TABLE_OUTPUT
  2. 1   Plan hash value: 1748000095
  3. 2    
  4. 3   ----------------------------------------------------------------------------------------------
  5. 4   | Id  | Operation                             | Name | Rows  | Bytes | Cost (%CPU)| Time     |
  6. 5   ----------------------------------------------------------------------------------------------
  7. 6   |   0 | SELECT STATEMENT                      |      |    10 |    20 |    24   (0)| 00:00:01 |
  8. 7   |   1 |  COLLECTION ITERATOR CONSTRUCTOR FETCH|      |       |       |            |          |
  9. 8   ----------------------------------------------------------------------------------------------

数字10为Array中数据的最大行数。

 

参考:

the cardinality hint when you are using PL/SQL collections in SQL

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Oracle,struct,oracle,collections,output,table,sql)