Database indexes failed several cases (oracle)

The purpose of creating the index is to avoid Oracle full table scan data, improve query performance, but if the sql statement written well cause the index fails, it will affect data query efficiency. The following situations can lead to failure of the index:

1 No WHERE clause

   As we all know, add index fields will need to use the appropriate take effect only after the conditions where, even if the query did not, it certainly will not be used in the index.

2. IS NULL and IS NOT NULL

    select ... from emp where colnum is null; colnum index of the column will fail

3. WHERE clause function

If you do not use function-based index, the where clause when using the function of the column indexes exist, the optimizer will ignore these indexes. E.g:

select * from staff where trunc(birthdate) = '01-MAY-82';

But the function is applied on the condition, the index is in force, the above statement into the following statement, you can search through the index.

select * from staff where birthdate < (to_date('01-MAY-82') + 0.9999);

     Note: For MIN, MAX function, Oracle still use the index.

4. LIKE '% T' fuzzy query

  select * from student where name like 'aaa%'; // 'aaa%' will be used in the index

  select * from student where name like '% aaa'; // '% aaa' or '_aaa' does not use the index

5. WHERE clause is not equal to the operating

Does not mean operations include:! <>, =, NOT colum> =, NOT colum <=??

For this restriction by OR Alternatively, for example: colum <> 0 ===> colum> 0 OR colum <0

6. The index range is not equal and in combination

SELECT emp_id, emp_m, salary_q ... FROM emp WHERE job='manager' AND deptno>10

job and deptno are non-unique index, oracle will not merge index under these conditions, it will only use the first index.

7. Comparison of the data type does not match

dept_id is a varchar2 type field, there is an index on this field, but the following statement will execute a full table scan.

select * from temp where dept_id = 100101;

This is because the oracle will automatically convert the where clause to to_number (dept_id) = 900198, corresponding to the use function, thus limiting the use of the index. Correct wording is as follows:

select * from temp where dept_id = '100101';

 

 

Reference article: https://www.cnblogs.com/orientsun/archive/2012/07/05/2577351.html , https://blog.csdn.net/dummyo/article/details/84194086 , HTTPS: // the WWW .cnblogs.com / lanseyitai1224 / p / 9217177.html

 

 

Published 118 original articles · won praise 59 · views 490 000 +

Guess you like

Origin blog.csdn.net/u012255097/article/details/102792683