如何转储B*Tree索引的分枝结构

2/9/2008来源:Oracle教程人气:6296


  Oracle答应对B*Tree索引进行转储,以显示B*Tree的层次结构。
  
  示例如下:
  
  1.首先选择要研究的索引
  
  SQL> select index_name from user_indexes where index_name='I_BD_INVMANDOC_TS';
  
  INDEX_NAME
  ------------------------------
  I_BD_INVMANDOC_TS
  
  2.找到该索引的object_id
  
  SQL> select object_id from dba_objects where object_name='I_BD_INVMANDOC_TS';
  
  OBJECT_ID
  ----------
  6393
  
  3.转储该索引结构
  
  SQL> ALTER session SET EVENTS 'immediate trace name TREEDUMP level 6393';
  
  Session altered.
  
  4.现在是trace文件中的片断
  
  我们可以看到该索引共有三个层次,每个leaf上大约有341条记录.
  
  *** 2005-02-26 10:52:11.458
  ----- begin tree dump
  branch: 0x1403d9c 20987292 (0: nrow: 5, level: 2)
  branch: 0x1403f07 20987655 (-1: nrow: 351, level: 1)
  leaf: 0x1403d9d 20987293 (-1: nrow: 341 rrow: 341)
  leaf: 0x1403d9e 20987294 (0: nrow: 341 rrow: 341)
  leaf: 0x1403d9f 20987295 (1: nrow: 341 rrow: 341)
  ......
  leaf: 0x1403f00 20987648 (344: nrow: 341 rrow: 341)
  leaf: 0x1403f01 20987649 (345: nrow: 341 rrow: 341)
  leaf: 0x1403f02 20987650 (346: nrow: 341 rrow: 341)
  leaf: 0x1403f03 20987651 (347: nrow: 341 rrow: 341)
  leaf: 0x1403f04 20987652 (348: nrow: 341 rrow: 341)
  leaf: 0x1403f05 20987653 (349: nrow: 341 rrow: 341)
  branch: 0x140406c 20988012 (0: nrow: 350, level: 1)
  leaf: 0x1403f06 20987654 (-1: nrow: 341 rrow: 341)
  leaf: 0x1403f08 20987656 (0: nrow: 341 rrow: 341)
  leaf: 0x1403f0a 20987658 (1: nrow: 341 rrow: 341)
  leaf: 0x1403f0b 20987659 (2: nrow: 341 rrow: 341)
  leaf: 0x1403f0c 20987660 (3: nrow: 341 rrow: 341)
  leaf: 0x1403f0d 20987661 (4: nrow: 341 rrow: 341)
  ...
  leaf: 0x1404067 20988007 (345: nrow: 341 rrow: 341)
  leaf: 0x1404068 20988008 (346: nrow: 341 rrow: 341)
  leaf: 0x1404069 20988009 (347: nrow: 341 rrow: 341)
  leaf: 0x140406a 20988010 (348: nrow: 341 rrow: 341)
  branch: 0x14041d1 20988369 (1: nrow: 350, level: 1)
  leaf: 0x140406b 20988011 (-1: nrow: 341 rrow: 341)
  leaf: 0x140406d 20988013 (0: nrow: 341 rrow: 341)
  leaf: 0x140406e 20988014 (1: nrow: 341 rrow: 341)
  ...
  leaf: 0x14041ce 20988366 (347: nrow: 341 rrow: 341)
  leaf: 0x14041cf 20988367 (348: nrow: 341 rrow: 341)
  branch: 0x1404336 20988726 (2: nrow: 351, level: 1)
  leaf: 0x14041d0 20988368 (-1: nrow: 341 rrow: 341)
  leaf: 0x14041d2 20988370 (0: nrow: 341 rrow: 341)
  leaf: 0x14041d3 20988371 (1: nrow: 341 rrow: 341)
  ...
  leaf: 0x1404332 20988722 (347: nrow: 341 rrow: 341)
  leaf: 0x1404333 20988723 (348: nrow: 341 rrow: 341)
  leaf: 0x1404334 20988724 (349: nrow: 341 rrow: 341)
  branch: 0x140446f 20989039 (3: nrow: 308, level: 1)
  leaf: 0x1404335 20988725 (-1: nrow: 341 rrow: 341)
  leaf: 0x1404337 20988727 (0: nrow: 341 rrow: 341)
  leaf: 0x1404338 20988728 (1: nrow: 341 rrow: 341)
  leaf: 0x1404339 20988729 (2: nrow: 341 rrow: 341)
  ...
  leaf: 0x140446c 20989036 (304: nrow: 341 rrow: 341)
  leaf: 0x140446d 20989037 (305: nrow: 341 rrow: 341)
  leaf: 0x140446e 20989038 (306: nrow: 73 rrow: 73)
  ----- end tree dump
  
  通过这个跟踪可以清楚地看到B*Tree索引的结构,有助于加深对于B*Tree索引的理解。