Analysis of four categories of Oracle index Scanning

Source: Internet
Author: User

When learning Oracle, you may encounter Oracle index scanning problems. Here we will introduce the solutions to Oracle index scanning problems. Here we will share with you. There are four types of Oracle index scans, depending on the index type and where restriction conditions:
◆ Unique index scan)
◆ Index range scan)
◆ Full index scan)
◆ Index fast full scan)

(1) unique index scan)

A single ROWID is often returned for finding a value through a unique index. If the unique Index consists of multiple columns (composite index), at least the bootstrap column of the composite index must be included in the query. For example, create an index: create index idx_test on emp (ename, deptno, loc ). The select ename from emp where ename = 'jack' and deptno = 'dev' statement can use this index. If this statement returns only one row, the access method is called unique index scan. The select ename from emp where deptno = 'dev' statement does not use this index, because the where clause does not have a bootstrap column. If the UNIQUE or primary key constraint exists (it ensures that the statement only accesses a single row), Oracle often implements a UNIQUE scan.

Examples of using uniqueness constraints:

 
 
  1. SQL> explain plan for  
  2. select empno,ename from emp where empno=10;  
  3. Query Plan  
  4. SELECT STATEMENT [CHOOSE] Cost=1 
  5. TABLE ACCESS BY ROWID EMP [ANALYZED]  
  6. INDEX UNIQUE SCAN EMP_I1 

(2) index range scan)

Use one index to access multiple rows of data. The same as above, if the index is a combination index, as shown in (1, in addition, the select ename from emp where ename = 'jack' and deptno = 'dev' statement returns multiple rows of data, although the statement still uses the combined index for query, the access method is called index range scan. A typical use of index range scanning on a unique index is a predicate (where restriction) range operators (such as >,<, >,>=, <=, and between) are used)

Example of using index range scan:

 
 
  1. SQL> explain plan for select empno,ename from emp  
  2. where empno > 7876 order by empno;  
  3. Query Plan  
  4. SELECT STATEMENT [CHOOSE] Cost=1 
  5. TABLE ACCESS BY ROWID EMP [ANALYZED]  
  6. INDEX RANGE SCAN EMP_I1 [ANALYZED] 

In a non-unique index, the predicate col = 5 may return multiple rows of data, so index range scanning is used for non-unique indexes.

Three cases of using index rang scan:
(A) Use the range operator on the unique index column (><>>=<=)
(B) on the composite index, only some columns are used for query, resulting in multiple rows being queried.
(C) any queries on non-unique index columns.

(3) full index scan)

The full Oracle index scan corresponds to the full table scan. In some cases, full Oracle index scanning may be performed instead of range scanning. Note that full Oracle index scanning is only effective in CBO mode. The CBO performs a full Oracle index scan only when it finds that the full Oracle index scan is more effective than the full table scan. In this case, the queried data must be directly obtained from the index.

Example of a full Oracle index scan:

 
 
  1. An Index full scan will not perform single block i/o's and so it may prove to be inefficient.  
  2. e.g.  
  3. Index BE_IX is a concatenated index on big_emp (empno, ename)  
  4. SQL> explain plan for select empno, ename from big_emp order by empno,ename;  
  5. Query Plan  
  6. SELECT STATEMENT [CHOOSE] Cost=26 
  7. INDEX FULL SCAN BE_IX [ANALYZED] 

(4) index fast full scan)

Scanning all data blocks in an index is similar to full scan, but it does not sort the queried data, that is, the data is not returned in the order of sorting. In this access method, you can use the multi-block READ function or parallel read to obtain the maximum throughput and shorten the execution time.

Example of fast index scanning:

 
 
  1. SQL> explain plan for select empno,ename from big_emp;  
  2. Query Plan  
  3. SELECT STATEMENT [CHOOSE] Cost=1 
  4. INDEX FAST FULL SCAN BE_IX [ANALYZED]  
  5. SQL> explain plan for select ename from big_emp;  
  6. Query Plan  
  7. SELECT STATEMENT [CHOOSE] Cost=1 
  8. INDEX FAST FULL SCAN BE_IX [ANALYZED] 
  1. Oracle management tool-Overview of Oracle SQL Handler Functions
  2. Master talk about Oracle index Scanning
  3. Six-minute Oracle full table Scan
  4. Code Description Oracle Selectivity
  5. About the sequence of Oracle execution plans

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.