Gathering statistics
Statistics are the primary source of information for Oracle Optimizer. It is through the use of statistics that the optimizer attempts to determine the most efficient way to use resources to satisfy our query. The more accurate our statistics are, the better the optimizer's plan choice will be, and thus, the better our query performance will be.
To gather object statistics, we would use the DBMS_STATS
package. The following is an example of gathering table statistics:
-- Collect table statistics and all indexes that are created on that table SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS('hr', 'emp', estimate_percent => 100, cascade => TRUE);
The estimate_percent
parameter tells Oracle to estimate statistics based on a sample. In this example, we are directing Oracle to use 100 percent of the table data to collect statistics. cascade
tells Oracle to collect table statistics as well as statistics on the dependent objects, for example, indexes. TRUE
means to collect...