开发者社区> lfreeali> 正文

理解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。


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
报错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: 结构需要清理
25 0
LeetCode 222. Count Complete Tree Nodes
给出一个完全二叉树,求出该树的节点个数。
25 0
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引起的。
882 0
[LeetCode]--237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the thi
1223 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
1218 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.
724 0
+关注
lfreeali
熟悉oracle数据库性能优化,rman备份,数据库恢复技术.
文章
问答
视频
文章排行榜
最热
最新
相关电子书
更多
The Value of Exploratory Data
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载