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