bbed 分析索引

来源:这里教程网 时间:2026-03-03 20:59:19 作者:

分析下索引情况: 模拟数据 create table t ( a varchar2(200),b varchar2(3000));  insert into t values (lpad('1',127,'1'),lpad('a',127,'a'));  1 a insert into t values (lpad('2',127,'2'),lpad('b',128,'b'));  2 b insert into t values (lpad('3',127,'3'),lpad('c',1000,'c')); 3 c commit; create index i_t_a_b on t(a,b); exec dbms_stats.gather_table_stats(ownname=>user, tabname=>'t', estimate_percent=>null, method_opt=>'FOR ALL COLUMNS SIZE 1');  select segment_name,header_file,header_block,BLOCKS from dba_segments where owner=user and segment_name='I_T_A_B'; SEGMENT_NAME HEADER_FILE HEADER_BLOCK I_T_A_B    7      1930 alter system checkpoint ; alter system dump datafile 7 block 1930 ; Leaf block dump =============== header address 2095530084=0x7ce74064 kdxcolev 0 KDXCOLEV Flags = - - - kdxcolok 0 kdxcoopc 0x80: opcode=0: iot flags=--- is converted=Y kdxconco 3 kdxcosdc 0 kdxconro 3 kdxcofbo 42=0x2a kdxcofeo 6361=0x18d9 kdxcoavs 6319 kdxlespl 0 kdxlende 0 kdxlenxt 0=0x0 kdxleprv 0=0x0 kdxledsz 0 kdxlebksz 8032 row#0[7767] flag: -------, lock: 0, len=265 col 0; len 127; (127):   31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31  31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31  31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31  31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31  31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31  31 31 col 1; len 127; (127):   61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61  61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61  61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61  61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61  61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61  61 61 col 2; len 6; (6):  01 c0 07 87 00 00 row#1[7500] flag: -------, lock: 0, len=267 col 0; len 127; (127):   32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32  32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32  32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32  32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32  32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32  32 32 col 1; len 128; (128):   62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62  62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62  62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62  62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62  62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62  62 62 62 col 2; len 6; (6):  01 c0 07 87 00 01 row#2[6361] flag: -------, lock: 0, len=1139 col 0; len 127; (127):   33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33  33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33  33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33  33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33  33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33  33 33 col 1; len 1000; (1000):   63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63  63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 col 2; len 6; (6):  01 c0 07 87 00 02 bbed 查看  BBED>  set dba 7,1931 DBA            0x01c0078b (29362059 7,1931) BBED> map /v  File: /u02/app/oracle/oradata/TEST/datafile/o1_mf_users_mnj4l868_.dbf (7)  Block: 1931                                  Dba:0x01c0078b ------------------------------------------------------------  KTB Data Block (Index Leaf)  struct kcbh, 20 bytes                      @0            ub1 type_kcbh                           @0            ub1 frmt_kcbh                           @1            ub2 wrp2_kcbh                           @2            ub4 rdba_kcbh                           @4            ub4 bas_kcbh                            @8            ub2 wrp_kcbh                            @12           ub1 seq_kcbh                            @14           ub1 flg_kcbh                            @15           ub2 chkval_kcbh                         @16           ub2 spare3_kcbh                         @18        struct ktbbh, 72 bytes                     @20           ub1 ktbbhtyp                            @20           union ktbbhsid, 4 bytes                 @24           struct ktbbhcsc, 8 bytes                @28           sb2 ktbbhict                            @36           ub1 ktbbhflg                            @38           ub1 ktbbhfsl                            @39           ub4 ktbbhfnx                            @40           struct ktbbhitl[2], 48 bytes            @44        struct kdxle, 32 bytes                     @100          struct kdxlexco, 16 bytes               @100          sb2 kdxlespl                            @116          sb2 kdxlende                            @118          ub4 kdxlenxt                            @120          ub4 kdxleprv                            @124          ub1 kdxledsz                            @128          ub1 kdxleflg                            @129       sb2 kd_off[3]                              @132       ub1 freespace[6319]                        @138       ub1 rowdata[1671]                          @6457      ub4 tailchk                                @8188     查看 row =2 的行起始位置 BBED> p *kd_off[2] rowdata[1410] ------------- ub1 rowdata[1410]                           @7867     0x00 查看值 BBED>  x /rccx rowdata[1410]                               @7867     ------------- flag@7867:     0x00 (NONE) lock@7868:     0x00 data key: col  0[127] @7870: 1111111111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111111111111111111111 col  1[127] @7998: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa col    2[6] @8126:  0x01  0xc0  0x07  0x87  0x00  0x00  BBED> dump /v offset  7996  count 32  File: /u02/app/oracle/oradata/TEST/datafile/o1_mf_users_mnj4l868_.dbf (7)  Block: 1931    Offsets: 7996 to 8027  Dba:0x01c0078b -------------------------------------------------------  317f6161 61616161 61616161 61616161 l 1.aaaaaaaaaaaaaa  61616161 61616161 61616161 61616161 l aaaaaaaaaaaaaaaa  <16 bytes per line> BBED>  dump /v   File: /u02/app/oracle/oradata/TEST/datafile/o1_mf_users_mnj4l868_.dbf (7)  Block: 1931    Offsets: 7867 to 7898  Dba:0x01c0078b -------------------------------------------------------  00007f31 31313131 31313131 31313131 l ...1111111111111  31313131 31313131 31313131 31313131 l 1111111111111111 注意: bbed看索引块存在问题,实际上kd_off[0], kd_off[1]记录的偏移量不对.实际上从kd_off[2]开始. --//使用bbed查看索引kd_off结构时存在问题,前面两项指向的偏移不对,从kd_off[2]算起,而且记录的是相对偏移=绝对偏移- kdxle 偏移. --//遗漏的两项可以通过最大的kd_off项记录的地址+2 ,+4 获得. --//dump offset kd_off[max]+2 count 2 --//dump offset kd_off[max]+4 count 2 --//每次看最后两项比较麻烦,先给dump offset kd_off[max]+2 count 2,然后大小头颠倒, 计算出数字,在此基础上加上kdxle偏移, --//获得正确的偏移NNNN,然后再使用如下命令查询。 https://blog.itpub.net/267265/viewspace-2991956/ 上面这句话怎么解释 我们查看索引的时候可以通过 p kd_off 查看索引的条目,但是需要注意的是  kd_off[0] 和kd_off[1] 都是不准确的,用bbed 解析的偏移量看都是乱的 BBED> p kd_off sb2 kd_off[0]                               @132      8032 sb2 kd_off[1]                               @134      0 sb2 kd_off[2]                               @136      7767 我们要怎么去找这个 偏移量   找到 kd_off最大的那个  @136(这里是这个,千万别用后面的偏移量)    这里计算就是  dump offset  【kd_off136+2】 count 2 --》 d offset  138 count 2    1               dump offset  【kd_off136+4】 count 2 --》 d offset  140 count 2     0    BBED> d offset  138 count 2  File: /u02/app/oracle/oradata/TEST/datafile/o1_mf_users_mnj4l868_.dbf (7)  Block: 1931             Offsets:  138 to  139           Dba:0x01c0078b ------------------------------------------------------------------------  4c1d   --》然后 前后调换 1d4c -->7500(相对偏移量)  7500再加上kdxle 的偏移量= 7600 (绝对偏移量)  --》查看数据 x /rcc dba 7,1931 offset 7600  <32 bytes per line> BBED> d offset  140 count 2    File: /u02/app/oracle/oradata/TEST/datafile/o1_mf_users_mnj4l868_.dbf (7)  Block: 1931             Offsets:  140 to  141           Dba:0x01c0078b ------------------------------------------------------------------------  d918   --》然后 前后调换 18d9  --> 6361   6361 再加上kdxle 的偏移量= 6461 (绝对偏移量)--》查看数据 x /rcc dba 7,1931 offset 6461 --查看数据 x /rcc dba 7,1931 *kd_off[2] x /rcc dba 7,1931 offset 7600 x /rcc dba 7,1931 offset 6461 后面再准备个环境自己试试 SQL> select segment_name,header_file,header_block,BLOCKS from dba_segments where owner='ZC' and segment_name='AA'; SEGMENT_NAME      HEADER_FILE HEADER_BLOCK   BLOCKS -------------------- ----------- ------------ ---------- AA        7 1970      256 分析上面的索引  BBED> set dba 7,1971 DBA            0x01c007b3 (29362099 7,1971) BBED> map /v  File: /u02/app/oracle/oradata/TEST/datafile/o1_mf_users_mnj4l868_.dbf (7)  Block: 1971                                  Dba:0x01c007b3 ------------------------------------------------------------  KTB Data Block (Index Branch)  struct kcbh, 20 bytes                      @0            ub1 type_kcbh                           @0            ub1 frmt_kcbh                           @1            ub2 wrp2_kcbh                           @2            ub4 rdba_kcbh                           @4            ub4 bas_kcbh                            @8            ub2 wrp_kcbh                            @12           ub1 seq_kcbh                            @14           ub1 flg_kcbh                            @15           ub2 chkval_kcbh                         @16           ub2 spare3_kcbh                         @18        struct ktbbh, 48 bytes                     @20           ub1 ktbbhtyp                            @20           union ktbbhsid, 4 bytes                 @24           struct ktbbhcsc, 8 bytes                @28           sb2 ktbbhict                            @36           ub1 ktbbhflg                            @38           ub1 ktbbhfsl                            @39           ub4 ktbbhfnx                            @40           struct ktbbhitl[1], 24 bytes            @44        struct kdxbr, 24 bytes                     @76           struct kdxbrxco, 16 bytes               @76           ub4 kdxbrlmc                            @92           sb2 kdxbrsno                            @96        sb2 kd_off[160]                            @100       ub1 freespace[6130]                        @420       ub1 rowdata[1578]                          @6550      ub4 tailchk                                @8188     BBED> p kd_off sb2 kd_off[0]                               @100      8056 sb2 kd_off[1]                               @102      16368 sb2 kd_off[2]                               @104      8047 *** sb2 kd_off[159]                             @418      6498     普通索引块 BBED> x /rnc *kd_off[18] rowdata[6003]                               @7928     ------------- flag@7928:     0x00 (NONE) lock@7929:     0x00 data key: col    0[2] @7931: 18  col    1[6] @7934: .????c.. BBED> d /v count 32  File: /u02/app/oracle/oradata/TEST/datafile/o1_mf_users_mnj4l868_.dbf (7)  Block: 1972    Offsets: 7928 to 7959  Dba:0x01c007b4 -------------------------------------------------------  000002c1 130601c0 01630019 000002c1 l ...????..????c.....   00 flag   00 lock  02--》字段宽度(或者说索引长度) c113-->18  120601c0 0163002a 000002c1 110601c0 l ...????c.*...????..  17 的偏移量是 7940  和 18 的偏移量 7928  差 12   也就是说 000002c1 13 0601c0 01630019 --》这个都是索引的数据  00 flag   00 lock   c113-->18 BBED>  x /rnc *kd_off[17]        --> 17 的偏移量是 7940  和 18 的偏移量 差 12  rowdata[6015]                               @7940     ------------- flag@7940:     0x00 (NONE) lock@7941:     0x00 data key: col    0[2] @7943: 17  col    1[6] @7946: .????c.* BBED> d /v count 32  File: /u02/app/oracle/oradata/TEST/datafile/o1_mf_users_mnj4l868_.dbf (7)  Block: 1972    Offsets: 7940 to 7971  Dba:0x01c007b4 -------------------------------------------------------  000002c1 120601c0 0163002a 000002c1 l ...????..????c.*...  110601c0 01630000 000002c1 100601c0 l ...????c.....????.. 0601c0 01630019  --》这块不知道是什么 怀疑是  指向的数据块的 dba 和 row nm   分析  SQL> select rowid from test where object_id='18';  --》上面 object_id =18的索引 ROWID ------------------ AAASCdAAHAAAAFjAAZ SQL> select get_rowid('AAASCdAAHAAAAFjAAZ') row_id from dual; OBJECT# IS :73885 RELATIVE_FNO IS :7 BLOCK NUMBER IS :355 ROW NUMBER IS :25 转换成 dba 0x01c00163  -->set dba  bbed看就行  分析发现: 01c0 0163 这块是dba 地址  25 转换成16进制是19 这个 19 就是row number (猜测0019是row number)  那么前面的06 就是 后面的dba加rownumer 的宽度 再次解读下上面的dump  BBED> d /v count 32  File: /u02/app/oracle/oradata/TEST/datafile/o1_mf_users_mnj4l868_.dbf (7)  Block: 1972    Offsets: 7928 to 7959  Dba:0x01c007b4 -------------------------------------------------------  00 00 02 c113 06 01c001630019  000002c1 l ...????..????c.....   00 flag   00 lock  02--》字段宽度(或者说索引长度)  c113-->18 06 后面的dba加rownum长度   01c00163 --》索引对应数据所在的dba   0019-->数据块所在的行  120601c0 0163002a 000002c1 110601c0 l ...????c.*...????.. 在叶子节点中,每个索引条目都会在数据块中占一行空间。每一行用2到3个字节作为行头,行头用来存放标记以及锁定类型等信息。 同时,在第一个表示索引的键值的字段中,每一个索引列都有1个字节表示数据长度,后面则是该列具体的值。 那么对于本例来说,在叶子节点中的一行所包含的数据大致如下图二所示: 2字节行头 (flag 和锁), 1字节 c1列长度,   c1 列的值, 1字节 dba 长度 dba的值,2字节row num 参考: https://www.cnblogs.com/lfree/p/11503366.html https://www.cnblogs.com/lfree/p/10441410.html https://blog.itpub.net/267265/viewspace-2991956/ https://blog.itpub.net/267265/viewspace-2994798/ https://blog.csdn.net/xiaoxu0123/article/details/5451810  [Oracle]深入研究B-树索引 -->这个还没看完   01c007b5

相关推荐