oracle hint Force index (rpm)

1. It is proposed to establish a paytime, id, cost composite index. Paytime just based on the index will have a lot of random read.
2. Even if the establishment of the index, if the amount of data you query very large, not necessarily with an index, sometimes full table scan is faster than the index scan! (As if to say that about 10% of the official documents, that is if you query the data accounted for 10% of total data, a full table scan is faster than the index).
3. build composite index statement is as follows (it is recommended to search for look at the official documentation, indexing has many parameters, and each version of the ORACLE not necessarily the same):
the CREATE  INDEX TEST_ index ON C ON SUME_test
(PAYTIME, ID, COST)
LOGGING
TABLESPACE  iNDEX _A
NOPARALLEL;
final say, ORACLE does not seem to "force index" argument is!
Follow-up:
I remember Force index ah, that is, / * + This is written inside * /, but I do not know grammar
A chase:
You mean the use hints to prompt you to query which index to use. 
SELECT / * + INDEX (TABLE INDEX_NAME ) * / FROM TABLE 
may be prompted to use the ORACLE TABLE table has been built INDEX_NAME. ORACLE official said the document, which is not mandatory, just a hint, the optimizer may choose this index may or may not choose. However, most cases will be prompted to do! 

hints is a mechanism provided by the oracle, to tell the optimizer generates an execution plan in accordance with our way of telling it. We can use hints to achieve: 

  1) the type used by the optimizer 

  2) cost-based optimizer optimization goal is all_rows or first_rows. 

  Access path 3) tables, full table scan or index scan, or direct use of rowid. 

  4) type of connection between tables 

  5) is connected between the order table 

  6) degree of parallelism statement 

  2, HINT effect may be generated based on the following rules 

  sequence table attached, connection method table, access paths, the parallelism 

  3, HINT application range 

  dml statement 

  query 

  4, the syntax 
  {DELETE | INSERT | the SELECT | UPDATE} / * + hint [text] [hint [text]] ... * / 
  or
  {DELETE | INSERT | the SELECT | UPDATE} - + hint [ text] [hint [text]] ...
  If the language (sentence) method is incorrect, ORACLE will automatically ignore HINT written, not being given 


example:

In some scenarios, it may not automatically go ORACLE index, this time, if a clear business, you can try to force the index, the performance test query statement.

At EMP table, for example:

First create a unique index on the EMP table, as shown.

General search:

SELECT * FROM EMP T

View the execution plan:

You can see, it is to take a full table scan.

Using forced index, after the SELECT plus /*.......*/ middle with indexed properties, as follows:

The SELECT / * + index (t pk_emp) * / * the FROM EMP T    

- Force index, / * ..... * no spaces after / first stars, the contents inside the structure: Plus index (table spaces index name).
- If the table with an alias, the comment in the table have to use aliases.

 

We can see that this is taking the index PK_EMP.

 

1. It is proposed to establish a paytime, id, cost composite index. Paytime just based on the index will have a lot of random read.
2. Even if the establishment of the index, if the amount of data you query very large, not necessarily with an index, sometimes full table scan is faster than the index scan! (As if to say that about 10% of the official documents, that is if you query the data accounted for 10% of total data, a full table scan is faster than the index).
3. build composite index statement is as follows (it is recommended to search for look at the official documentation, indexing has many parameters, and each version of the ORACLE not necessarily the same):
the CREATE  INDEX TEST_ index ON C ON SUME_test
(PAYTIME, ID, COST)
LOGGING
TABLESPACE  iNDEX _A
NOPARALLEL;
final say, ORACLE does not seem to "force index" argument is!
Follow-up:
I remember Force index ah, that is, / * + This is written inside * /, but I do not know grammar
A chase:
You mean the use hints to prompt you to query which index to use. 
SELECT / * + INDEX (TABLE INDEX_NAME ) * / FROM TABLE 
may be prompted to use the ORACLE TABLE table has been built INDEX_NAME. ORACLE official said the document, which is not mandatory, just a hint, the optimizer may choose this index may or may not choose. However, most cases will be prompted to do! 

hints is a mechanism provided by the oracle, to tell the optimizer generates an execution plan in accordance with our way of telling it. We can use hints to achieve: 

  1) the type used by the optimizer 

  2) cost-based optimizer optimization goal is all_rows or first_rows. 

  Access path 3) tables, full table scan or index scan, or direct use of rowid. 

  4) type of connection between tables 

  5) is connected between the order table 

  6) degree of parallelism statement 

  2, HINT effect may be generated based on the following rules 

  sequence table attached, connection method table, access paths, the parallelism 

  3, HINT application range 

  dml statement 

  query 

  4, the syntax 
  {DELETE | INSERT | the SELECT | UPDATE} / * + hint [text] [hint [text]] ... * / 
  or 
  {DELETE | INSERT | the SELECT | UPDATE} - + hint [ text] [hint [text]] ...
  If the language (sentence) method is incorrect, ORACLE will automatically ignore HINT written, not being given 


example:

In some scenarios, it may not automatically go ORACLE index, this time, if a clear business, you can try to force the index, the performance test query statement.

At EMP table, for example:

First create a unique index on the EMP table, as shown.

General search:

SELECT * FROM EMP T

View the execution plan:

You can see, it is to take a full table scan.

Using forced index, after the SELECT plus /*.......*/ middle with indexed properties, as follows:

The SELECT / * + index (t pk_emp) * / * the FROM EMP T    

- Force index, / * ..... * no spaces after / first stars, the contents inside the structure: Plus index (table spaces index name).
- If the table with an alias, the comment in the table have to use aliases.

 

We can see that this is taking the index PK_EMP.

 

Guess you like

Origin www.cnblogs.com/mindOpen/p/12095372.html
Recommended