Improvement of AUTO sampling statistics gathering feature in Oracle Database 11g
By Maria Colgan-Oracle on Jan 28, 2008
exec dbms_stats.gather_table_stats(null, 'BIGT', estimate_percent => 1);It is not always easy for users to pick the appropriate sampling percentage. If the specified sampling percentage is too high, it can take longer to gather statistics. On the contray, if the data is skewed and the specified sampling percentage is too low, the resulting statistics can be inaccurate. For this reason, Oracle introduced the AUTO value for the estimate_percent parameter. For example, you can gather statistics on BIGT as follows:
exec dbms_stats.gather_table_stats(null, 'BIGT', estimate_percent => dbms_stats.auto_sample_size);
|column name||column type|
Table 1 gives the elapsed time of gathering statistics on the Lineitem table by different sampling percentages.
|Sampling Percentage||Elapsed Time (sec)|
|100% sampling (Compute)||18772|
|Auto sampling in Oracle 10g||2935|
|Auto sampling in Oracle 11g||1908|
Table 1: Statistics gathering time on 230G TPC-D Lineitem Table Using Different Estimate Percentages We also compare the quality of the statistics gathered using different estimate percentages. Among all the statistics of a column, number of distinct values (NDV) is the one whose accuracy used to be an issue. We define the accuracy rate of NDV of a column as follows:
accuracy rate = 1 - (|estimated NDV - actual NDV|)/actual NDV.The accuracy rate ranges from 0% to 100%. The higher the accuracy rate is, the more accurate the gathered statistics are. Since 100% sampling always lead to an accuracy rate of 100%, we do not report it. We focus on the columns which has at least one statistics accuracy rate below 99.9% when using different estimate percentages. Table 2 illustrates the accurate rates of the columns.
|Column Name||Actual NDV||Auto Sampling in Oracle 11g||1% Sampling|
Table 2: Accuracy Rate of Gathering NDV LineItem Using Different Estimate Percentages In short, the elapsed time of ''AUTO sampling in Oracle 11g'' is 10 times faster than 100% sampling but yields the statistics of similar quality (accuracy rate close to 100%).