ORACLE 表分析 dbms_stats包


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,'表名');

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM