oracle 统计信息是什么

上一篇 / 下一篇  2009-01-04 22:52:55 / 个人分类:Oracle

  • 文件版本: V1.0
  • 开发商: 本站原创
  • 文件来源: 本地
  • 界面语言: 简体中文
  • 授权方式: 免费
  • 运行平台: Win9X/Win2000/WinXP
1. 什么是统计信息
-maE){$_0统计信息主要是描述数据库中表,索引的大小,规模,数据分布状况等的一类信息。比如,表的行数,块数,平均每行的大小,索引的leaf blocks,索引字段的行数,不同值的大小等,都属于统计信息。CBO正是根据这些统计信息数据,计算出不同访问路径下,不同join 方式下,各种计划的成本,最后选择出成本最小的计划。
7pP/zr*?E4o0统计信息是存放在数据字段表中的,如tab$。一般我们从数据字段视图中察看统计信息状况,如DBA_TABLES,DBA_INDEXES,DBA_TAB_COL_STATISTICS, DBA_TAB_HISTOGRAMS 等。51Testing软件测试网W$e0]jP#h0ns
列举下DBA_TABLES,DBA_INDEXES 视图中表示统计信息的一些字段。这些字段只有搜集过统计信息之后才有值,否则是空的。这些字段中last_analyzed 字段表示上次统计信息搜集的时间,大家可以根据这个字段,快速的了解最近一次统计信息搜集的时间。51Testing软件测试网.\ G%i(e![DnpX4IQH
51Testing软件测试网Xjj {i W IU
--dba_tables51Testing软件测试网!M r,N,d4Wb
NUM_ROWS* NUMBER Number of rows in the table
i2A6XL ut{4V-_0BLOCKS* NUMBER Number of used data blocks in the table51Testing软件测试网(y%R.x&t{PfSp
EMPTY_BLOCKS* NUMBER Number of empty (never used) data blocks in the table51Testing软件测试网ZhI|#X@/a@l
AVG_SPACE* NUMBER Average amount of free space, in bytes, in a data block allocated to the table
*r5^1B0vs/r0CHAIN_CNT* NUMBER Number of rows in the table that are chained from one data block to another, or which have migrated to a new block, requiring a link to preserve the old ROWID
UV6GrU7G)U;y0AVG_ROW_LEN* NUMBER Average length of a row in the table in bytes
yb1W#Y3u/n4m0LAST_ANALYZED DATE Date on which this table was most recently analyzed51Testing软件测试网{ _Dmcq/q&wIx
51Testing软件测试网5_ Bl-rn
51Testing软件测试网-eIUv(b
--dba_indexes
,N#\3B ?Y ] E0BLEVEL* NUMBER B*-Tree level: depth of the index from its root block to its leaf blocks. A depth of 0 indicates that the root block and leaf block are the same.51Testing软件测试网4f0D'u8Eq'amy
LEAF_BLOCKS* NUMBER Number of leaf blocks in the index51Testing软件测试网'u x*Q2x)fl!O
DISTINCT_KEYS* NUMBER Number of distinct indexed values. For indexes that enforce UNIQUE and PRIMARY KEY constraints, this value is the same as the number of rows in the table (USER_TABLES.NUM_ROWS)
rz\,T0m0AVG_LEAF_BLOCKS_PER_KEY* NUMBER Average number of leaf blocks in which each distinct value in the index appears, rounded to the nearest integer. For indexes that enforce UNIQUE and PRIMARY KEY constraints, this value is always 1.51Testing软件测试网 B8k*yu-[6Yw)[N F)W?v
AVG_DATA_BLOCKS_PER_KEY* NUMBER Average number of data blocks in the table that are pointed to by a distinct value in the index rounded to the nearest integer. This statistic is the average number of data blocks that contain rows that contain a given value for the indexed columns.
K4Ec4nq F b%krJ0CLUSTERING_FACTOR* NUMBER Indicates the amount of order of the rows in the table based on the values of the index.51Testing软件测试网ed/gXleu
• If the value is near the number of blocks, then the table is very well ordered. In this case, the index entries in a single leaf block tend to point to rows in the same data blocks.51Testing软件测试网5wH,~(J{g'J]Y
• If the value is near the number of rows, then the table is very randomly ordered. In this case, it is unlikely that index entries in the same leaf block point to rows in the same data blocks51Testing软件测试网Hu E'b'?8z5P_"}
NUM_ROWS NUMBER Number of rows in the index
D x2W&j5s6Gj0SAMPLE_SIZE NUMBER Size of the sample used to analyze the index51Testing软件测试网&Is:i'Q'vH-[8Ae6j ]
LAST_ANALYZED DATE Date on which this index was most recently analyzed51Testing软件测试网4v:^"J J'HAR6S

0W(tS$J3ac1K.H B"Ql02. 如何搜集统计信息51Testing软件测试网?c(awt:J
统计信息搜集也是有多种方法,推荐大家使用DBMS_STATS 表来进行统计信息搜集及进行一般的统计信息维护工作
,Y3\ rSDF0DBMS-STATS 包,主要提供了搜集,删除,导出,导入,修改统计信息的方法,分别对应于gather系列,delete系列,export 系列,import系列,set系列的子过程。一般可能主要是使用统计信息的搜集,以及导出导入这样的功能。具体来说,主要会使用到如下几个子过程:
'_'~lr P|4O"o0GATHER_INDEX_STATS Procedure51Testing软件测试网 qwQ| uM L
Gathers index statistics.
o-V9^h?5JWi5i051Testing软件测试网_-E\!Y"~%k?AG
GATHER_TABLE_STATS Procedure
A/V"z_R.^Q0Gathers table and column (and index) statistics.51Testing软件测试网2I$d[ ~1@7eb w
51Testing软件测试网xv4LMUW8J%Kl1v
CREATE_STAT_TABLE Procedure51Testing软件测试网wG'?W'E:X n!jDQ
Creates a table with name stattab in ownname's schema which is capable of holding statistics.51Testing软件测试网8x6V'b n9d8J r
51Testing软件测试网8}Y] {W,H ~
EXPORT_TABLE_STATS Procedure51Testing软件测试网^2u?,G5c y(}An tj
Retrieves statistics for a particular table and stores them in the user stat table.51Testing软件测试网L)q8Fq%T!D
51Testing软件测试网R5E!u/K6BFm
EXPORT_SCHEMA_STATS Procedure
)h"_ CUA;L0Retrieves statistics for all objects in the schema identified by ownname and stores them in the user stat table identified by stattab.
[ri4m7e$I0w051Testing软件测试网A"G#])I|O-_+^Ms@f
IMPORT_INDEX_STATS Procedure51Testing软件测试网9W:rRvjP T*dOb
Retrieves statistics for a particular index from the user stat table identified by stattab and stores them in the dictionary.
0Fnef2{+y-F.c0
+R%Nc_ a:Q\!a w*[0IMPORT_TABLE_STATS Procedure
([:X!Ua4QQi^}*oF0Retrieves statistics for a particular table from the user stat table identified by stattab and stores them in the dictionary.
z#yEm9S"\,O0I1y0
;G$YUI.s(PR5o)? F0IMPORT_SCHEMA_STATS Procedure51Testing软件测试网B\.gkaf'WyI
Retrieves statistics for all objects in the schema identified by ownname from the user stat table and stores them in the dictionary.51Testing软件测试网?1P]y.Vo(oBL

A9A [ z N`0对于统计信息的搜集,谈谈个人的几点理解:51Testing软件测试网%`;QQ8L U
 统计信息默认是存放在数据字典表中的,也只有数据字典中的统计信息,才会影响到CBO。51Testing软件测试网{3}+l8S.rG1u
 DBMS_STATS 提供的CREATE_STAT_TABLE 过程,只是生成一个用户自定义的特定格式的表,用来存放统计信息罢了,这个表中的统计信息是不会影响到统计信息的。
$nc ^r/z0 GATHER 系列过程中,如果指定stattab,statid,statown 参数(也可以不指定),则是搜集的统计信息除了更新到数据字典外,还在statown 用户下的stattab 表中存放一份,标示为 statid;
1m3ZG?#YQ+Y?9U0 EXPORT和IMPORT 系列的过程中,stattab,statid,statown 参数不能为空,分别表示把数据字典中的当前统计信息导出到用户自定义的表中,以及把用户表中的统计信息导入到数据字典中,很明显可以看出,这里的导入操作和上面GATHER 操作会改变统计信息,可能会引起执行执行计划的改变,因此要慎重操作。51Testing软件测试网 XE@)sh.u/D
 每次统计信息搜集前,将旧的统计信息备份起来是很有必要的;特别是保留一份或多份系统在稳定时期的统计信息也是很有必要的。
!HqR`eeN0 多长时间搜集一次统计信息,对于统计信息如何备份和保留,搜集统计信息时如何选择合适的采样,并行,直方图设置等都比较重要,需要设计一个较好的统计信息搜集策略。

TAG: Oracle

 

评分:0

我来说两句

Open Toolbar