index_stats视图用于查看索引结构相关信息
来源:互联网 发布:sql safe updates 编辑:程序博客网 时间:2024/05/16 15:40
index_stats视图存储最后一次执行ANALYZE INDEX … VALIDATE STRUCTURE语句的统计信息。
这个视图主要是通过执行Analysis Index index_name VALIDATE STRUCTURE语句产生的统计信息,注意这个视图是session级别的。
上述这个语句只是分析相关索引信息,并不会统计收集、更新索引的信息状态等,如若要统计收集、更新索引的状态,必须使用:
Alter Index index_name Compute Statistics;
INDEX_STATS
stores information from the last ANALYZE INDEX ... VALIDATE STRUCTURE
statement.
Note:
TheANALYZE INDEX ... VALIDATE STRUCTURE OFFLINE
statement must be used in order to collect statisticsHEIGHT
NUMBER
Height of the B-TreeBLOCKS
NUMBER
NOT NULL
Blocks allocated to the segmentNAME
VARCHAR2(30)
NOT NULL
Name of the indexPARTITION_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-TreeLF_ROWS_LEN
NUMBER
Sum of the lengths of all the leaf rowsLF_BLK_LEN
NUMBER
Usable space in a leaf blockBR_ROWS
NUMBER
Number of branch rows in the B-TreeBR_BLKS
NUMBER
Number of branch blocks in the B-TreeBR_ROWS_LEN
NUMBER
Sum of the lengths of all the branch blocks in the B-TreeBR_BLK_LEN
NUMBER
Usable space in a branch blockDEL_LF_ROWS
NUMBER
Number of deleted leaf rows in the indexDEL_LF_ROWS_LEN
NUMBER
Total length of all deleted rows in the indexDISTINCT_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-TreeUSED_SPACE
NUMBER
Total space that is currently being used in the B-TreePCT_USED
NUMBER
Percent of space allocated in the B-Tree that is being usedROWS_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 rowsOPT_CMPR_COUNT
NUMBER
Optimal key compression lengthOPT_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树索引》有关该视图的使用
- index_stats视图用于查看索引结构相关信息
- Oracle索引2--index_stats视图
- sp_help 快速查看表结构、视图信息
- 使用INDEX_STATS重建索引判断
- 查看表或视图上的索引信息
- INDEX_STATS
- 分析b-tree索引的好视图index_stats(http://space.itpub.net/?uid-780947-action-viewspace-itemid-368892)
- 索引分析后index_stats里没数据?
- 查看索引信息
- 视图相关的结构
- 查看Oracle当前用户下的信息(用户,表视图,索引...)
- 查看Linux 相关信息
- MySQL查看相关信息
- 查看keystore相关信息
- 查看php相关信息
- 查看表和视图信息
- Trafodion 查看索引表结构
- 查看Oracle索引和视图的方法
- 抽象工厂模式的几种实现方法及比较
- struts中action,actionform,jsp配置及流程分析(个人理解)
- Android---用Wi-Fi来建立对等连接
- 数据库事务、锁死、范式
- Constants付 MySQL 的死连接,Sleep的进程的来源探究[转]
- index_stats视图用于查看索引结构相关信息
- [ORACLE]数据库之间复制表
- veriguide for Plagiarism detection
- 什么叫程序库?
- kill session 与 查找spid
- [原]qt5几个类和机制的简要介绍
- 这次马云不会成功
- 优秀书籍收集
- Tomcat中文乱码问题的原理和解决方法(全面、详细)