分析表
analyze table tablename compute statistics;
分析索引
analyze index indexname compute statistics;
該語句生成的統計信息會更新user_tables這個視圖的統計信息,分析的結果被Oracle用于基于成本的優化生成更好的查詢計劃
對于使用CBO(Cost-Base Optimization)很有好處,可以使用更可靠的table信息,從而執行計劃也可以更準確一些,在10g會自動analyze,之前的版本需要手動定期
analyze table 一般可以指定分析: 表,所有字段,所有索引字段,所有索引。 若不指定則全部都分析。
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:
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> analyze table my_table delete statistics;SQL> analyze table my_table delete statistics for table for all indexes for all indexed columns;