Oracle analysis table and Index

Source: Internet
Author: User
After the advent of the dbms_stats package, Oracle experts can collect statistics for CBO in a simple way. It is no longer recommended that you use older analysis tables and dbms_util

After the advent of the dbms_stats package, Oracle experts can collect statistics for CBO in a simple way. It is no longer recommended that you use older analysis tables and dbms_util

Analyze table tablename compute statistics;
Analyze index indexname compute statistics;

It is very beneficial to use CBO, and more reliable table information can be used, so that the execution plan can be more accurate. In 10 Gb, analyze is automatically performed, and previous versions need to be manually scheduled.

Generate Statistics and select a reasonable execution plan ..

The online document of Oracle describes the role of analyze as follows:
Use the ANALYZE statement to collect non-optimizer statistics, for example,:

1. Collect or delete statistics about an index or index partition, table or table partition, index-organized table, cluster, or scalar object attribute.
2. Validate the structure of an index or index partition, table or table partition, index-organized table, cluster, or object reference (REF ).
3. Identify migrated and chained rows of a table or cluster.

For the collection of statistics, I generally use the package dbms_stats to collect statistics and use it to make the CBO Optimization Selection execution plan more accurate.

It is best to collect statistics regularly to determine different collection cycles based on different services.

After the advent of the dbms_stats package, Oracle experts can collect statistics for CBO in a simple way. Currently, it is no longer recommended that you use the old-fashioned analysis table and dbms_utility method to generate CBO statistics. Old methods may even compromise SQL Performance, because they are not always able to capture high-quality information about tables and indexes. CBO uses Object statistics to select the best execution plan for all SQL statements.

Dbms_stats can effectively estimate the statistical data (especially for large partition tables), obtain better statistical results, and finally develop a faster SQL Execution Plan.

Listing A shows A demo execution of dbms_stats, where the options clause is used.

Execdbms_stats.gather_schema_stats (-
Ownname => 'Scott ',-
Options => 'Collect auto ',-
Estimate_percent => dbms_stats.auto_sample_size ,-
Method_opt => 'for all columns size repeat ',-
Degree => 15-
)

To fully understand the benefits of dbms_stats, You need to carefully understand every major pre-compiled command (directive ). Next let's study every command and learn how to use it to collect the highest quality statistics for the cost-based SQL optimizer.

Options Parameters

Use one of the four preset methods to control the refresh method of Oracle statistics:

Note that both gather stale and gather auto require monitoring. If you run the alter table xxx monitoring command, Oracle uses the dba_tab_modifications view to track the changed tables. In this way, you will know exactly how many insert, update, and delete operations have taken place since the last statistical data analysis.

Estimate_percent Option

The following estimate_percent parameter is a relatively new design that allows Oracle dbms_stats to automatically estimate the optimal percentage of a segment to be sampled when collecting statistics:
Estimate_percent => dbms_stats.auto_sample_size

To verify the accuracy of automatic sampling statistics, you can view the dba_tables sample_size column. One interesting thing is that Oracle selects a percentage of 5 to 20 for a sample size when automatic sampling is used. Remember, the better the quality of statistical data, the better the decision made by CBO.

Method_opt Option

The method_opt parameter of dbms_stats is especially suitable for refreshing statistics when the table and index data change. The method_opt parameter is also suitable for determining which columns require a histogram (histograms ).

In some cases, the distribution of each value in the index will affect whether CBO uses an index or executes a full table scan decision. For example, if the number of values specified in the where clause is asymmetrical, full table scan is more economical than index access.


When using the alter table xxx monitoring; command to implement Oracle table monitoring, you must use the auto option in dbms_stats. As shown in listing D, the auto option creates a histogram based on the data distribution and the way the application accesses the column (for example, the workload of a column determined by monitoring. Using method_opt => 'auto' is similar to using gather auto in the option parameter of dbms_stats. Begin
Dbms_stats.gather_schema_stats (
Ownname => 'Scott ',
Estimate_percent => dbms_stats.auto_sample_size,
Method_opt => 'for all columns size auto ',
Degree => 7
);
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.