Oracle分析表和索引(analyze)

分析表

analyze table tablename compute statistics;

分析索引

analyze index indexname compute statistics;

该语句生成的统计信息会更新user_tables这个视图的统计信息,分析的结果被Oracle用于基于成本的优化生成更好的查询计划

对于使用CBO(Cost-Base Optimization)很有好处,可以使用更可靠的table信息,从而执行计划也可以更准确一些,在10g会自动analyze,之前的版本需要手动定期

analyze table 一般可以指定分析: 表,所有字段,所有索引字段,所有索引。 若不指定则全部都分析。

sql 复制代码
SQL> analyze table my_table compute statistics;  

SQL> analyze table my_table compute statistics for table for all indexes for all columns;   

SQL> analyze table my_table compute statistics for table for all indexes for all indexed columns;

其中:

SQL> analyze table my_table compute statistics;  

等价于:

SQL> analyze table my_table compute statistics for table for all indexes for all columns;

sample:

sql 复制代码
analyze table t1 compute statistics for table;
analyze table t2 compute statistics for all columns;
analyze table t3 compute statistics for all indexed columns;

analyze table t5 compute statistics for all indexes; 

analyze table t4 compute statistics;     (不指定)

另外,可以删除分析数据:

sql 复制代码
SQL> analyze table my_table delete statistics;

SQL> analyze table my_table delete statistics for table for all indexes for all indexed columns;
相关推荐
下雨天u9 分钟前
maven dependencyManagement标签作用
java·数据库·maven
代码配咖啡13 分钟前
国产数据库工具突围:SQLynx如何解决Navicat的三大痛点?深度体验报告
数据库
清酒伴风(面试准备中......)34 分钟前
小白学编程之——数据库如何性能优化
数据库·oracle·性能优化
The Future is mine1 小时前
SQL Server中delete table和truncate table删除全表数据哪个快?
数据库
瀚高PG实验室1 小时前
HGDB插入超长字段报错指示列名的问题处理
数据库
好吃的肘子1 小时前
MongoDB 高可用复制集架构
数据库·mongodb·架构
兮兮能吃能睡2 小时前
Python之with语句
数据库·python
不穿铠甲的穿山甲2 小时前
MySQL-数据库分布式XA事务
数据库·分布式·mysql
Hadoop_Liang2 小时前
解决Mawell1.29.2启动SQLException: You have an error in your SQL syntax问题
大数据·数据库·maxwell
码上飞扬3 小时前
MongoDB数据库深度解析:架构、特性与应用场景
数据库·mongodb·架构