HelloDBA [中文]
Search Internet Search HelloDBA
  Oracle Technology Site. email: fuyuncat@gmail.com  MSN: fuyuncat@hotmail.com Add to circle  acoug  acoug 

Query Execution Call Stack Trace

[中文]

Author:  fuyuncat

Source:  www.HelloDBA.com

Date:  2010-05-12 09:54:07

Share to  Twitter Facebook GMail Blogger Orkut Google Bookmarks Sina Weibo QQ Renren Tieba Kaixin Douban Taobao

    As we know, an execution plan decides the functions that access data / generate row source / process row sources. With tracing the call stacks, we can find the internal funcions mapping to execution plan operations.
 

    First, with a simple sql that have full table scan on a small table.

SQL代码
  1. HELLODBA.COM>select owner, table_name from demo.T_TEST2 t where table_name like 'T%';   
  2.   
  3. OWNER                          TABLE_NAME   
  4. ------------------------------ ------------------------------   
  5. SYS                            TS$   
  6. SYS                            TSQ$   
  7. SYS                            TYPE_MISC$   
  8. SYS                            TAB$   
  9. SYS                            TYPED_VIEW$   
  10. SYS                            TRIGGER$   
  11. SYS                            TRIGGERCOL$   
  12. SYS                            TRIGGERJAVAF$   
  13. SYS                            TRIGGERJAVAS$   
  14. SYS                            TRIGGERJAVAC$   
  15. SYS                            TRIGGERJAVAM$   
  16. SYS                            TRUSTED_LIST$   
  17. SYS                            TYPE$   
  18. SYS                            TYPEHIERARCHY$   
  19. SYS                            TABPART$   
  20. SYS                            TABSUBPART$   
  21. SYS                            TABCOMPART$   
  22. SYS                            TABLE_PRIVILEGE_MAP   
  23. SYS                            TAB_STATS$   
  24. SYS                            TSM_SRC$   
  25. SYS                            TSM_DST$   
  26. SYS                            TRANSFORMATIONS$   
  27.   
  28. 22 rows selected.   
  29.   
  30.   
  31. Execution Plan   
  32. ----------------------------------------------------------   
  33. Plan hash value: 1680898452   
  34.   
  35. -----------------------------------------------------------------------------   
  36. | Id  | Operation         | Name    | Rows  | Bytes | Cost (%CPU)| Time     |   
  37. -----------------------------------------------------------------------------   
  38. |   0 | SELECT STATEMENT  |         |    51 |  1275 |    13   (0)| 00:00:01 |   
  39. |*  1 |  TABLE ACCESS FULL| T_TEST2 |    51 |  1275 |    13   (0)| 00:00:01 |   
  40. -----------------------------------------------------------------------------   
  41.   
  42. Predicate Information (identified by operation id):   
  43. ---------------------------------------------------   
  44.   
  45.    1 - filter("TABLE_NAME" LIKE 'T%')   

    With the trace, it's not hard to find the funcion map to TABLE ACCESS FULL is qertbFetch. The calls number of the funcion correspond to the fetchs number. Except the first row, the limitation of the fetch size is decided by the array_size set in client. For SQL*Plus, default is 15. Take previous case, the fetchs number = 1 + ceil((22-1)/15) = 3. And we can noted there are 3 qertbFetch be traced in the trace file.
 

SQL代码
  1. (qertbFetch) fetch first row   
  2. FETCH #2:c=1000,e=88060877,p=0,cr=4,cu=0,mis=0,r=1,dep=0,og=1,tim=1243700271288837   
  3. (qertbRelease)   
  4.   
  5. (qertbFetch) fetch 15 (array sizerows  
  6. FETCH #2:c=6999,e=191651765,p=0,cr=4,cu=0,mis=0,r=15,dep=0,og=1,tim=1243700463636714   
  7. (qertbRelease)   
  8.   
  9. (qertbFetch) fetch next array (final 6 rows)   
  10. FETCH #2:c=2000,e=99456246,p=0,cr=43,cu=0,mis=0,r=6,dep=0,og=1,tim=1243700598805788   
  11. (qertbClose)  

    Then, trace another execution with index scan.

SQL代码
  1. HELLODBA.COM>select object_id, object_name, status from demo.t_test1 where owner='DEMO';   
  2.   
  3.  OBJECT_ID OBJECT_NAME                                               STATUS    
  4. ---------- --------------------------------------------------------- ------------   
  5.      53085 BIN$hftukXrySqHgQAB/AQBHcw==$0                            VALID     
  6.      53333 T_TEST1                                                   VALID     
  7.      53086 T_TEST2                                                   VALID     
  8.      53320 T_TEST2_IDX1                                              VALID     
  9.   
  10.   
  11. Execution Plan   
  12. ----------------------------------------------------------   
  13. Plan hash value: 211562518   
  14.   
  15. -------------------------------------------------------------------------------------------   
  16. | Id  | Operation                   | Name        | Rows  | Bytes | Cost (%CPU)| Time     |   
  17. -------------------------------------------------------------------------------------------   
  18. |   0 | SELECT STATEMENT            |             |     4 |   152 |     5   (0)| 00:00:01 |   
  19. |   1 |  TABLE ACCESS BY INDEX ROWID| T_TEST1     |     4 |   152 |     5   (0)| 00:00:01 | ==> qertbFetchByRowID   
  20. |*  2 |   INDEX RANGE SCAN          | T_TEST1_UK1 |     4 |       |     2   (0)| 00:00:01 | ==> qerixtFetch    
  21. -------------------------------------------------------------------------------------------   
  22.   
  23. Predicate Information (identified by operation id):   
  24. ---------------------------------------------------   
  25.   
  26.    2 - access("OWNER"='DEMO')  

    The found function of TABLE ACCESS BY INDEX ROWID is qertbFetchByRowID, and the one of INDEX RANGE SCAN is qerixtFetch. The fetchs number decided the qertbFetchByRowID calls number. And rows number in indexes to be accessed decided the qerixtFetch calls number, with an additional call to decide the ending.

SQL代码
  1. (qertbFetchByRowID)   
  2. (qerixtFetch)   
  3. FETCH #1:c=2000,e=42017935,p=3,cr=3,cu=0,mis=0,r=1,dep=0,og=1,tim=1243777053415112   
  4. (qertbRelease)   
  5. (qerixRelease)   
  6.   
  7. (qertbFetchByRowID)   
  8. (qerixtFetch)   
  9. (qerixtFetch)   
  10. (qerixtFetch)   
  11. FETCH #1:c=2000,e=91247424,p=2,cr=4,cu=0,mis=0,r=3,dep=0,og=1,tim=1243777172136097   
  12. (qerixtFetch)   
  13. (qertbClose)   
  14. (qerixClose)  

    Note: once call qertbRelease, the resouces loaded by qertbFetch are released, including the buffer cache. So, even thougth some buffer block read in previous fetch, it will still cause new logic io in the next fetch. In another work, the fetch array size decided the execution plan go through times.

   With more traces, we can also find the funcions of JOIN and other operations:
 

  • (NESTED LOOPS / MERGE) JOIN  ==> qerjotFetch;
  • HASH JOIN ==> qerhjFetch
  • SORT ==> qersoFetch
    ...

--- Fuyuncat ---

Top

Copyright ©2005, HelloDBA.Com All reseverd.

Declaration
by fuyuncat