欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Oracle中检查是否需要重构索引的sql

程序员文章站 2022-10-13 20:42:34
复制代码 代码如下: select height, /*height of the b-tree*/ blocks, /* blocks in the index segm...
复制代码 代码如下:

select
height, /*height of the b-tree*/
blocks, /* blocks in the index segment */
name, /*index name */
lf_rows, /* number of leaf rows in the index */
lf_blks, /* number of leaf blocks in the index */
del_lf_rows, /* number of deleted leaf rows in the index */
rows_per_key /* average number of rows per distinct key */
blk_gets_per_access /* consistent mode block reads (gets) */
from index_stats
where name='index_name';

复制代码 代码如下:

analyze index index_name validate structure


height:
this column refers to the height of the b-tree index, and it's usually at the 1, 2, or 3 level.
if large inserts push the index height beyond a level of 4, it's time to rebuild, which flattens the b-tree.

del_lf_rows:
this is the number of leaf nodes deleted due to the deletion of rows.
oracle doesn't rebuild indexes automatically and, consequently, too many deleted leaf rows can lead to an unbalanced b-tree.

blk_gets_per_access:
you can look at the blk_gets_per_access column to see how much logical i/o it takes to retrieve data from the index. if this row shows a double-digit number, you should probably start rebuilding the index.