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;
相关推荐
syt_biancheng14 分钟前
Redis初识
数据库·redis·缓存
cmes_love41 分钟前
股票逐笔level2历史行情下载十档订单薄五档tick分钟下载分享
数据库·区块链
仙俊红42 分钟前
SQL 调优需要掌握的知识
数据库·sql
fofantasy1 小时前
NSK LH12AN 微型导轨技术手册
运维·网络·数据库·经验分享·规格说明书
杨运交1 小时前
[032][缓存模块]基于Redis Bitmap的用户行为统计实战:签到与日活分析
数据库·redis·缓存
一 乐2 小时前
家政服务管理系统|基于springboot + vue家政服务管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·家政服务管理系统
努力成为AK大王4 小时前
并发编程的核心挑战、优化方案与核心知识点总结
java·开发语言·数据库
En^_^Joy4 小时前
Django开发:模板系统入门指南
数据库·django·sqlite
无关86885 小时前
Redis Bitmaps 用户签到系统设计方案
数据库·redis·缓存