To avoid unexpected execution plan changes some people say that we must set DBMS_STATS estimate_percent should always be to 100.
I would like to know if you agree with this ?
We recommend you use auto sample size.
First up, plans can and will still change when you use an estimate of 100%. This is because plans can change for reasons unrelated to statistics (e.g. adding an index), and as your data changes over time, a different plan may become faster than the current fastest plan. So using an estimate of 100% to stop plan changes won't work.
Next, while a 100% sample will give the best stats, it is also the slowest. Auto sampling is designed to give the best performance with the highest accuracy:
This algorithm reads all rows and produces statistics that are nearly as accurate as statistics from a 100% sample. https://docs.oracle.com/en/database/oracle/oracle-database/26/tgsql/gathering-optimizer-statistics.html#GUID-88E321BF-445E-40BD-83A2-9EA107689B2F Auto sample size is also a prerequisite for some more recent optimizer features, such as:
* Incremental statistics
* Concurrent statistics
* New histogram types
e.g. with an estimate of 100%, the database will create height-balanced histograms. With auto, it can create Top-N or hybrid histograms instead:
create table t ( c1, c2 ) as
select level, floor ( 50000 / level )
connect by level <= 100000;
exec dbms_stats.gather_table_stats ( user, 't', estimate_percent => 100 );
select column_name, histogram
from user_tab_cols
where table_name = 'T';
COLUMN_NAME HISTOGRAM
C1 HEIGHT BALANCED
C2 HEIGHT BALANCED
exec dbms_stats.gather_table_stats ( user, 't', estimate_percent => dbms_stats.auto_sample_size );
select column_name, histogram
from user_tab_cols
where table_name = 'T';
COLUMN_NAME HISTOGRAM
C1 HYBRID
C2 TOP-FREQUENCY