ain index, Oracle calls the statistics collection method in the statistics type if you analyze the column or domain index. 只有存储在字典视图中的统计信息,才会被优化器使用。
当我们收集表、列或者索引的统计信息时,如果数据字典中已经包含有统计信息,oracle会将已有信息进行更新。同时oracle也会使当前解析的与更新对象相关的sql语句无效,以便可以使用信息的统计信息。在远程主机中执行的分布式语句,则在oracle下次解析时才会使用心得统计信息。
当我们将某列或者域索引与某一统计类别管理时,oracle会在分析该列或者域索引是调用该统计类别下的统计收集方法。
missing statistics
When statistics do not exist on schema objects, the optimizer uses the following default values.
当统计信息不存在是,oracle会使用如下的默认统计信息。
| Tables |
| Statistic |
Default Value Used by Optimizer |
| Cardinality |
100 rows |
| Avg. row len |
20 bytes |
| No. of blocks |
100 |
| Remote cardinality |
2000 rows |
| Remote average row length |
100 bytes |
| Indexes |
| Statistic |
Default Value Used by Optimizer |
| Levels |
1 |
| Leaf blocks |
25 |
| Leaf blocks/key |
1 |
| Data blocks/key |
1 |
| Distinct keys |
100 |
| Clustering factor |
800 (8*no. of blocks) |
Analyze vs DBMS_STATS
The following is a quick overview of the two.
Analyze The only method available for collecting statistics in Oracle 8.0 and lower.(ORACLE 8之前仅有的统计信息收集方式)ANALYZE can only run serially(只可以串行执行).ANALYZE cannot overwrite or delete certain types of statistics that where generated by DBMS_STATS
(不可以覆盖DBMS_STATS生成的部分统计信息)
.ANALYZE calculates global statistics for partitioned tables and indexes instead of gathering them directly. This can lead to inaccuracies for some statistics, such as the number of distinct values.
(ANALYZE针对分区表和索引计算全局统计信息,而不是直接针对整张表进行统计分析,这可能造成不正确的统计信息,例如distinct value的取值) For partitioned tables and indexes, ANALYZE gathers statistics for the individual partitions and then calculates the global statistics from the partition statistics.
(对于分区表,ANALYZE收集每个分区的统计信息,然后根据各个分区的信息计算出全局统计信息)For composite partitioning, ANALYZE gathers statistics for the subpartitions and then calculates the partition statistics and global statistics from the subpartition statistics.
(对于组合分区表,ANALYZE收集每个子分区的统计信息,然后据此计算各个分区和全局的统计信息) ANALYZE can gather additional information that is not used by the optimizer, such as information about chained rows and the structural integrity of indexes, tables, and clusters. DBMS_STATS does not gather this information.
(ANALYZE 会收集某些与优化器无关的信息,例如chainrow,索引、表和cluster的结构完整性,DBMS_STATS不会收集这些信息)No easy way of knowing which tables or how much data within the tables have changed. The DBA would generally re-analyze all of their tables on a semi-regular basis.
(没有办法知道哪些表或者表中的哪些数据发生了变化,dba通常会依据一定的规则重新收集所有标的统计信息)
DBMS_STATS Only available for Oracle 8i and higher.(在oracle8之后才可用)Statistics can be generated to a statistics table and can then be imported or exported between databases and re-loaded into the data dictionary at any time. This allows the DBA to experiment with various statistics.(统计信息可以被导出导入,方便了DBA的使用)DBMS_STATS routines have the option to run via parallel query or operate serially(可以并行或者串行执行).Can gather statistics for sub-partitions or partitions.(可以收集分区和子分区的统计信息)Certain DDL commands (ie. create index) automatically generate statistics, therefore eliminating the need to generate statistics explicitly after DDL command.(某些DDL语句可以自动收集统计信息)DBMS_STATS does not generate information about chained rows and the structural integrity of segments.(不会收集chainrow和段结构有效性的统计信息)The DBA can set a particular table, a whole schema or the entire database to be automatically monitored when a modification occurs. When ena