如何轉儲B*Tree索引的分枝結構(轉)

zhouwf0726發表於2019-05-29

http://www.eygle.com/archives/2005/02/ecibtreeeeoaeoe.html

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索引的理解。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/756652/viewspace-242193/,如需轉載,請註明出處,否則將追究法律責任。

相關文章