ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Oracle Analyze 命令 详解

Oracle Analyze 命令 详解

原创 Linux操作系统 作者:roominess 时间:2012-03-30 16:38:37 0 删除 编辑

官网的链接如下:

http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_4005.htm#SQLRF01105

 

使用DBMS_STATS 收集统计信息参考:

Oracle Statistic 统计信息 小结

http://blog.csdn.net/tianlesoftware/article/details/4668723

 

Oracle 判断 并 手动收集 统计信息 脚本

http://blog.csdn.net/tianlesoftware/article/details/6445868

 

Oracle 分析及动态采样

http://blog.csdn.net/tianlesoftware/article/details/5845028

 

这篇只看官网对Analyze命令的相关说明。

 

一.Purpose

Use the ANALYZE statement tocollect statistics, for example, to:

--使用analyze命令可以收集统计信息,如:

(1)Collect ordelete statistics about an index or index partition, table or table partition,index-organized table, cluster, or scalar object attribute.

--收集或删除对象的统计信息

(2)Validate thestructure of an index or index partition, table or table partition, index-organizedtable, cluster, or object reference (REF).

--验证对象的结构

(3)Identifymigrated and chained rows of a table or cluster.

--确定table 或cluster的migrated 和chained rows。

 

For thecollection of most statistics, use the DBMS_STATS package, which letsyou collect statistics in parallel, collect global statistics for partitionedobjects, and fine tune your statistics collection in other ways.

--在大多数情况下,使用DBMS_STATS 包来收集统计信息。

 

Usethe ANALYZE statement (rather than DBMS_STATS) for statisticscollection not related to the cost-based optimizer:

--在如下两种情况下,使用analyze 命令要比dbms_stats 包好:

(1)To usethe VALIDATE or LIST CHAINED ROWS clauses

(2)To collectinformation on freelist blocks

 

二.Prerequisites

The schemaobject to be analyzed must be local, and it must be in your own schema or youmust have the ANALYZE ANY system privilege.

If you want tolist chained rows of a table or cluster into a list table, then the list tablemust be in your own schema, or you must have INSERT privilege on thelist table, or you must have INSERT ANY TABLE systemprivilege.

If you want tovalidate a partitioned table, then you must have the INSERT objectprivilege on the table into which you list analyzed rowids, or you must havethe INSERT ANY TABLE system privilege.

 

三. Syntax

 


详细语法如下:

   ANALYZE TABLE tablenameCOMPUTE|ESTIMATE|DELETE STATISTICS ptnOption options

   ANALYZE INDEX indexnameCOMPUTE|ESTIMATE|DELETE STATISTICS ptnOption options

   ANALYZE CLUSTER clusternameCOMPUTE|ESTIMATE|DELETE STATISTICS options

 

ptnOption

   PARTITION (partion)

   SUBPARTITION (subpartition)

 

options

   VALIDATE STRUCTURE [CASCADE][INTO tablename]

   LIST CHAINED ROWS [INTOtablename]

   COMPUTE|ESTIMATE STATISTICSFOR TABLE

   COMPUTE|ESTIMATE STATISTICSFOR ALL COLUMNS

   COMPUTE|ESTIMATE STATISTICSFOR ALL INDEXED COLUMNS

   COMPUTE|ESTIMATE STATISTICSFOR COLUMNS [SIZE int] column [SIZE int]

 

   When Estimating statistics youcan optionally

    specify

    ... ESTIMATE STATISTICSSAMPLE n ROWS

    ... ESTIMATE STATISTICSSAMPLE n PERCENT

 

四. Semantics

4.1 schema

Specify theschema containing the table, index, or cluster. If you omit schema, thenOracle Database assumes the table, index, or cluster is in your own schema.

 

4.2 TABLE table

Specify a tableto be analyzed. When you analyze a table, the database collects statisticsabout expressions occurring in any function-based indexes as well. Therefore,be sure to create function-based indexes on the table before analyzing thetable. Refer to CREATEINDEX for more information about function-based indexes.

--当使用analyze 收集表的统计信息时,也会自动收集函数索引的信息。

 

When analyzing atable, the database skips all domain indexesmarked LOADING or FAILED.

--在收集表的统计信息时,会跳过标记为Loading 或Failed 的索引。

 

For anindex-organized table, the database also analyzes any mapping table andcalculates its PCT_ACCESSS_DIRECT statistics. These statisticsestimate the accuracy of guess data block addresses stored as part of the localrowids in the mapping table.

 

Oracle Databasecollects the following statistics for a table. Statistics marked with anasterisk are always computed exactly. Table statistics, including the status ofdomain indexes, appear in the data dictionary views USER_TABLES, ALL_TABLES,and DBA_TABLES in the columns shown in parentheses.

--Oracle analyze 收集表的如下统计信息,其中加星号的会准确收集,收集的信息放在user_tables,all_tables 和 dba_tables 里的对应字段,下面的括号内是对应的字段:

 (1)Number of rows (NUM_ROWS)

(2)* Number of data blocks below thehigh water mark—the number of data blocks that have been formatted to receivedata, regardless whether they currently contain data or are empty (BLOCKS)

(3)* Number of data blocks allocatedto the table that have never been used (EMPTY_BLOCKS)

(4)Average available free space in eachdata block in bytes (AVG_SPACE)

(5)Number of chained rows(CHAIN_COUNT)

(6)Average row length, including therow overhead, in bytes (AVG_ROW_LEN)

 

4.2.1 Restrictions on AnalyzingTables 

Analyzing tables is subject to thefollowing restrictions:

--analyze table 有如下限制:

(1)You cannotuse ANALYZE to collect statistics on data dictionary tables.

     --不能收集datadictionary tables

(2)You cannotuse ANALYZE to collect statistics on an external table. Instead, youmust use the DBMS_STATS package.

--不能收集external table, 如果要收集外部表的统计信息,需要使用DBMS_STATS包.

(3)You cannotuse ANALYZE to collect default statistics on a temporary table.However, if you have already created an association between one or more columnsof a temporary table and a user-defined statistics type, then you canuse ANALYZE to collect the user-defined statistics on the temporarytable.

     --不能收集临时表的defaultstatistics.

(4)You cannotcompute or estimate statistics for the following column types:

--不用计算或者估算如下类型列的统计信息:

  REF columntypes, varrays, nested tables, LOB column types (LOB column types are notanalyzed, they are skipped), LONG column types, or object types.However, if a statistics type is associated with such a column, then OracleDatabase collects user-defined statistics.

    

4.2.2 partition_extension_clause

Specify thepartition or subpartition, or the partition or subpartition value, on which youwant statistics to be gathered. You cannot use this clause when analyzingclusters.

--可以在收集统计信息时指定分区,但是当是cluster 时,则不能收集。

If youspecify PARTITION and table is composite-partitioned, thenOracle Database analyzes all the subpartitions within the specified partition.

--如果指定的分区是组合分区,那么会收集所有的子分区。

 

4.3 INDEX index

Specify an indexto be analyzed.

Oracle Databasecollects the following statistics for an index. Statistics marked with anasterisk are always computed exactly. For conventional indexes, when youcompute or estimate statistics, the statistics appear in the data dictionaryviews USER_INDEXES, ALL_INDEXES, and DBA_INDEXES in thecolumns shown in parentheses.

--Analyze 收集索引的如下统计信息,加星号的准确收集。 对于conventionalindex,收集的统计信息可以通过user_indexes,all_indexes或者 dba_indexes 来查看,具体对应的字段查看括号里的内容。

(1)* Depth of the index from its rootblock to its leaf blocks (BLEVEL)

(2)Number of leaf blocks (LEAF_BLOCKS)

(3)Number of distinct index values(DISTINCT_KEYS)

(4)Average number of leaf blocks foreach index value (AVG_LEAF_BLOCKS_PER_KEY)

(5)Average number of data blocks foreach index value (for an index on a table) (AVG_DATA_BLOCKS_PER_KEY)

(6)Clustering factor (how well orderedthe rows are about the indexed values) (CLUSTERING_FACTOR)

 

For domainindexes, this statement invokes the user-defined statistics collection functionspecified in the statistics type associated with the index (see ASSOCIATESTATISTICS). If no statistics type is associated with the domain index,then the statistics type associated with its indextype is used. If nostatistics type exists for either the index or its indextype, then nouser-defined statistics are collected. User-defined index statistics appear inthe STATISTICS column of the data dictionaryviews USER_USTATS, ALL_USTATS, and DBA_USTATS.

--对于domain indexes,收集user-defined indexstatistics 信息,可以通过user_ustats,all_ustats 和dba_ustats 来查看。

 

官网对domain index 的解释:

domain index is an index designed for a specializeddomain, such as spatial or image processing. Users can build a domain index ofa given type after the designer creates the indextype.The behavior. of domain indexes is specific to an industry, a business function,or some other special purpose; you must specify it during cartridgedevelopment.

http://docs.oracle.com/cd/E11882_01/appdev.112/e10765/dom_idx.htm#ADDCI4409

 

Restriction on AnalyzingIndexes 

You cannotanalyze a domain index that is marked IN_PROGRESS or FAILED.

            --不能收集被标记为in_progress 和 failed的domainindex 统计信息。

 

Note:

When you analyzean index from which a substantial number of rows has been deleted, OracleDatabase sometimes executes a COMPUTE statistics operation (which canentail a full table scan) even if you request an ESTIMATE statisticsoperation. Such an operation can be quite time consuming.

--当我们收集统计信息时,如果表或索引上有大量的数据被删除,那么如果采用compute或者 estimage 来收集,可以会进行full table scan,因此会使用很多的时间。示例:

 SYS@anqing1(rac1)> analyze table ttestimate statistics;

Table analyzed.

SYS@anqing1(rac1)> analyze table ttcompute statistics;

Table analyzed.

SYS@anqing1(rac1)> analyze indexidx_tt_id compute statistics;

Index analyzed.

SYS@anqing1(rac1)> analyze indexidx_tt_id estimate statistics;

Index analyzed.

 

4.4 CLUSTER cluster

Specify acluster to be analyzed. When you collect statistics for a cluster, OracleDatabase also automatically collects the statistics for all the tables in thecluster and all their indexes, including the cluster index.

--当收集cluster 的信息时,DB 会自动收集cluster所有表和索引的统计信息,包括cluster index。

 

For both indexedand hash clusters, the database collects the average number of data blockstaken up by a single cluster key (AVG_BLOCKS_PER_KEY). These statistics appearin the data dictionary viewsALL_CLUSTERS, USER_CLUSTERS,and DBA_CLUSTERS.

 

4.5 validation_clauses

The validationclauses let you validate REF values and the structure of the analyzedobject.

 

4.5.1VALIDATE REF UPDATE Clause

Specify VALIDATE REF UPDATE tovalidate the REF values in the specified table, check the rowidportion in each REF, compare it with the true rowid, and correct it, ifnecessary. You can use this clause only when analyzing a table.

            --指定validate ref update来验证ref的值,检查时会那每个ref 的rowid 于表真实的rowid 进行比较,如果不一致,就修改ref 的值。

 

If the owner ofthe table does not have SELECT object privilege on the referencedobjects, then Oracle Database will consider them invalid and set them to null.Subsequently these REF values will not be available in a query, evenif it is issued by a user with appropriate privileges on the objects.

            --如果表的用户没有selectreferenced 对象的权限,那么DB 会认为他们是无效,并设置为空,因为在之后的查询中,ref 值就不可用,即使用户有权限的用户重新发布了ref values。

 

4.5.2 SET DANGLING TO NULL  

SET DANGLING TO NULL setsto null any REF values (whether or not scoped) in the specified tablethat are found to point to an invalid or nonexistent object.

 

4.5.3 VALIDATE STRUCTURE

Analyze 的语法如下:

ANALYZE INDEX

[PARTITION ]

[SUBPARTITION ]

VALIDATE STRUCTURE CASCADE

INTO

 

select * from index_stats;

 

ANALYZE TABLE

[PARTITION ]

[SUBPARTITION ]

VALIDATE STRUCTURE CASCADE

[INTO ]

 

ANALYZE CLUSTER VALIDATE STRUCTURE CASCADE

INTO

 

Specify VALIDATE STRUCTURE tovalidate the structure of the analyzed object. The statistics collected by thisclause are not used by the Oracle Database optimizer.

 

(1)For a table,Oracle Database verifies the integrity of each of the data blocks and rows. Foran index-organized table, the database also generates compression statistics(optimal prefix compression count) for the primary key index on the table.

--对于table,DB 验证每个datablock 和rows 的完整性。 对于index-organized table,db 也生成主键索引的compressionstatistics。

(2)For acluster, Oracle Database automatically validates the structure of the clustertables.

--对于cluster,db 自动验证clustertable 的structure。

(3)For apartitioned table, Oracle Database also verifies that each row belongs to thecorrect partition. If a row does not collate correctly, then its rowid isinserted into the INVALID_ROWS table.

--对于分区表,db 验证每个row 是否属于正确的分区,如果row 没有效验正确,那么这个rowid 会插入invalid_rows 表。

(4)For atemporary table, Oracle Database validates the structure of the table and itsindexes during the current session.

--对于临时表,db 会验证其structure 和 current session 期间的索引。

(5)For an index,Oracle Database verifies the integrity of each data block in the index andchecks for block corruption. This clause does not confirm that each row in thetable has an index entry or that each index entry points to a row in the table.You can perform. these operations by validating the structure of the table withthe CASCADE clause.

--对于索引,db 验证每个索引block 的完整性和block 是否损坏。 这个命令不会确实每个表的row 是否和索引的row 匹配。

 

Oracle Databasealso computes compression statistics (optimal prefix compression count) for allnormal indexes.

Oracle Databasestores statistics about the index in the data dictionaryviews INDEX_STATS and INDEX_HISTOGRAM.

            --Oracle 存储索引相关的statistics 在Index_stats和 index_histogram里。

 

If OracleDatabase encounters corruption in the structure of the object, then an errormessage is returned. In this case, drop and re-create the object.

--如果DB 在对象的structure里遇到corruption,那么会返回error,这种情况下需要drop和re-create 对象。

 

4.5.3.1 INTO 

The INTO clauseof VALIDATE STRUCTURE is valid only for partitioned tables.Specify a table into which Oracle Database lists the rowids of the partitionswhose rows do not collate correctly. If you omit schema, then the databaseassumes the list is in your own schema. If you omit this clause altogether,then the database assumes that the table is named INVALID_ROWS. The SQLscript. used to create this table is UTLVALID.SQL.

--into clause 仅对分区表有效。指定一个表来存放效验不正确的数据,如果忽略用户,则认为是的当前的用户,如果忽略表,则默认会认为表示INVALID_ROWS。创建这个表的sql 脚本是: $ORACLE_HOME/rdbms/admin/utlvalid.sql

 

[oracle@rac1 admin]$ cat utlvalid.sql

create tableINVALID_ROWS (

  owner_name         varchar2(30),

  table_name         varchar2(30),

  partition_name     varchar2(30),

  subpartition_name  varchar2(30),

  head_rowid         rowid,

  analyze_timestamp  date

);

 

4.5.3.2 CASCADE 

Specify CASCADE ifyou want Oracle Database to validate the structure of the indexes associatedwith the table or cluster. If you use this clause when validating a table, thenthe database also validates the indexes defined on the table. If you use thisclause when validating a cluster, then the database also validates all thecluster tables indexes, including the cluster index.

--当指定cascade 后,DB 在验证对象时也会关联其他的相关的对象,如索引关联表,表就关联索引。 如果是验证cluster,就关联cluster tables 和indexes,包含cluster index。

 

Bydefault, CASCADE performs a COMPLETE validation, which canbe resource intensive. Specify FAST if you want the database to checkfor the existence of corruptions without reporting details about thecorruption. If the FAST check finds a corruption, you can then usethe CASCADE option without the FAST clause to locate andlearn details about it.

--默认情况下,cascade 执行的是complete validation,如果我们指定FAST,那么只检查已经存在的corruptions,并且不报告corruption的详细信息。 如果FAST check 发现了corruption,那么可以使用cascade查看详细信息。

 

If you use thisclause to validate an enabled (but previously disabled) function-based index,then validation errors may result. In this case, you must rebuild the index.

 

4.5.3.3 ONLINE | OFFLINE 

Specify ONLINE toenable Oracle Database to run the validation while DML operations are ongoingwithin the object. The database reduces the amount of validation performed toallow for concurrency.

--指定online 后可以在DML时进行validate操作,但是这样会降低validation 的性能。

 

Note:

When youvalidate the structure of an object ONLINE, Oracle Database does notcollect any statistics, as it does when you validate the structure of theobject OFFLINE.

            --这里要注意,在前面我们提到当进行validate 时会将收集的信息存放到Index_stats 和index_histogram里,如果我们指定ONLINE,则不会将statistics 信息写入index_stats视图。

 

Specify OFFLINE,to maximize the amount of validation performed. This settingprevents INSERT, UPDATE, and DELETE statements fromconcurrently accessing the object during validation but allows queries. This isthe default.

            --OFFLINE 是默认值,这种也是性能最好的。 但是offline在验证期间会阻止对象的insert,update 和 delete操作。

所以对于在线业务可以考虑使用validatestructure online在线验证方法,但是validate strucutre online也有它的缺点,那就是online下结构验证信息不会写入index_stats 和 index_histogram 里。


4.5.3.4 Restriction on ONLINE

 You cannotspecify ONLINE when analyzing a cluster.

--online 不能使用于cluster 对象。

 

4.6 LIST CHAINED ROWS

有关chained rows的详细内容,下节在说明,先看该命令语法:

ANALYZE TABLE LISTCHAINED ROWS

INTO ;

 

ANALYZE CLUSTER LISTCHAINED ROWS INTO ;

 

LIST CHAINED ROWS letsyou identify migrated and chained rows of the analyzed table or cluster. Youcannot use this clause when analyzing an index.

--不能在索引上使用。

 

Inthe INTO clause, specify a table into which Oracle Database lists themigrated and chained rows. If you omit schema, then the database assumesthe chained-rows table is in your own schema. If you omit this clausealtogether, then the database assumes that the table isnamed CHAINED_ROWS. The chained-rows table must be on your local database.

执行该命令时通过into 来指定存放有链化数据的表,如果没有指定表,db 会假设表名为CHAINED_ROWS。

 

You can createthe CHAINED_ROWS table using one of these scripts:

--默认情况下没有创建这个表,我们要先创建这个表之后才能存放数据:

(1)UTLCHAIN.SQL usesphysical rowids. Therefore it can accommodate rows from conventional tables butnot from index-organized tables. (See the Note that follows.)

(2)UTLCHN1.SQL usesuniversal rowids, so it can accommodate rows from both conventional andindex-organized tables.

--可以使用上面的任一脚本来创建chained_rows 表。

 

If you create your own chained-rows table, then it must follow the format prescribed by oneof these two scripts.

 

If you areanalyzing index-organized tables based on primary keys (rather than universalrowids), then you must create a separate chained-rows table for eachindex-organized table to accommodate its primary-key storage.

Use the SQLscripts DBMSIOTC.SQL and PRVTIOTC.PLB to definethe BUILD_CHAIN_ROWS_TABLE procedure, and then execute this procedureto create an IOT_CHAINED_ROWS table for each such index-organizedtable.

 

4.7 DELETE STATISTICS

Specify DELETE STATISTICS todelete any statistics about the analyzed object that are currently stored inthe data dictionary. Use this statement when you no longer want Oracle Databaseto use the statistics.

When you usethis clause on a table, the database also automatically removes statistics forall the indexes defined on the table. When you use this clause on a cluster,the database also automatically removes statistics for all the cluster tablesand all their indexes, including the cluster index.

--当我们delete 表的statistics 时,DB 会自动remove表上所有索引statistics。

 

Specify SYSTEM ifyou want Oracle Database to delete only system (not user-defined) statistics.If you omit SYSTEM, and if user-defined column or index statistics werecollected for an object, then the database also removes the user-definedstatistics by invoking the statistics deletion function specified in the statisticstype that was used to collect the statistics.

 

五.Chained Rows相关说明

            每个Block的大小都是有限的,当单个数据块没有足够的空间来保存新建的一行记录或者更新的某行记录时,有两种解决方法:rowchainingrowmigration

Row chaining 就是我们说的chained rows,即链化现象。

 

在我之前的blog:

Oracle 数据块 Block 说明

http://blog.csdn.net/tianlesoftware/article/details/6414765

 

中的9.5 小节有说明: Chained and MigratedRows

 

Row chaining:

 


Row migration:

 

 

When a row ischained or migrated, the I/O needed to retrieve the data increases. Thissituation results because Oracle Database must scan multiple blocks to retrievethe information for the row.

         当产生大量的chained 或者 migrated 时,对会对I/O 产生影响。访问这些数据的速度就会开始变慢,因为额外的i/o以及与i/o相关的闩定都会增加访问时间,缓冲区缓存的效率开始下降,因为需要缓存两个块,而如果没有行迁移只需要缓存一个块。另外表的大小和复杂性都有所增加。

 

通过调整PCTFREE参数,可以有效避免链化现象。根据段空间管理方法的不同,相关的参数也不一样,默认表空间使用  Locallymanaged tablespaces ,其又分utomatic segment space management (ASSM) 和manual segment space management(MSSM). 这部分内容参考:

Oracle 自动段空间管理(ASSM:autosegment space management)

http://blog.csdn.net/tianlesoftware/article/details/4958989

 

默认情况下行迁移是禁止的,可以通过如下SQL 验证:

SYS@anqing1(rac1)> select d.row_movement from  dba_tables d where table_name='TT';

ROW_MOVE

--------

DISABLED

 

启用行迁移:

SQL>alter table table_name enable row movement;

 

必须在启用行迁移的情况下才能使用Shrink 和FlashbackTable,这部分具体参考:

Oracle 10g Shrink Table 详解

http://blog.csdn.net/tianlesoftware/article/details/4764254

 

Oracle Flashback 技术 总结

http://blog.csdn.net/tianlesoftware/article/details/4677378

 

既然chained row 对性能影响很大,我们就需要监控它。这个就是我们的analyze 的作用所在。 但是收集到有chaining的row 需要保存到一个表里。 等我们analyze 完之后查看这个表就知道有多少chaining的数据了。

         而且在我们执行analyze 命令之前,必须先创建这个表,否则就会报错。我们可以使用 $ORACLE_HOME/rdbms/admin/utlchain.sql 来创建这个表:

 

[root@rac1 ~]# cd $ORACLE_HOME/rdbms/admin

[root@rac1 admin]# cat utlchain.sql

create table CHAINED_ROWS (

 owner_name         varchar2(30),

 table_name         varchar2(30),

 cluster_name       varchar2(30),

 partition_name     varchar2(30),

 subpartition_name  varchar2(30),

 head_rowid         rowid,

 analyze_timestamp  date

);

 

创建完了就可以执行analyze命令:

ANALYZE TABLE LISTCHAINED ROWS

INTO ;

 

ANALYZE CLUSTER LISTCHAINED ROWS INTO ;

 

六. 示例

6.1 验证Chained row

--没有创建chained_rows表,这个是默认的表名:

SYS@anqing1(rac1)> select * from CHAINED_ROWS;

select * from CHAINED_ROWS

              *

ERROR at line 1:

ORA-00942: table or view does not exist

 

--在没有创建chained_row表的情况下,执行analyze 失败:

SYS@anqing1(rac1)> Analyze table tt list chained rows;

Analyze table tt list chained rows

*

ERROR at line 1:

ORA-01495: specified chain row table notfound

 

--创建表,在执行Analyze命令:

SYS@anqing1(rac1)>@?/rdbms/admin/utlchain.sql

SYS@anqing1(rac1)> Analyze table tt listchained rows;

 

Table analyzed.

 

--然后查询chained_row表:

SYS@anqing1(rac1)> select * fromCHAINED_ROWS;

no rows selected

 

--我这里是测试表,没有任何数据。官网的一个测试数据如下:

SELECT owner_name, table_name, head_rowid,analyze_timestamp

   FROM chained_rows

   ORDER BY owner_name, table_name, head_rowid, analyze_timestamp;

 

OWNER_NAME TABLE_NAME  HEAD_ROWID         ANALYZE_TIMESTAMP

---------- ----------  -----------------------------------

OE         ORDERS      AAAAZzAABAAABrXAAA25-SEP-2000

 

6.2 验证 structure

对于普通表直接执行命令即可:

SYS@anqing1(rac1)> analyze table ttvalidate structure;

Table analyzed.

 

--指定cascade和 online:

SYS@anqing1(rac1)> analyze table ttvalidate structure cascade online;

Table analyzed.

 

--对于分区表, db 验证每个row 是否属于正确的分区,如果row 没有效验正确,那么这个rowid 会插入invalid_rows 表。

--默认情况下invalid_rows表也没有创建,其创建脚本是:

$ORACLE_HOME/rdbms/admin/utlvalid.sql

 

有关分区表参考:

Oracle 分区表 总结

http://blog.csdn.net/tianlesoftware/article/details/4717318

 

我们创建了一个分区表pt。

 

SYS@anqing1(rac1)> analyze table ptvalidate structure;

analyze table pt validate structure

*

ERROR at line 1:

ORA-14508: specified VALIDATE INTO tablenot found

 

--对于分区表的验证就必须指定into 和invalid_rows.

SYS@anqing1(rac1)>@?/rdbms/admin/utlvalid.sql

SYS@anqing1(rac1)> analyze table ptvalidate structure into invalid_rows;

Table analyzed.

SYS@anqing1(rac1)> analyze table ptvalidate structure cascade online into invalid_rows;

Table analyzed.

 

--analyze 完成之后查看invalid_rows表即可:

SYS@anqing1(rac1)> select * frominvalid_rows;

no rows selected

 

6.3 删除统计信息

SYS@anqing1(rac1)> analyze table ttdelete statistics;

Table analyzed.

--该命令会删除表和其所有索引的statistics。

 

 

小结:

从Oracle 8i以后analyze具备”validate”验证功能,并且和DBMS_STATS包在功能上进行了划分,analyze 主要负责验证表和索引的结构以及链式行(chained and migrated rows)信息,DBMS_STATS包主要负责统计信息的管理。

          在以上的说明和测试这块也是花了很多的篇幅来说明analyze 在validate 和 list chained rows上的用法。

           

在开篇提到在如下两种情况下Analyze的效果要比DBMS_STATS包好。

(1)To usethe VALIDATE or LIST CHAINED ROWS clauses

(2)To collectinformation on freelist blocks

 

            Validate和 list chainedrows 已经说明,下篇主要看下dbms_stats和 analyze的具体区别。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15880878/viewspace-719947/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-02-24

  • 博文量
    118
  • 访问量
    186206