Oracle收集统计信息的采样比例:
SELECT owner, segment_name, ROUND (SUM (bytes) / 1024 / 1024) size_mb,
case when sum(bytes)/1024/1024 < 1 then '100'
when sum(bytes)/1024/1024 >= 1 and sum(bytes)/1024/1024 < 1000 then '20'
when sum(bytes)/1024/1024 >= 1000 and sum(bytes)/1024/1024 < 100000 then '5'
when sum(bytes)/1024/1024 >= 100000 then '1' end estimate_percent
FROM dba_segments
WHERE segment_type like 'TABLE%' GROUP BY owner, segment_name
exec dbms_stats.gather_database_stats(estimate_percent=>100,degree=>4,cascade=>true,granularity=>'ALL');
exec dbms_stats.gather_table_stats(username,'tablename',estimate_percent=>100,degree=>4,cascade=>true,granularity=>'ALL');
user: username
tablename : 指定的tablename
estimate_percent: 采样比例,数据量大采样比例小,数据量小采样比例大.默认为100
degree : 收集时候的并行度.默认为null
cascade: 表示是否收集表对应的索引、列等的统计信息
granularity : ① ALL:采集Global、partition、subpartition等粒度统计信息。
② AUTO:根据分区类型,由Oracle确定统计信息采集粒度。
③ PARTITION:只采集partition粒度统计信息。
④ SUBPARTITION:只采集subpartition粒度统计信息