SQL> select count(*)from index_test;
COUNT(*)
----------
74
SQL> select count(*)from index_test where object_id is null;
COUNT(*)
----------
1
因为我们存在一条记录中object_id位空值了,所以没有作为索引列。
我们来随机抽取几条数据作为后续的dml操作基础。
select *from (select object_id from index_test order by dbms_random.value()) where rownum<5;
OBJECT_ID
----------
15287
22180
22295
14019
我们就选择第一条记录。做一个update操作。
update index_test set object_id=11111 where object_id=15287;
commit;
analyze index inx_test validate structure;--再次分析索引
select height,blocks,br_blks,lf_blks,lf_rows,del_lf_rows from index_stats;
HEIGHT BLOCKS BR_BLKS LF_BLKS LF_ROWS DEL_LF_ROWS
---------- ---------- ---------- ---------- ---------- -----------
1 8 0 1 74 1
可以很清晰的看到叶子内行数从73变为74,然后 叶子中被删除的行数 也从0变为1.
这是因为update也是一个delete+insert的操作,新增加的一行是object_id=15287被删除时留下的。
我们来尝试一个Insert操作。
insert into index_test select *from index_test;
commit;
analyze index inx_test validate structure; --再次分析索引
select height,blocks,br_blks,lf_blks,lf_rows,del_lf_rows from index_stats;
HEIGHT BLOCKS BR_BLKS LF_BLKS LF_ROWS DEL_LF_ROWS
---------- ---------- ---------- ---------- ---------- -----------
1 8 0 1 146 0
这个时候叶子内行数从74变为146. 可以这么理解73*2=146. 因为表中的非null数据有73行,所以再次插入的时候对应的叶子内行数就是73*2=146.
我们插入较多的数据来看看叶子节点的存储情况。
insert into index_test select *from index_test;
/
commit; --插入了两次
analyze index inx_test validate structure; --再次分析索引
select height,blocks,br_blks,lf_blks,lf_rows,del_lf_rows from index_stats;
HEIGHT BLOCKS BR_BLKS LF_BLKS LF_ROWS DEL_LF_ROWS
---------- ---------- ---------- ---------- ---------- -----------
2 8 1 2 584 0
可以看到叶子内行数变化很大,同时叶子节点块变为了2个。
如果再逐渐插入数据,可以看到分支节点,叶子节点的变化情况。
我们这个时候可以换个思路,来使用dbms_stats来查看一下信息。
user_indexes中的信息还有比较粗略的。我们来验证一下是否和analyze分析的Index_stats结果一致。
SQL> select blevel,leaf_blocks from user_indexes where index_name='INX_TEST';
BLEVEL LEAF_BLOCKS
---------- -----------
0 1
这个时候看起来信息过旧了,我们使用dbms_stats来收集一下统计信息。
exec dbms_stats.gather_index_stats(ownname=>'N1',indname=>'INX_TEST');
再次查看结果就跟预期的一致了。
select blevel,leaf_blocks from user_indexes where index_name='INX_TEST';
BLEVEL LEAF_BLOCKS
---------- -----------
1 2
索引的内部信息还是比较抽象的,要做细致的分析还是要下不少的功夫。不过对于索引的很多细节信息,可以说都属于技术级别,都在oracle内部做了封装。我们可以根据兴趣来了解一下。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23718752/viewspace-1367045/ ,如需转载,请注明出处,否则将追究法律责任。