理解index leaf node 90-10 split

简介: 理解index leaf node  90-10 split当索引leaf满分裂时,存在两种情况:1.如果插入的键值是最大值,分裂按照90-10 split.2.如果不是,按照50-50分裂。
理解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。


目录
相关文章
|
5月前
Leetcode 19.Remove Nth Node From End of List
删除单链表中的倒数第n个节点,链表中删除节点很简单,但这道题你得先知道要删除哪个节点。在我的解法中,我先采用计数的方式来确定删除第几个节点。另外我在头节点之前额外加了一个节点,这样是为了把删除头节点的特殊情况转换为一般情况,代码如下。
19 0
报错FileSystemException: /datas/nodes/0/indices/gtTXk-hnTgKhAcm-8n60Jw/1/index/.es_temp_file
首先我碰到的问题是服务器突然断电导致elasticsearch宕机,当我再次启动的时候 >FileSystemException: /data/elasticsearchDatas/datas/nodes/0/indices/gtTXk-hnTgKhAcm-8n60Jw/1/index/.es_temp_file: 结构需要清理
133 0
报错FileSystemException: /datas/nodes/0/indices/gtTXk-hnTgKhAcm-8n60Jw/1/index/.es_temp_file
|
SQL 索引
ORA-01502: index ‘index_name' or partition of such index is in unusable state
错误现象:   今天发布脚本时,一个表插入数据时报如下错误   ORA-01502: index ‘index_name' or partition of such index is in unusable state   ORA-06512: at line 168 错误原因:   这个错误一般是因为索引状态为UNUSABLE引起的。
906 0
|
SQL 索引
ORA-01502: index 'INDEX_NAME' or partition of such index is in unusable state
ORA-01502: index 'INDEX_NAME' or partition of such index is in unusable state 原因:   这个错误一般是因为索引状态为UNUSABLE引起的。
993 0
[LeetCode]--19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node fr
1319 0
leetcode 19. Remove Nth Node From End of List
题目 Given a linked list, remove the nth node from the end of list and return its head.
811 0