dbms_stats包的常用几个信息统计分析

来源:互联网 发布:mac粉饼专柜价格表 编辑:程序博客网 时间:2024/06/13 01:18
1.分析表


begin


dbms_stats.gather_table_stats (


  ownname          => 'TEST',


  tabname          => 'STUDENT',


  estimate_percent => dbms_stats.AUTO_SAMPLE_SIZE,


  degree           => 4,


  cascade          => TRUE);


end;


2.分析用户


begin


dbms_stats.gather_schema_stats(


    ownname          => 'TEST',


    estimate_percent => dbms_stats.AUTO_SAMPLE_SIZE,


    degree           => 4,


    cascade          => TRUE);


end;


3.分析索引


begin


dbms_stats.gather_index_stats(


  ownname          => 'TEST',


  indname          => 'IDX_STUDENT_BIRTH',


  estimate_percent => dbms_stats.AUTO_SAMPLE_SIZE,


  degree           => 4);


end;


一般来说,ORACLE都会锁定统计信息,这是为了稳定执行计划。如果在进行表分析是发现表被锁住,需要进行解锁:


①按用户schema解锁:EXEC DBMS_STATS.UNLOCK_schema_STATS('user');


②按表模式解锁:先查出被锁定的表select table_name from user_tab_statistics where stattype_locked is not null;然后exec dbms_stats.unlock_table_stats(user,'表名');
原创粉丝点击