理解index leaf node 90-10 split
当索引leaf满分裂时,存在两种情况:
1.如果插入的键值是最大值,分裂按照90-10 split.
2.如果不是,按照50-50分裂。
按照字面的理解90-10 split,就是90的键值保留在原来数据块中,其他10%键值使用新的数据块。实际情况如何呢?
1.建立测试表:
select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
create table t1(a varchar2(5),b varchar2(10));
create unique index i_t1_a on t1(a);
select a.*,b.name from v$mystat a , v$statname b where a.statistic#=b.statistic# and b.name like '%leaf%';
SID STATISTIC# VALUE NAME
---------- ---------- ---------- ----------------------------------------------------------------
11 382 0 leaf node splits
11 383 0 leaf node 90-10 splits
begin
for i in 1..501 loop
insert into t1 values (lpad(to_char(i),5,'0') ,'test');
end loop;
end;
/
commit;
select a.*,b.name from v$mystat a , v$statname b where a.statistic#=b.statistic# and b.name like '%leaf%';
SID STATISTIC# VALUE NAME
---------- ---------- ---------- ----------------------------------------------------------------
11 382 1 leaf node splits
11 383 1 leaf node 90-10 splits
应该产生一次leaf node 90-10 splits。
2. 分析索引结构:
SQL> SELECT object_id FROM dba_objects WHERE object_name = 'I_T1_A';
OBJECT_ID
----------
76265
SQL> ALTER SESSION SET EVENTS 'immediate trace name treedump level 76265';
Session altered.
----- begin tree dump
branch: 0x100051b 16778523 (0: nrow: 2, level: 1)
leaf: 0x100051e 16778526 (-1: nrow: 499 rrow: 499)
leaf: 0x100051f 16778527 (0: nrow: 2 rrow: 2)
----- end tree dump
可以发现两个索引leaf node,1个有499个键值,另外一个2个键值。
3.转储数据块:
select header_file, header_block from dba_segments where segment_name='I_T1_A';
HEADER_FILE HEADER_BLOCK
----------- ------------
4 1306
根节点块1307,根据上面leaf节点应该是1310,1311.
alter system dump datafile 4 block min 1310 block max 1311;
Start dump data blocks tsn: 4 file#:4 minblk 1310 maxblk 1311
........
Block header dump: 0x0100051f
Object id on Block? Y
seg/obj: 0x129e9 csc: 0x00.37946f itc: 2 flg: E typ: 2 - INDEX
brn: 0 bdba: 0x1000518 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0005.010.00000e0d 0x00c00a13.0222.02 CB-- 0 scn 0x0000.0037946f
0x02 0x0005.000.00000e0b 0x00c00a0f.0222.1c --U- 2 fsc 0x0000.00379471
Leaf block dump
===============
header address 46978354870884=0x2aba00277a64
kdxcolev 0
KDXCOLEV Flags = - - -
kdxcolok 0
kdxcoopc 0x80: pcode=0: iot flags=--- is converted=Y
kdxconco 1
kdxcosdc 1
kdxconro 2
kdxcofbo 40=0x28
kdxcofeo 8004=0x1f44
kdxcoavs 7964
kdxlespl 0
kdxlende 0
kdxlespl 0
kdxlende 0
kdxlenxt 0=0x0
kdxleprv 16778526=0x100051e
kdxledsz 6
kdxlebksz 8032
row#0[8018] flag: ------, lock: 2, len=14, data:(6): 01 00 05 0e 00 2e
col 0; len 5; (5): 30 30 35 30 30
row#1[8004] flag: ------, lock: 2, len=14, data:(6): 01 00 05 0e 00 2f
col 0; len 5; (5): 30 30 35 30 31
----- end of leaf block dump -----
End dump data blocks tsn: 4 file#: 4 minblk 1310 maxblk 1311
也可以确定1311块中仅仅两个键值。
SQL> select dump('00500',16),dump('00501',16) from dual;
DUMP('00500',16) DUMP('00501',16)
---------------------------- ----------------------------
Typ=96 Len=5: 30,30,35,30,30 Typ=96 Len=5: 30,30,35,30,31
根据测试如果index leaf node 90-10 split时,实际上是新添加的键值使用新的索引extent,保留原来节点信息。实际上应该叫100-1个键值的split。