Oracle index monitoring and foreign key Indexing

Source: Internet
Author: User

The Oracle monitoring index feature allows us to roughly determine whether an index is used. This is because the index is monitored when statistics are collected in Oracle 10 Gb, which is not produced by SQL statements. In the case of 11g, there is no type. Second, if a sub-table has a foreign key, will the index be monitored when the primary table is operated? This topic is described below.

1. General Index Monitoring

-- Demo Environment
SQL> select * from v $ version where rownum <2;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-64bit Production

-- Create a master table
SQL> create table ptb (deptno number constraint ptb_pk primary key, dname varchar2 (20 ));

Table created.

-- Copy data from scott. dept account
SQL> insert into ptb select deptno, dname from dept;

4 rows created.

SQL> commit;

Commit complete.

-- Enable index monitoring
SQL> alter index ptb_pk monitoring usage;

-- Collect statistics for the master table
SQL> exec dbms_stats.gather_table_stats ('Scott ', 'ptb', cascade => true );

PL/SQL procedure successfully completed

SQL> select * from v $ object_usage where index_name = 'ptb _ pK ';

INDEX_NAME TABLE_NAME MON Use START_MONITORING END_MONITORING
---------------------------------------------------------------------------------------------------
PTB_PK ptb yes no 03/22/2013 17:15:37

-- Pay attention to the above situation. When collecting statistical information, indexes are not monitored for use, and 10 Gb indexes are monitored.
-- Enable autotrace below
SQL> set autot trace exp;

SQL> select * from ptb where deptno = 10;

Execution Plan
----------------------------------------------------------
Plan hash value: 3991869509

Bytes --------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
Bytes --------------------------------------------------------------------------------------
| 0 | select statement | 1 | 12 | 1 (0) | 00:00:01 |
| 1 | table access by index rowid | PTB | 1 | 12 | 1 (0) | 00:00:01 |
| * 2 | index unique scan | PTB_PK | 1 | 0 (0) | 00:00:01 |
Bytes --------------------------------------------------------------------------------------

SQL> set autot off;
SQL> select * from v $ object_usage where index_name = 'ptb _ pK'; -- the index usage is monitored

INDEX_NAME TABLE_NAME MON Use START_MONITORING END_MONITORING
---------------------------------------------------------------------------------------------------
PTB_PK ptb yes 03/22/2013 17:15:37

  • 1
  • 2
  • 3
  • Next Page

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.