Index Enhancements   «Prev 

CREATE INDEX . . .COMPUTE STATISTICS

CREATE INDEX . . .COMPUTE STATISTICS
	
CREATE INDEX index_name ON table_name
  (column_list) COMPUTE STATISTICS;

CREATE INDEX Required keywords.
index_name Unique name for the index.
ON Required keyword.
table_name The unique name of the table the index will be based on.
column_list A list of columns whose values will make up the index.
COMPUTE STATISTICS Required keywords for computing statistics during index creation.

Gathering Statistics During a Rebuild

You can gather statistics on an index while rebuilding the index, as the following example shows:
SQL>alter index hr.emp_emp_id_pk rebuild compute statistics;
Index altered.
You save time by having the database gather statistics while it's rebuilding the index.

During index creations, you may be able to eliminate subsequent sorts by using the compute statistics clause of the create index command and gathering the statistics as the index is created.

Eliminate the Need to Query Undo Segments

When performing a query, Oracle will need to maintain a read-consistent image of the rows queried. If a row is modified by another user, the database will need to retrieve the earlier version of the blocks from the undo segment to see the row as it existed at the time your query began. Application designs that call for queries to frequently access data that others may be changing at the same time force the database to do more work, it has to look in multiple locations for one piece of data. Again, this is a design issue. DBAs may be able to size the undo segment areas to reduce the possibility of queries encountering errors, but correcting the fundamental problem requires a change to the application design.

What does the Database need to Know?

Oracle's optimizer relies on statistics when it evaluates the thousands of possible paths to take during the execution of a query. How you manage those statistics can significantly impact the performance of your queries.

Keep Your Statistics Updated

How often should you gather statistics? With each major change to the data in your tables, you should reanalyze the tables. If you have partitioned the tables, you can analyze them on a partition-by-partition basis. You can use the Automatic Statistics Gathering feature to automate the collection of statistics. By default, that process gathers statistics during a maintenance window from 11 P.M. to 7 A.M. each night and all day on weekends. Since the analysis job is usually a batch operation performed after hours, you can tune it by improving sort and full table scan performance at the session level. The result will be greatly enhanced performance for the sorts and full table scans the analysis performs.

Indexing using Oracle Database