analyze table & index

为了利用索引提高效率,可以单独对该字段或该表用analyze语句进行分析,对该列搜集足够的统计数据,使ORACLE在查询选择性较高的值时能用上索引。

ANALYZE   TABLE   tablename   COMPUTE|ESTIMATE|DELETE   STATISTICS

analyze   table   tablename   compute   statistics
  ------------------------------------------
  对全表进行统计,然后生成统计信息,数据量大的时候  
  速度很慢,对temp表要求也很高。

  analyze   table   tablename   ESTIMATE   STATISTICS
  SAMPLE     XXX     PERCENT
  ------------------------------------------
  抽取表中的部分数据进行统计,最好> =20%,否则得不到
  准确的统计信息

  analyze   table   tablename   delete   statistics
  -----------------------------------------
    删除表上的统计信息

当然索引也是可以analyze的,用法和table一样。
分析表后可以使用更可靠的table信息,从而执行计划也可以更准确一些,10g会自动analyze,之前的版本需要手动定期生成统计信息,选择合理的执行计划。
Use the ANALYZE statement to collect non-optimizer statistics, for example, to:
1、Collect or delete statistics about an index or index partition, table or table partition, index-organized table, cluster, or scalar object attribute.
2、Validate the structure of an index or index partition, table or table partition, index-organized table, cluster, or object reference (REF).
3、Identify migrated and chained rows of a table or cluster.

猜你喜欢

转载自polyangel.iteye.com/blog/1319218