Oracle执行分析详细(五)

2014-11-24 16:18:24 · 作者: · 浏览: 8
重点讲解)

官网对recursive calls 的解释如下:


Recursive Calls: Number of recursive calls generated at both the user and system level.


Oracle Database maintains tables used for internal processing. When it needs to change these tables, Oracle Database generates an internal SQL statement, which in turn generates a recursive call.In short, recursive calls are basically SQL performed on behalf of your SQL. So, if you had to parse the query, for example, you might have had to run some other queries to get data dictionary information. These would be recursive calls. Space management, security checks, calling PL/SQL from SQL—all incur recursive SQL calls。

IBM上面也有一篇讲解,有兴趣可以看看

http://publib.boulder.ibm.com/tividd/td/ITMD/SC23-4724-00/en_US/HTML/oraclepac510rg59.htm

总结一下:

当执行一条SQL语句时,产生的对其他SQL语句的调用,这些额外的语句称之为''recursive calls''或''recursive SQL statements''.

在IBM 的那片文档里讲了触发Recursive Call的6种情况:  

如:

(1)我们做一条insert 时,没有足够的空间来保存row记录,Oracle 通过Recursive Call 来动态的分配空间。

(2)执行DDL语句时,ORACLE总是隐含的发出一些recursive SQL语句,来修改数据字典信息,以便成功的执行该DDL语句。

(3)当Shared Pool过小,data dictionary cache 也会相应的过小,没有足够的空间存储ORACLE的系统数据字典信息时,会发生Recursive calls,这些Recursive calls会将数据字典信息从硬盘读入内存中。

(4)存储过程、触发器内如果有SQL调用的话,也会产生recursive SQL。

在这些情况中,主要是对数据字典的查询,通常发生在第一次执行时,第二次执行一般可显著降低。递归需要消耗大量的资源,如果操作复杂,很容易出现问题!

现在让我们举例说明:

[sql] view plaincopyprint
  1. SQL> select * from employees;
  2. 107 rows selected.
  3. Execution Plan
  4. ---------------------------------------------------------- Plan hash value: 1445457117
  5. -------------------------------------------------------------------------------
  6. | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------
  7. | 0 | SELECT STATEMENT | | 107 | 7276 | 3 (0)| 00:00:01 | | 1 | TABLE ACCESS FULL| EMPLOYEES | 107 | 7276 | 3 (0)| 00:00:01 |
  8. -------------------------------------------------------------------------------
  9. Statistics
  10. ---------------------------------------------------------- 1 recursive calls
  11. 0 db block gets 15 consistent gets
  12. 0 physical reads 0 redo size
  13. 9997 bytes sent via SQL*Net to client 569 bytes received via SQL*Net from client
  14. 9 SQL*Net roundtrips to/from client 0 sorts (memory)
  15. 0 sorts (disk) 107 rows processed
  16. SQL> select * from employees;
    
    107 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1445457117
    
    -------------------------------------------------------------------------------
    | Id  | Operation         | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    -------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |           |   107 |  7276 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| EMPLOYEES |   107 |  7276 |     3   (0)| 00:00:01 |
    -------------------------------------------------------------------------------
    
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
             15  consistent gets
              0  physical reads
              0  redo size
           9997  bytes sent via SQL*Net to client
            569  bytes received via SQL*Net from client
              9  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            107  rows processed
     

    让我们再执行一遍

    [sql] view plaincopyprint
    1. SQL> select * from employees;
    2. 107 rows selected.
    3. Execution Plan
    4. ---------------------------------------------------------- Plan hash value: 1445457117