索引分裂的enq

索引分裂引起的enq-index contentionenq: TX - allocate ITL entry,该等待事件是由于索引分裂下,并发的用户在此更新索引导致。

SQL> create table t1(id number,name varchar2(1000));

Table created

SQL> create index index_t1 on t1(id,name) pctfree 0;

Index created

SQL> begin

2 for i in 1..1000 loop

3 insert into t1 values(i,rpad('x',1000,'x'));

4 end loop;

5 commit;

6 end;

7 /

PL/SQL procedure successfully completed

SQL> analyze index index_t1 validate structure;

Index analyzed

SQL> select name,height,blocks,lf_rows,lf_blks,pct_used from index_stats;

NAME HEIGHT BLOCKS LF_ROWS LF_BLKS PCT_USED

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

INDEX_T1 2 256 1000 143 89

SQL>

SQL> select a.value,b.name from v$mystat a,v$statname b

2 where a.statistic#=b.statistic# and b.name like 'leaf node%'

3 ;

VALUE NAME

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

156 leaf node splits

156 leaf node 90-10 splits

SQL> insert into t1 values(1,rpad('x',1000,'x'));

1 row inserted

SQL> commit;

SQL> analyze index index_t1 validate structure;

Index analyzed

SQL> select name,height,blocks,lf_rows,lf_blks,pct_used from index_stats;

NAME HEIGHT BLOCKS LF_ROWS LF_BLKS PCT_USED

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

INDEX_T1 2 256 1001 144 88

SQL>

SQL> select a.value,b.name from v$mystat a,v$statname b

2 where a.statistic#=b.statistic# and b.name like 'leaf node%'

3 ;

VALUE NAME

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

157 leaf node splits

156 leaf node 90-10 splits

发生索引叶块的5-5分裂,叶块由143变为了144.

SQL> insert into t1 values(0.5,rpad('x',1000,'x'));

1 row inserted

SQL> analyze index index_t1 validate structure;

Index analyzed

SQL> select name,height,blocks,lf_rows,lf_blks,pct_used from index_stats;

NAME HEIGHT BLOCKS LF_ROWS LF_BLKS PCT_USED

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

INDEX_T1 2 256 1002 144 88

SQL> insert into t1 values(1001,rpad('x',1000,'x'));

1 row inserted

SQL> commit;

Commit complete

SQL> analyze index index_t1 validate structure;

Index analyzed

SQL> select name,height,blocks,lf_rows,lf_blks,pct_used from index_stats;

NAME HEIGHT BLOCKS LF_ROWS LF_BLKS PCT_USED

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

INDEX_T1 2 256 1003 144 89

此时没有发生叶块分裂,因为索引顺序排序下,叶块的最后的一个叶块节点并并没有写满,所以1001这个键值会存储在最后的一个叶块上。

SQL> begin

2 for i in 1002..1200 loop

3 insert into t1 values(i,rpad('x',1000,'x'));

4 end loop;

5 commit;

6 end;

7 /

PL/SQL procedure successfully completed

SQL>

SQL> select a.value,b.name from v$mystat a,v$statname b

2 where a.statistic#=b.statistic# and b.name like 'leaf node%'

3 ;

VALUE NAME

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

186 leaf node splits

185 leaf node 90-10 splits

对比一下上述的统计信息,重新插入数值由于在维护索引,分别发生了5-5分裂和1-9分裂

SQL> analyze index index_t1 validate structure;

Index analyzed

SQL> select name,height,blocks,lf_rows,lf_blks,pct_used from index_stats;

NAME HEIGHT BLOCKS LF_ROWS LF_BLKS PCT_USED

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

INDEX_T1 2 256 1202 173 88

模拟下关于索引等待的两个事件

并发的两个session执行下列pl/sql

SQL> declare

2 begin

3 for i in 501..1000 loop

4 insert into t1 values(i,rpad('x',1000,'x'));

5 end loop;

6 commit;

7 end;

8 /

PL/SQL procedure successfully completed

SQL> select userenv('SID') from dual;

USERENV('SID')

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

144

SQL> select sid,event,total_waits,time_waited,average_wait from v$session_event where event like 'enq%';

SID EVENT TOTAL_WAITS TIME_WAITED AVERAGE_WAIT

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

138 enq: HW - contention 428 664 1.55

138 enq: TX - index contention 7 2 0.28

144 enq: RO - fast object reuse 4 54 13.62

144 enq: HW - contention 592 1448 2.45

144 enq: TX - allocate ITL entry 4 0 0.01

144 enq: TX - index contention 2 21 10.49

6 rows selected

等待出现了,enq: TX - allocate ITL entryenq: TX - index contention

[@more@]

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

转载于:http://blog.itpub.net/25362835/viewspace-1058113/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值