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