统计信息收集

1 按用户收集统计信息


exec dbms_stats.gather_schema_stats(ownname=>'htuser',estimate_percent=>dbms_stats.auto_sample_size,

method_opt=>'for all columns size auto',degree=>8,cascade=>true);


2 按表收集统计信息

exec dbms_stats.gather_table_stats(ownname=>'htuser',tabname=>'ht_test_fy', estimate_percent=>100,method_opt=>'for all columns size repeat',no_invalidate=>false,degree=>8,cascade=>true);


3  查看表的统计信息

  select t.OWNER, t.TABLE_NAME, t.NUM_ROWS, t.LAST_ANALYZED, t.PARTITIONED

  from dba_tables t where t.TABLE_NAME in ('a','b', 'c')

如果上次收集统计信息时间在1周以前,或者num_rows和当前表中记录数差距较大,应对该表新收集统计信息:

  


4 索引的统计信息

  select owner,table_name,index_name,last_analyzed from dba_indexes where table_name ='&table_name';


请使用浏览器的分享功能分享到微信等