One of the pitfalls of indexing using indexes: Leading columns that do not use a composite index cause the query to not use the index
In Oracle, we often assume that indexed, SQL queries use the index as we would like, in fact, Oracle only uses indexes under certain conditions, and here we sum up the 1th: Oracle uses indexes when they include leading columns in the condition. This means that the first column in the index must be used in the query condition, as shown in the following example
Sql> select * from tab;
Tname Tabtype Clusterid
------------------------------ ------- ----------
BONUS TABLE
DEPT TABLE
DUMMY TABLE
EMP TABLE
Salgrade TABLE
Establish a federated index (note indexed column order for composite indexes)
Sql> CREATE INDEX EMP_ID1 on EMP (EMPNO,ENAME,DEPTNO);
Index created
Establish a single key index
Sql> CREATE INDEX Emp_id2 on EMP (SAL);
Index created
Sql> Select Table_name,index_name from User_indexes
2-access ("EMP".) EMPNO "=7777 and" EMP. " ename "= ' RICH ' and ' EMP '." Dep
TNO "=30)
Note:rule Based Optimization
Rows selected
All the columns of the composite index are used, so the index is gone, and because all the selected columns are included in the index, only the index range scan
Select Empno from emp where empno=7777 and Ename= ' RICH ' and deptno=30;
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.