Oracle

Gather Statistics in Oracle

DBAs should gather statistics periodically for objects where the statistics become stale over time because of changing data volumes or changes in column values. New statistics should be gathered after a schema object’s data or structure are modified in ways that make the previous statistics inaccurate. For example, after loading a significant number of rows into a table, collect new statistics on the number of rows. After updating data in a table, you do not need to collect new statistics on the number of rows, but you might need new statistics on the average row length.

Because the cost-based approach relies on statistics, you should generate statistics for all tables and clusters and all indexes accessed by your SQL statements before using the cost-based approach. If the size and data distribution of the tables change frequently, then regenerate these statistics regularly to ensure the statistics accurately represent the data in the tables.

Oracle generates statistics using the following techniques:

  • Estimation based on random data sampling
  • Exact computation
  • User-defined statistics collection methods

To perform an exact computation, Oracle requires enough space to perform a scan and sort of the table. If there is not enough space in memory, then temporary space might be required. For estimations, Oracle requires enough space to perform a scan and sort of only the rows in the requested sample of the table. For indexes, computation does not take up as much time or space.

Continue reading “Gather Statistics in Oracle”
Oracle

Importing and Exporting Optimizer Statistics – I

You can export and import optimizer statistics from the data dictionary to user-defined statistics tables. You can also copy statistics from one database to another database.
Importing and exporting are especially useful for testing an application using production statistics.
Developers often want to tune query plans in a realistic environment before deploying applications. A typical scenario would be to use DBMS_STATS.EXPORT_SCHEMA_STATS to export schema statistics from a production database to a test database.

Continue reading “Importing and Exporting Optimizer Statistics – I”