index_stats视图用于查看索引结构相关信息
2013-10-11 13:22
429 查看
index_stats视图存储最后一次执行ANALYZE INDEX … VALIDATE STRUCTURE语句的统计信息。
Note:
The
通过该视图我们可以判断一个所以是否需要重建:
对一个索引进行结构分析后,如果该索引占用超过了一个数据块,且满足以下条件之一;
B-tree树的高度大于3;
使用百分比低于75%;
数据删除率大于15%.
SQL> select btree_space, -- if > 8192(块的大小)
height, -- if > 3
pct_used, -- if < 75
del_lf_rows/(decode(lf_rows,0,1,lf_rows)) *100 as deleted_pct -- if > 15%
from index_stats;
-The End-
======================================================================
经常碰到人问我index 什么时候需要rebuild,今天看了个文章,记录了一下.
The INDEX_STATS view is useful for seeing how efficiently an index is using its space. Large indexes
have a tendency to become unbalanced over time if many deletions are in the table (and therefore
index) data. Your goal is to keep an eye on those large indexes with a view to keeping them balanced.
Note that the INDEX_STATS view is populated only if the table has been analyzed by using the
ANALYZE command, as follows:
SQL> ANALYZE index hr.emp_name_ix VALIDATE STRUCTURE;
Index analyzed.
The query in Listing 7-26 using the INDEX_STATS view helps determine whether you need to
rebuild the index. In the query, you should focus on the following columns in the INDEX_STATS view
to determine if your index is a candidate for a rebuild:
• 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.
Using the INDEX_STATS View to Determine Whether to Rebuild an Index
SQL> SELECT height, /*Height of the B-Tree*/
2 blocks, /* Blocks in the index segment */
3 name, /*index name */
4 lf_rows, /* number of leaf rows in the index */
5 lf_blks, /* number of leaf blocks in the index */
6 del_lf_rows, /* number of deleted leaf rows
in the index */
7 rows_per_key /* average number of rows
per distinct key */
8 blk_gets_per_access /* consistent mode block reads (gets) */
8 FROM INDEX_STATS
9* WHERE name='EMP_NAME_IX';
HEIGHT BLOCK LF_ROWS LF_BLKS DEL_LF_ROWS ROWS_PER_KEY BLK_GETS
------ ----------- ------- -------- ----------- ------------ ---------
16 EMP_NAME_IX 107 1 0 1
注释:参看《深入研究B树索引》有关该视图的使用
这个视图主要是通过执行Analysis Index index_name VALIDATE STRUCTURE语句产生的统计信息,注意这个视图是session级别的。
上述这个语句只是分析相关索引信息,并不会统计收集、更新索引的信息状态等,如若要统计收集、更新索引的状态,必须使用:
Alter Index index_name Compute Statistics;
INDEX_STATSstores information from the last
ANALYZE INDEX ... VALIDATE STRUCTUREstatement.
Note:
The
ANALYZE INDEX ... VALIDATE STRUCTURE OFFLINEstatement must be used in order to collect statistics
Column | Datatype | NULL | Description |
---|---|---|---|
HEIGHT | NUMBER | Height of the B-Tree | |
BLOCKS | NUMBER | NOT NULL | Blocks allocated to the segment |
NAME | VARCHAR2(30) | NOT NULL | Name of the index |
PARTITION_NAME | VARCHAR2(30) | Name of the partition of the index which was analyzed. If the index is not partitioned, NULL is returned. | |
LF_ROWS | NUMBER | Number of leaf rows (values in the index) | |
LF_BLKS | NUMBER | Number of leaf blocks in the B-Tree | |
LF_ROWS_LEN | NUMBER | Sum of the lengths of all the leaf rows | |
LF_BLK_LEN | NUMBER | Usable space in a leaf block | |
BR_ROWS | NUMBER | Number of branch rows in the B-Tree | |
BR_BLKS | NUMBER | Number of branch blocks in the B-Tree | |
BR_ROWS_LEN | NUMBER | Sum of the lengths of all the branch blocks in the B-Tree | |
BR_BLK_LEN | NUMBER | Usable space in a branch block | |
DEL_LF_ROWS | NUMBER | Number of deleted leaf rows in the index | |
DEL_LF_ROWS_LEN | NUMBER | Total length of all deleted rows in the index | |
DISTINCT_KEYS | NUMBER | Number of distinct keys in the index (may include rows that have been deleted) | |
MOST_REPEATED_KEY | NUMBER | How many times the most repeated key is repeated (may include rows that have been deleted) | |
BTREE_SPACE | NUMBER | Total space currently allocated in the B-Tree | |
USED_SPACE | NUMBER | Total space that is currently being used in the B-Tree | |
PCT_USED | NUMBER | Percent of space allocated in the B-Tree that is being used | |
ROWS_PER_KEY | NUMBER | Average number of rows per distinct key (this figure is calculated without consideration of deleted rows) | |
BLKS_GETS_PER_ACCESS | NUMBER | Expected number of consistent mode block reads per row, assuming that a randomly chosen row is accessed using the index. Used to calculate the number of consistent reads that will occur during an index scan. | |
PRE_ROWS | NUMBER | Number of prefix rows (values in the index) | |
PRE_ROWS_LEN | NUMBER | Sum of lengths of all prefix rows | |
OPT_CMPR_COUNT | NUMBER | Optimal key compression length | |
OPT_CMPR_PCTSAVE | NUMBER | Corresponding space savings after anANALYZE |
对一个索引进行结构分析后,如果该索引占用超过了一个数据块,且满足以下条件之一;
B-tree树的高度大于3;
使用百分比低于75%;
数据删除率大于15%.
SQL> select btree_space, -- if > 8192(块的大小)
height, -- if > 3
pct_used, -- if < 75
del_lf_rows/(decode(lf_rows,0,1,lf_rows)) *100 as deleted_pct -- if > 15%
from index_stats;
-The End-
======================================================================
经常碰到人问我index 什么时候需要rebuild,今天看了个文章,记录了一下.
The INDEX_STATS view is useful for seeing how efficiently an index is using its space. Large indexes
have a tendency to become unbalanced over time if many deletions are in the table (and therefore
index) data. Your goal is to keep an eye on those large indexes with a view to keeping them balanced.
Note that the INDEX_STATS view is populated only if the table has been analyzed by using the
ANALYZE command, as follows:
SQL> ANALYZE index hr.emp_name_ix VALIDATE STRUCTURE;
Index analyzed.
The query in Listing 7-26 using the INDEX_STATS view helps determine whether you need to
rebuild the index. In the query, you should focus on the following columns in the INDEX_STATS view
to determine if your index is a candidate for a rebuild:
• 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.
Using the INDEX_STATS View to Determine Whether to Rebuild an Index
SQL> SELECT height, /*Height of the B-Tree*/
2 blocks, /* Blocks in the index segment */
3 name, /*index name */
4 lf_rows, /* number of leaf rows in the index */
5 lf_blks, /* number of leaf blocks in the index */
6 del_lf_rows, /* number of deleted leaf rows
in the index */
7 rows_per_key /* average number of rows
per distinct key */
8 blk_gets_per_access /* consistent mode block reads (gets) */
8 FROM INDEX_STATS
9* WHERE name='EMP_NAME_IX';
HEIGHT BLOCK LF_ROWS LF_BLKS DEL_LF_ROWS ROWS_PER_KEY BLK_GETS
------ ----------- ------- -------- ----------- ------------ ---------
16 EMP_NAME_IX 107 1 0 1
注释:参看《深入研究B树索引》有关该视图的使用
相关文章推荐
- 利用sys.dm_db_index_physical_stats查看索引大小/碎片等信息
- INDEX--索引相关信息查看
- 查看当前数据库中没用的索引(sys.dm_db_index_usage_stats)
- 查看表或视图上的索引信息
- MySQL: table、view、trigger、procedure、index (表、主键、UNIQUE Key、列、索引、视图、触发器、存储过程)查看、修改、更新、删除操作
- 利用sys.dm_db_index_physical_stats查看索引碎片等数据(转)
- 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)
- 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)
- 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)
- 查看Oracle当前用户下的信息(用户,表视图,索引...)
- 查看索引信息:show index from tablename;
- mysql查看表的存储引擎、表结构等相关信息
- 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)
- 利用sys.dm_db_index_physical_stats查看索引碎片等数据
- 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)
- 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)
- 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)
- 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词等)
- 利用sys.dm_db_index_physical_stats查看索引碎片等数据
- 【转】查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)