測試過程如下(測試環境11.2.0.3 RAC):
1 創建一個200w行左右的測試表,數據源為dba_objects。
2 查看視圖中統計信息: select a.OWNER,a.INDEX_NAME,a.TABLE_NAME,a.LAST_ANALYZED from dba_ind_statistics a where table_name='STATEST1' and table_owner='YCR' select b.TABLE_NAME,b.OWNER,b.LAST_ANALYZED from dba_tab_statistics b where table_name='STATEST1' and owner in ('YCR')
通過觀察得到,索引的統計信息為索引創建時自動收集,表的統計信息為空。
3 手工收集統計信息,在執行約38秒時手工中斷(已通過測試,此表收集統計信息約需要60秒)
begin
dbms_stats.gather_table_stats(ownname => 'YCR',tabname => 'STATEST1' ,estimate_percent => 100 ,cascade => true);
end;
/ 4 查看視圖中統計信息: select a.OWNER,a.INDEX_NAME,a.TABLE_NAME,a.LAST_ANALYZED from dba_ind_statistics a where table_name='STATEST1' and table_owner='YCR' select b.TABLE_NAME,b.OWNER,b.LAST_ANALYZED from dba_tab_statistics b where table_name='STATEST1' and owner in ('YCR')
因為統計信息并未收集完全,所以此二表中的數據并無變化,再次收集統計信息完成后,表中信息才更新。