Oracle use index in the notes

tags: Oracle  SQL  Blog

1. Use the unequal operator (<>, !=)
In the following case, even if the column dept_id has an index, the query still performs a full table scan.

select * from dept where staff_num <> 1000;

However, such a query is really needed in development. Is there a solution to the problem?

Have!

By using the or syntax instead of the inequality to query, you can use the index to avoid full table scan: the above statement is changed to the following, you can use the index.


select * from dept shere staff_num < 1000 or dept_id > 1000;

2, use is null or is not null

Using is null or is nuo null also limits the use of the index because the database does not define a null value. If there are many nulls in the indexed column, the index will not be used (unless the index is a bitmap index, the bitmap index will be explained in detail in a future blog post). Using null in the sql statement can cause a lot of trouble.

The solution to this problem is to define the column that needs to be indexed as non-null (not null) when building the table.

3, using the function

If you do not use a function-based index, the optimizer ignores the index when using a function on a column with an index in the where clause. The following query will not use the index:

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

But the function is applied to the condition, the index can be effective, and the above statement can be changed to the following statement, and the index can be searched.

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

4, compare data types that do not match

Comparing mismatched data types is also one of the performance issues that are difficult to find. In the following example, dept_id is a varchar2 type field with an index on this field, but the following statement performs a full table scan.

select * from dept where dept_id = 900198;

This is because oracle will automatically convert the where clause to to_number(dept_id)=900198, which is the case of 3, which limits the use of the index. Change the sql statement to the following form to use the index

select * from dept where dept_id = '900198';

5, use the like clause

When using the like clause to query, the data needs to be traversed to judge all the records, the index can not play a role, this situation should be avoided.


Looking at the introduction of foreign websites, the operators that affect the use of indexes are as follows:

"IS NULL", "<>", "!=", "!>", "!<", "NOT", "NOT EXISTS", "NOT IN", "NOT LIKE", and "LIKE '%500'"


In the actual test, it was found that "IN" was not included, and NOT IN was really slow.

The original text is as follows: [url]http://www.orafaq.com/node/1918[/url]

Intelligent Recommendation

oracle study notes (25): index

What is an index? 1. The index is a mechanism for quickly querying the content in the table, similar to the directory of the Xinhua dictionary; 2. Used in a field / fields in the table, but when store...

Detailed use of combined index in Oracle

In Oracle, you can create a composite index, which is an index that contains two or more columns at the same time. In terms of the use of composite indexes, Oracle has the following characteristics: 1...

oracle text index create and use

[b][size=medium] First, Install Text Index[/size][/b] 1,The steps of context install on Oracle 10g. The steps of context uninstall (remove) on Oracle 10g. 2,The steps of context install on Oracle 9i. ...

How to monitor the use of ORACLE index or not

In database management and maintenance, we always have a problem: Will the index we create be used by some SQL statements? Another popular way of saying: Is the index I created an unused index (unused...

Notes on the use of z-index

Note: In the front-end development, we often encounter the use of z-index, at the same time, the development of the page's effects, positioning, layout display. It's all very important. I haven't noti...

More Recommendation

mysql use an index notes

Article Directory Mysql Index General index Creating an index Modify table configuration (add an index) Create table when specified directly Delete index syntax The only index Creating an index Delete...

Oracle study notes help index command

The help index command can view all the commands in oracle: The above commands will be learned slowly later....

Oracle database study notes (19)-index

Index concept The index is to build a binary tree on the columns of the table to achieve the purpose of greatly improving the query efficiency, but the index will affect the efficiency of addition, de...

Notes on the use of MySQL index to avoid index failure

In mysql, the index is established, but when it is used, it is necessary to ensure that the established index is used in the query of sql. So you need to pay attention to some problems in the process ...

Force the use of oracle index to query the performance of sql

Query the performance of sql Enforce indexing:...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top