Some cases of failure index

  1. Implicit conversion lead to failure of the index. This should pay attention to. Also in development often make mistakes.

Since the fields of the table is defined as tu_mdn varchar2 (20), but in the field as a query to the conditions where the number passed to the type Oracle, this will lead to failure of the index.

Bad example: select from test where tu_mdn = 13333333333;

Examples of correct: select from test where tu_mdn = '13333333333';

  1. Calculates the index column failure cause index, I mean index column operations include (+, - ,, /,!, Etc.)

Bad example: select from test where id-1 = 9;

Examples of correct: select from test where id = 10;

  1. Using Oracle internal function failure results in an index based on the index function should be created for such cases.

Bad example: select from test where round (id) = 10; described, when the index has been ineffective id

Examples of correct: first establish a functional index, create index test_id_fbiidx on test (round (id)); then select * from test where round (id) = 10; that case the function of the index function

  1. Use the following index will fail, should be avoided;

a. 使用 <> 、not in 、not exist、!=

b. like "%" Percent front (this method can be treated with indexing reverse (columnName))

C. When reference composite index in a first position of non-indexed columns separately. Column should always use the first index, if the index is based on a plurality of columns, only in its first column is referenced where clause , the optimizer will choose to use the index.

D. character number field is not added in the condition where quotes.

e. When the variable is used in variable times, and the field of the table is a date variable used. or vice versa.

  1. Do not empty variable values ​​compared directly with the comparison operator (symbol).

If the variable may be empty, or use IS NULL IS NOT NULL compared, or use the ISNULL function.

  1. Do not use double quotes in the SQL code.

Because the character constant use single quotes. If the object name is not necessarily limited, may be used (non-standard ANSI SQL) to enclose the name in parentheses.

  1. Where the index table space and table space where the data are located on different disks chunk, help improve the efficiency index query.

  2. Oracle default use of cost-based SQL optimizer (CBO) relies heavily on statistics, once the statistical information is not normal, it will not lead to the use of the index or using the wrong index database queries.

In general, Oracle's automated tasks which will include updated statistical information statements, but if the table data has a relatively large change (over 20%) can be considered immediately manually update statistics, such as: analyze table abc compute statistics, but Note that the update statistics consuming system resources, it is recommended to perform when the system is idle.

  1. When performing a query Oracle, generally for a table will only use an index.

Therefore, sometimes too many indexes may lead to Oracle using the wrong index, reduce the query efficiency. For example, a table has an index 1 (Policyno) and index 2 (classCode), if the query is policyno = 'xx' and classcode = 'xx', the system might use the index 2, compared to an index of 1, the query efficiency obviously decased.

  1. Priorities and using the partition index as much as possible.

Guess you like

Origin www.cnblogs.com/eer123/p/11803787.html