如何查看统计信息是否成功收集

可通过dba_ind_statistics和dba_tab_statistics中的LAST_ANALYZED字段,观察是否完成了统计信息的收集,只有完成的收集工作才会记录在这两个视图中。

测试过程如下(测试环境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')
因为统计信息并未收集完全,所以此二表中的数据并无变化,再次收集统计信息完成后,表中信息才更新。