통계정보 수집할 대상 테이블 조회
/*==========================================================
통계정보 수집할 대상 테이블 조회 <= 매주 수요일에 수행
1) Non-partition table
2) 최근 1주일 동안 analyzed 하지 않은 table
3) 한번도 analyzed 를 하지 않은 table
4) insert + delete 된 row가 10% 이상인 table
5) Permanent table
==========================================================*/
select t.table_name, t.last_analyzed, t.num_rows, m.mod_rows
from user_tables t
left outer join ( select table_name, (nvl(inserts,0)+nvl(deletes,0)) mod_rows
from user_tab_modifications
where partition_name is null ) m
on t.table_name = m.table_name
and nvl(t.num_rows,0)/10 <= m.mod_rows /* insert + delete 된 row가 10% 이상인 table */
and m.mod_rows > 0
where t.tablespace_name is not null /* Non-partition table */
and DURATION is null /* Permanent table */
and ( t.last_analyzed <= sysdate-7 or t.last_analyzed is null )
/* 최근 1주일 동안 analyzed 하지 않은 table or 한번도 analyzed 를 하지 않은 table */
order by t.num_rows+m.mod_rows nulls first;
/* 작은 table 먼저 수행 */