How to maintain indexes in Oracle databases

Source: Internet
Author: User

The following articles mainly introduce the maintenance of indexes in Oracle databases. If you are curious about the actual operation and application of indexes in Oracle databases, the following articles will unveil its mysteries. I hope you will gain some benefits after browsing.

Index selectivity = number of different keywords in the index/total number of rows in the table:

 
 
  1. Select I. distinct_keys/t. num_rows
  2. From
  3. User_indexes I,
  4. User_tables t
  5. Where I. table_name = 'table name'
  6. And I. index_name = 'index name'
  7. And I. table_name = t. table_name
  8. /

You can query USER_TAB_COLUMNS to understand the selectivity of each column.

The number of different values of all rows in this column in the table:

 
 
  1. Select
  2. Column_name,
  3. Num_distinct
  4. From user_tab_columns
  5. Where table_name = 'table name'
  6. /

Column selectivity = the total number of rows in the NUM_DISTINCT/table. querying USER_TAB_COLUMNS helps to measure the selectivity of each column, but it does not accurately measure the selectivity of column Union combinations. To measure the selectivity of a group of columns, You need to manually create an index based on the group of columns and re-analyze the table.

Determine the actual fragmentation of the Index

With the use of the database, it is inevitable to insert, update, and delete the basic table. As a result, the leaf row is deleted from the index, causing fragmentation of the index. The more frequently the table is inserted and deleted, the higher the degree of index fragmentation. The generation of fragments increases the I/O cost for accessing and using the index. Indexes with high fragmentation must be rebuilt to maintain optimal performance.

1) Use the verify Index Command to verify the index.

This will fill in valuable index information in the index_stats table.

 
 
  1. Validate index username. index name
  2. /

2) query the index_stats table to determine the percentage of leaf rows that are deleted and not filled in the index.

 
 
  1. select  
  2. name,  
  3. del_lf_rows,  
  4. lf_rows,  
  5. round((del_lf_rows/(lf_rows+0.0000000001))*100) "Frag Percent"  
  6. from index_stats  
  7. /  

3) if the fragmentation of the leaf row of the index exceeds 10%, rebuild the index.

 
 
  1. Alter index username. index name rebuild
  2. Tablespace name
  3. Storage (initial Value: next extension value)
  4. Nologging
  5. /

4) if the index cannot be rebuilt out of space or other considerations, you can sort the index.

 
 
  1. Alter index username. index name coalesce
  2. /

5) clear analysis information

 
 
  1. Analyze index username. index name
  2. Delete statistics
  3. /

The above content describes the items related to index maintenance in the Oracle database, hoping to help you in this regard.

Article by: http://database.51cto.com/art/200703/43583.htm

Related Article

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.