索引块分裂

索引和表的itl 是完全不同的,如果表没有空闲空间创建itl并且itl使用完,则发生itl 等待

索引块如果没有空闲空间创建itl,会发生索引块分裂,将一个索引块分裂为2个,而不发生itl 等待。

 

试验;

1,创建表和索引

09:38:24 SQL> create table jiebin_test (id int);

 

Table created

 

Executed in 0.063 seconds

 

 

09:38:44 SQL>

 

begin

for i in 100000 .. 1000000 loop

insert into jiebin_test values(i);

commit;

end loop;  

end;

 

           7  /

 

PL/SQL procedure successfully completed

 

Executed in 11.375 seconds

 

 

09:39:50 SQL>  create index jiebin_ind on jiebin_test(id) pctfree 0 initrans 2;

 

Index created

 

Executed in 0.235 seconds

 

 

09:40:48 SQL> select * from dba_extents where segment_name='JIEBIN_IND';

 

OWNER                          SEGMENT_NAME                                                                     PARTITION_NAME                 SEGMENT_TYPE       TABLESPACE_NAME                 EXTENT_ID    FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO

------------------------------ -------------------------------------------------------------------------------- ------------------------------ ------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                   0          4      40609      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                   1          4      40617      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                   2          4      40625      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                   3          4      40633      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                   4          4      40641      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                   5          4      40649      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                   6          4      40657      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                   7          4      40665      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                   8          4      40673      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                   9          4      40681      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                  10          4      40689      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                  11          4      40697      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                  12          4      40705      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                  13          4      40841      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                  14          4      40849      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                  15          4      40857      65536          8            4

JIEBIN                         JIEBIN_IND                                                                                                      INDEX              USERS                                  16          4      40969    1048576        128            4

 

 

2 dump index 的一个叶子块

  40617,该块是满的,pctfree 0.

部分内容:

 

 

Block header dump:  0x01009ea9

 Object id on Block? Y

 seg/obj: 0x31581  csc: 0x02.d9bcbef6  itc: 2  flg: E  typ: 2 - INDEX

     brn: 1  bdba: 0x1009ea1 ver: 0x01 opc: 0

     inc: 0  exflg: 0

 

 Itl           Xid                  Uba         Flag  Lck        Scn/Fsc

0x01   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000

0x02   0xffff.000.00000000  0x00000000.0000.00  C---    0  scn 0x0002.d9bcbef6

 

Leaf block dump

===============

header address 102160996=0x616da64

kdxcolev 0

KDXCOLEV Flags = - - -

kdxcolok 0

kdxcoopc 0x80: pcode=0: iot flags=--- is converted=Y

kdxconco 2

kdxcosdc 0

kdxconro 533

kdxcofbo 1102=0x44e

kdxcofeo 1108=0x454

kdxcoavs 6

kdxlespl 0

kdxlende 0

kdxlenxt 16817834=0x1009eaa

kdxleprv 16817832=0x1009ea8

kdxledsz 0

kdxlebksz 8032

row#0[8019] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 16 29 

col 1; len 6; (6):  01 00 30 a5 00 9f

row#1[8006] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 16 2a

col 1; len 6; (6):  01 00 30 a5 00 a0

row#2[7993] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 16 2b

col 1; len 6; (6):  01 00 30 a5 00 a1

row#530[1134] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 1b 47

col 1; len 6; (6):  01 00 30 a6 00 1d

row#531[1121] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 1b 48

col 1; len 6; (6):  01 00 30 a6 00 1e

row#532[1108] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 1b 49

col 1; len 6; (6):  01 00 30 a6 00 1f

----- end of leaf block dump -----

End dump data blocks tsn: 4 file#: 4 minblk 40617 maxblk 40617

 

索引记录的key值为

 

 

row#0[8019] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 16 29  ------------索引的key

col 1; len 6; (6):  01 00 30 a5 00 9f-----------rowid

 

row#532[1108] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 1b 49 ------------索引的key

col 1; len 6; (6):  01 00 30 a6 00 1f-----------rowid

 

通过计算,将16进制key 转化为 10进制

该索引块 记录的表jiebin_test id

2140-2672

 

 

 

验证

hex 即为dump文件里的16进制的值

  select id,dump(id), dump(id,16) HEX from jiebin.jiebin_test where id=2140;

 

        ID

----------

DUMP(ID)

------------------------------------------------------------------------------------------------------------------------------------

HEX

------------------------------------------------------------------------------------------------------------------------------------

      2140

Typ=2 Len=3: 194,22,41

Typ=2 Len=3: c2,16,29

 

10:48:14 sys@bt>select id,dump(id), dump(id,16) HEX from jiebin.jiebin_test where id=2672;

 

        ID

----------

DUMP(ID)

------------------------------------------------------------------------------------------------------------------------------------

HEX

------------------------------------------------------------------------------------------------------------------------------------

      2672

Typ=2 Len=3: 194,27,73

Typ=2 Len=3: c2,1b,49

 

因为该块的pctfree0

只能支持2个事物

我对该表开了3session 做了3update

 

update jiebin_test set id=12672 where id=2672;

 

update jiebin_test set id=12671 where id=2671;

 

update jiebin_test set id=12670 where id=2670;

 

3update 都可以进行,表明索引在单块上没有itl的时候,可以进行。

原理是如果索引的单个叶子如果没有空间创建itl ,可以发生块分裂。

在索引的高度变化时,叶子和brance块都可能发生分裂,索引根节点也可能发生分裂,变成分支节点

 

我们在update后,重新dump索引的叶子节点后,文件内容:

row#0[4512] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 16 29

col 1; len 6; (6):  01 00 30 a5 00 9f

row#1[4525] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 16 2a

col 1; len 6; (6):  01 00 30 a5 00 a0

 

row#268[7993] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 19 09

col 1; len 6; (6):  01 00 30 a5 01 ab

row#269[8006] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 19 0a

col 1; len 6; (6):  01 00 30 a5 01 ac

row#270[8019] flag: ------, lock: 0, len=13

col 0; len 3; (3):  c2 19 0b

col 1; len 6; (6):  01 00 30 a5 01 ad

----- end of leaf block dump -----

End dump data blocks tsn: 4 file#: 4 minblk 40617 maxblk 40617

 

 

索引的key

id

2140--2410

发生索引块分裂,一个索引上的内容,按照5:5 的比例,分配到了2个块中。

 

原来该索引块的内容为id 2140-2672

原来该索引块 记录了532 行记录,

现在则只有 270行记录

 

所以,索引即使在pctfree 满的时候,也不会一定会发生itl 的等待,

 

在索引数据块上,有2种情形会导致发生“enq: TX - allocate ITL entry”等待:

1、达到数据块上最大事务数限制;---一个数据块的最大事物数通常为 255

2、递归事务ITL争用,第二种情形是由索引分裂引起的:

当一个事务中递归事务请求分裂一个数据块时,

该数据块正在被另外一个事务的递归事务分裂,就发生“enq: TX - allocate ITL entry”等待。

无论在叶子节点数据块上还是在枝节点数据块上,

有且只有一个ITL slot(枝节点上的唯一ITL slot,叶子节点上的第一条ITL slot)是用于递归事务的,

2个递归事务同时要请求该ITL slot,后发出请求的事务就需要等待。

 

 

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8135069/viewspace-675624/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/8135069/viewspace-675624/

你可能感兴趣的:(索引块分裂)