【索引】使用索引分析快速得到索引的基本資訊

secooler發表於2009-11-27
我們在使用“validate structure”對索引進行分析後,透過查詢index_stats可以得到很多有關索引本身的屬性資訊。
透過這個實驗簡單展示一下幾個重要的資訊列。

1.建立測試表t,在t表的x列上存在主鍵。

2.對索引(
主鍵)進行分析
sec@ora10g> analyze index pk_t validate structure;

Index analyzed.

3.查詢分析之後的結果
sec@ora10g> select lf_blks, br_blks, used_space, opt_cmpr_count, opt_cmpr_pctsave from index_stats;

   LF_BLKS    BR_BLKS USED_SPACE OPT_CMPR_COUNT OPT_CMPR_PCTSAVE
---------- ---------- ---------- -------------- ----------------
      2088          4   15002737              0                0

4.所用該欄位註釋如下
LF_BLKS:索引使用的葉子塊(資料所在的塊)數目;
BR_BLKS:分支塊(索引結構中導航所用的塊)數目;
USED_SPACE:索引使用的空間,單位是位元組;
OPT_CMPR_COUNT:最優壓縮數;
OPT_CMPR_PCTSAVE:使用上面的最優壓縮數後最優節省壓縮百分比;

透過後面兩個引數的指示,對於使用索引壓縮技術來講有直接的指導和借鑑意義。

5.有關index_stats檢視的官方文件的解釋附在此處,方便大家參考。

INDEX_STATS

INDEX_STATS stores information from the last ANALYZE INDEX ... VALIDATE STRUCTURE statement.

Note:

The ANALYZE INDEX ... VALIDATE STRUCTURE OFFLINE statement 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 an ANALYZE

6.小結
透過這種方法對索引進行分析後,可以快速的得到索引的基本情況,為進一步對其進行最佳化起到了非常大的幫助。
index_stats檢視的其他列也同樣很有意義,值得細細品味。

secooler
09.11.27

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-620882/,如需轉載,請註明出處,否則將追究法律責任。

相關文章