How does DBMS_STATS work?
How does DBMS_STATS work? I want to know what really happens when collecting statistics using DBMS_STATS. How does Oracle get the number of rows from a table?

    Requires Free Membership to View

    By submitting your registration information to SearchOracle.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchOracle.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

Basically, to get the number of rows and other information that DBMS_STATS calculates, Oracle has to read that table. So if your table is 1 million rows, then DBMS_STATS will read all 1 million rows of data. This can be quite time-consuming for larger objects. For this, you should ESTIMATE rather than COMPUTE statistics on the object. With ESTIMATE, Oracle does not read the entire table, but a sample of the table. You can define how much by telling Oracle to use 10% or 20%, or whatever value, of the table. Or, you can let Oracle decide how much of the table to use by specifying the AUTO_SAMPLE_SIZE option as follows:
EXEC DBMS_STATS.GATHER_TABLE_STATS( 
ownname=>'SCOTT', tabname=>'EMP', 
estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE);

This was first published in May 2006

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.