Oracle ANALYZE Statement: Old-Style Table and Index Statistics Collection Explained

Oracle ANALYZE Statement: Old-Style Table and Index Statistics Collection

The ANALYZE statement in Oracle Database is a legacy tool used to collect statistics on tables and indexes. These statistics help the database optimizer make decisions about the most efficient way to execute SQL queries. Although Oracle now recommends using the DBMS_STATS package for statistics gathering, understanding ANALYZE is essential for maintaining legacy systems or interpreting older scripts.

Purpose of the ANALYZE Statement

  • Collect statistics about tables, indexes, and clusters to help the optimizer generate efficient execution plans.

  • Validate structures of database objects.

  • Identify migrated and chained rows in tables or clusters.

  • **Delete existing statistics** from objects.

Note: The use of ANALYZE for optimizer statistics is now obsolete. Oracle recommends DBMS_STATS for all modern statistics collection tasks

Code Breakdown and Explanation

Sample SQL Command

1analyze table employees compute statistics;
2
3analyze table employees estimate statistics sample 100 rows;
4
5analyze table employees estimate statistics sample 15 percent;
6
7analyze index employees_ind compute statistics;

1. analyze table employees compute statistics;

2. analyze table employees estimate statistics sample 100 rows;

3. analyze table employees estimate statistics sample 15 percent;

4. analyze index employees_ind compute statistics;

Key Points and Insights

Best Practices

References

By understanding the legacy ANALYZE statement and its modern alternatives, you can better maintain older Oracle systems and ensure your database statistics are always up to date for optimal performance.

Posts in this series