为了利用索引提高效率,可以单独对该字段或该表用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.
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.
本文介绍如何通过ANALYZE语句收集表和索引的统计数据,以便ORACLE在查询时能够充分利用索引,提高数据库查询效率。重点包括全表统计、部分数据抽样统计以及统计信息的管理和维护。
141

被折叠的 条评论
为什么被折叠?



