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

Look Oracle from inside (tracing internal calls) --- Logical IOs

[中文]

Author:  fuyuncat

Source:  www.HelloDBA.com

Date:  2010-06-10 05:43:58

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

    WARNING: Never play OraTracer in any crytical system! 

Logical IOs

    For logical IO, it contains 2 kinds of figure: db block gets and consistent gets. We can get the figure by turning on AUTOTRACE before execute a SQL. Sometimes, we may not content with this statistics data, we want to know which blocks did the sql read exactly. Now, by tracing the db block gets and consistent gets internal functions, _kcbgcur&_kcbgtcr, we can get the details. Take below simple UPDATE statement as an example.

SQL代码
  1. HELLODBA.COM>update demo.tt set x=111 where x=1;   
  2.   
  3. rows updated.   
  4.   
  5.   
  6. Execution Plan   
  7. ----------------------------------------------------------   
  8. Plan hash value: 3408939625   
  9.   
  10. ---------------------------------------------------------------------------   
  11. | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |   
  12. ---------------------------------------------------------------------------   
  13. |   0 | UPDATE STATEMENT   |      |     2 |     6 |     2   (0)| 00:00:03 |   
  14. |   1 |  UPDATE            | TT   |       |       |            |          |   
  15. |*  2 |   TABLE ACCESS FULL| TT   |     2 |     6 |     2   (0)| 00:00:03 |   
  16. ---------------------------------------------------------------------------   
  17.   
  18. Predicate Information (identified by operation id):   
  19. ---------------------------------------------------   
  20.   
  21.    2 - filter("X"=1)   
  22.   
  23.   
  24. Statistics  
  25. ----------------------------------------------------------   
  26.           0  recursive calls   
  27.           3  db block gets   
  28.           7  consistent gets   
  29.           0  physical reads   
  30.         744  redo size  
  31.         677  bytes sent via SQL*Net to client   
  32.         570  bytes received via SQL*Net from client   
  33.           4  SQL*Net roundtrips to/from client   
  34.           1  sorts (memory)   
  35.           0  sorts (disk)   
  36.           2  rows processed   
  37.   
  38. HELLODBA.COM>rollback;   
  39.   
  40. Rollback complete.   
  41.   
  42. HELLODBA.COM>set autot off  
  43. HELLODBA.COM>select distinct spid from v$mystat m, v$session s, v$process p where m.sid=s.sid and s.paddr=p.addr;   
  44.   
  45. SPID   
  46. ------------   
  47. 9800  

    Set the trace points as below.

SQL代码
  1. _kcbgcur (8*1,0*2,0*2,0*2,0*2,0*2)   
  2. _kcbgtcr (8*1,0*2,0*2,0*2)  

    Run OraTracer, trace the thread with TID 9800. Then execute the SQL in the session, we will get the trace log as below.

SQL代码
  1. [2010-06-09 14:27:55.528]User call: _kcbgtcr (TID: 9800)    
  2.     [Args(4)]:    
  3.         0x799c5c4(=>0x050000004be64001)   
  4.         0   
  5.         0x1bc(=>NULL)   
  6.         0   
  7. [2010-06-09 14:27:55.528]User call: _kcbgtcr (TID: 9800)    
  8.     [Args(4)]:    
  9.         0x799c3d8(=>0x050000004be64001)   
  10.         0   
  11.         0x1bd(=>NULL)   
  12.         0   
  13. [2010-06-09 14:27:55.528]User call: _kcbgtcr (TID: 9800)    
  14.     [Args(4)]:    
  15.         0x839a5bc(=>0x050000004ce64001)   
  16.         0   
  17.         0x23f(=>NULL)   
  18.         0   
  19. [2010-06-09 14:27:55.543]User call: _kcbgtcr (TID: 9800)    
  20.     [Args(4)]:    
  21.         0x839a5bc(=>0x050000004de64001)   
  22.         0   
  23.         0x23f(=>NULL)   
  24.         0   
  25. [2010-06-09 14:27:55.559]User call: _kcbgtcr (TID: 9800)    
  26.     [Args(4)]:    
  27.         0x839a5bc(=>0x050000004ee64001)   
  28.         0   
  29.         0x23f(=>NULL)   
  30.         0   
  31. [2010-06-09 14:27:55.575]User call: _kcbgtcr (TID: 9800)    
  32.     [Args(4)]:    
  33.         0x839a5bc(=>0x050000004fe64001)   
  34.         0   
  35.         0x23f(=>NULL)   
  36.         0   
  37. [2010-06-09 14:27:55.590]User call: _kcbgcur (TID: 9800)    
  38.     [Args(6)]:    
  39.         0x839abf8(=>0x050000004fe64001)   
  40.         2   
  41.         0x250(=>NULL)   
  42.         0   
  43.         0x310ef(=>NULL)   
  44.         0x839abb4(=>0x1ab26c3c(=>0x1a90fba8))   
  45. [2010-06-09 14:27:55.590]User call: _kcbgcur (TID: 9800)    
  46.     [Args(6)]:    
  47.         0x7995d88(=>0x0100000099008000)   
  48.         2   
  49.         0x17b(=>NULL)   
  50.         0   
  51.         0x1010010(=>0x89cc4d8b(=>NULL))   
  52.         0x7995d88(=>1)   
  53. [2010-06-09 14:27:55.606]User call: _kcbgtcr (TID: 9800)    
  54.     [Args(4)]:    
  55.         0x839a5bc(=>0x0500000050e64001)   
  56.         0   
  57.         0x23f(=>NULL)   
  58.         0   
  59. [2010-06-09 14:27:55.621]User call: _kcbgcur (TID: 9800)    
  60.     [Args(6)]:    
  61.         0x839abf8(=>0x0500000050e64001)   
  62.         2   
  63.         0x250(=>NULL)   
  64.         0   
  65.         0x310ef(=>NULL)   
  66.         0x839abb4(=>0x1ab26c3c(=>0x1a90fba8))  

    Count the funcation calls, we get 7 _kcbgtcr calls and 3 _kcbgcur calls, which matched the statistics data. An interesting argument of these 2 functions is the 1st one, which contains the data block address (DBA) infomation. You may compare the actual DBA as below.

SQL代码
  1. HELLODBA.COM>select x, to_char(dbms_utility.make_data_block_address(dbms_rowid.rowid_relative_fno(rowid), dbms_rowid.rowid_block_number(rowid)), 'XXXXXXXX') DBA from demo.tt;   
  2.   
  3.          X DBA   
  4. ---------- ---------   
  5.          8   140E64C   
  6.        101   140E64D   
  7.        101   140E64D   
  8.         11   140E64D   
  9.          1   140E64F   
  10.          1   140E650   
  11.          2   140E650   
  12.          3   140E650   
  13.   
  14. rows selected.  

    Two interesting consistent gets are the 1st & 2nd ones. With their DBA, it's not hard to get that it read the segment header block twice.

SQL代码
  1. HELLODBA.COM>select to_char(header_file, 'XXXXXXXX') file_no, to_char(header_block, 'XXXXXXXX') block_no from dba_segments where owner='DEMO' and segment_name = 'TT';   
  2.   
  3. FILE_NO   BLOCK_NO   
  4. --------- ---------   
  5.         5      E64B  

    Another interesting consistent get is the 5th one. Check the table data, we found it actually does not contain any row. However, since it's a Full Table Scan, the data block under High Water Mark were scaned.
    Therefore, we got 7 consistent gets: 2 segment header block reads, 5 data blocks under High Water Mark.

    For db block gets. Since the rows we updated locate at 2 data blocks, they were read in current mode. For the left one, by dumping the data block, we will find it's actuall the Undo Segment Header block.

SQL代码
  1. HELLODBA.COM>select dbms_utility.data_block_address_file(to_number('00800099''XXXXXXXX')) file_no, dbms_utility.data_block_address_block(to_number('00800099''XXXXXXXX')) block_no from dual;   
  2.   
  3.    FILE_NO   BLOCK_NO   
  4. ---------- ----------   
  5.          2        153   
  6.   
  7. HELLODBA.COM>alter system dump datafile 2 block 153;   
  8.   
  9. System altered.  

    The dumped data block contents.

SQL代码
  1. Start dump data blocks tsn: 1 file#: 2 minblk 153 maxblk 153   
  2. buffer tsn: 1 rdba: 0x00800099 (2/153)   
  3. scn: 0x0000.ec8f0f54 seq: 0x01 flg: 0x04 tail: 0x0f542601   
  4. frmt: 0x02 chkval: 0x71d4 type: 0x26=KTU SMU HEADER BLOCK   
  5. Hex dump of block: st=0, typ_found=1   
  6. ...  

    You can download the OraTracer at here:
    http://www.HelloDBA.com/Download/OraTracer.zip

    --- Fuyuncat ---

Top

Copyright ©2005, HelloDBA.Com All reseverd.

Declaration
by fuyuncat