Detailed explanation of oracle HINT

ORACLE's HINT detailed explanation
  Hints is a mechanism provided by Oracle to tell the optimizer to generate an execution plan in the way we tell it. We can use hints to achieve: 

  1) the type of optimizer used 
  2) the optimization goal of the cost-based optimizer, whether it is all_rows or first_rows. 
  3) The access path of the table, whether it is a full table scan, an index scan, or a direct use of rowid. 
  4) Connection type between 
  tables 5) Connection order between tables 
  6) Degree of parallelism of statements 
2. HINT can work based on the following rules 

  1. /*+ALL_ROWS*/ 

  Indicates that the cost-based optimization method is selected for the statement block, And get the best throughput and minimize resource consumption. 

  For example: 

  SELECT /*+ALL_ROWS*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT'; 

 

  2. /*+FIRST_ROWS*/ 

  indicates that the statement block selection is based on An optimization method for overhead, and to get the best response time and minimize resource consumption. 

 
  For example: 

  SELECT /*+FIRST_ROWS*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT'; 

  3. /*+CHOOSE*/ 

  Indicates that if the data dictionary has access table statistics, the cost-based optimization method will be used, and the best throughput will be obtained; 

  if there is no access table statistics in the data dictionary, the rule cost-based optimization method will be used; 

  for example: 

  SELECT /*+CHOOSE*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT'; 

 

  4. /*+RULE*/ 

 

  Indicates that the rule-based optimization method is selected for the statement block. 

 

  For example: 

 

  SELECT /*+ RULE */ EMP_NO, EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT'; 

 

  5. /*+FULL(TABLE)*/ 

 

  Indicates the method of global scan for the table. 

 

  For example: 

 

  SELECT /*+FULL(A)*/ EMP_NO,EMP_NAM FROM BSEMPMS A WHERE EMP_NO='SCOTT'; 

 

  6. /*+ROWID(TABLE)*/ 

 

  The prompt clearly indicates that access to the specified table is based on ROWID. 

 

  For example: 

 

  SELECT /*+ROWID(BSEMPMS)*/ * FROM BSEMPMS WHERE ROWID>='AAAAAAAAAAAAAAA ' 

 

  AND EMP_NO='SCOTT'; 

 

  7.  /*+CLUSTER(TABLE)*/ 

 

  The hint clearly indicates the access method for selecting a cluster scan for the specified table, which is only valid for cluster objects. 

 

  For example: 

 

  SELECT /*+CLUSTER */ BSEMPMS.EMP_NO,DPT_NO FROM BSEMPMS,BSDPTMS 

 

  WHERE DPT_NO='TEC304' AND BSEMPMS.DPT_NO=BSDPTMS .DPT_NO; 

 

  8. /*+INDEX(TABLE INDEX_NAME)*/ 

 

  Indicates the scan method for selecting indexes on the table. 

 

  For example: 

 

  SELECT /*+INDEX(BSEMPMS SEX_INDEX) USE SEX_INDEX BECAUSE THERE ARE FEWMALE BSEMPMS */ FROM BSEMPMS WHERE SEX=' M'; 

 

  9. /*+INDEX_ASC(TABLE INDEX_NAME)*/ 

 

  Indicates the scan method to select the index for the table in ascending order. 

 

  For example: 

 

  SELECT /*+INDEX_ASC(BSEMPMS PK_BSEMPMS) */ FROM BSEMPMS WHERE DPT_NO='SCOTT'; 

 

  10. / *+INDEX_COMBINE*/ 

 

  Select the bitmap access path for the specified table. If the index as a parameter is not provided in INDEX_COMBINE, the boolean combination of the bitmap index will be selected. 

 

  For example: 

 

  SELECT /*+INDEX_COMBINE(BSEMPMS SAL_BMI HIREDATE_BMI)*/ * FROM BSEMPMS 

 

  WHERE SAL<5000000 AND HIREDATE 

 

  11. /*+INDEX_JOIN(TABLE INDEX_NAME)*/ 

 

  Hints to explicitly instruct the optimizer to use indexes as access paths. 

 

  For example: 

 

  SELECT /*+ INDEX_JOIN(BSEMPMS SAL_HMI HIREDATE_BMI)*/ SAL,HIREDATE 

 

  FROM BSEMPMS WHERE SAL<60000; 

 

  12. /*+INDEX_DESC(TABLE INDEX_NAME)*/ 

 

  Indicates the scan method for selecting indexes in descending order of the table. 

 

  For example: 

 

  SELECT /*+INDEX_DESC(BSEMPMS PK_BSEMPMS ) */ FROM BSEMPMS WHERE DPT_NO='SCOTT'; 

 

  13. /*+INDEX_FFS(TABLE INDEX_NAME)*/ 

 

  Perform a fast full index scan on the specified table instead of a full table scan. 

 

  For example: 

 

  SELECT /*+INDEX_FFS( BSEMPMS IN_EMPNAM)*/ * FROM BSEMPMS WHERE DPT_NO='TEC305'; 

 

  14. /*+ADD_EQUAL TABLE INDEX_NAM1, INDEX_NAM2,...*/ 

 

  Prompt to explicitly select the execution plan and combine several single-column index scans. 

 

  For example: 

 

  SELECT /*+INDEX_FFS(BSEMPMS IN_DPTNO,IN_EMPNO,IN_SEX)* /* FROM BSEMPMS WHERE EMP_NO='SCOTT' AND DPT_NO='TDC306'; 

 

  15. /*+USE_CONCAT*/ 

 

  Convert the OR condition after the WHERE in the query to a combined query of UNION ALL. 

 

  For example: 

 

  SELECT /*+USE_CONCAT */ * FROM BSEMPMS WHERE DPT_NO='TDC506' AND SEX='M'; 

 

  16. /*+NO_EXPAND*/ 

 

  For the OR or IN-LIST query statement after WHERE, NO_EXPAND will prevent it from expanding it based on the optimizer .Example 

 

  : 

 

  SELECT /*+NO_EXPAND*/ * FROM BSEMPMS WHERE DPT_NO='TDC506' AND SEX='M'; 

 

  17. /*+NOWRITE*/ 

 

  Disable query rewrite operations on query blocks. 

 

  18. /*+REWRITE */ 

 

  You can take a view as a parameter. 

 

  19.  / * + MERGE (TABLE) * /

 

  Can merge each query of the view accordingly. 

 

  For example: 

 

  SELECT /*+MERGE(V) */ A.EMP_NO,A.EMP_NAM,B.DPT_NO FROM BSEMPMS A (SELET DPT_NO 

 

  ,AVG(SAL) AS AVG_SAL FROM BSEMPMS B GROUP BY DPT_NO) V WHERE A.DPT_NO=V.DPT_NO 

 

  AND A.SAL>V.AVG_SAL; 

 

  20. /*+NO_MERGE(TABLE)*/ 

 

  For mergeable views no longer merge. 

 

  For example: 

 

  SELECT /*+NO_MERGE (V) */ A.EMP_NO,A.EMP_NAM,B.DPT_NO FROM BSEMPMS A (SELECT DPT_NO,AVG(SAL) AS AVG_SAL FROM BSEMPMS B GROUP BY DPT_NO) V WHERE A.DPT_NO=V.DPT_NO AND A.SAL> V.AVG_SAL; 

 

  21. /*+ORDERED*/ 

 

  According to the order in which the tables appear in FROM, ORDERED makes ORACLE join them in this order. 

 

  For example: 

 

  SELECT /*+ORDERED*/ A.COL1,B.COL2,C. COL3 FROM TABLE1 A,TABLE2 B,TABLE3 C WHERE A.COL1=B.COL1 AND B.COL1=C.COL1; 

 

  22. /*+USE_NL(TABLE)*/ 

 

  Connect the specified table with the row source of the nested join, and use the specified table as the inner table. 

 

  For example: 

 

  SELECT /*+ORDERED USE_NL(BSEMPMS)*/ BSDPTMS.DPT_NO, BSEMPMS.EMP_NO,BSEMPMS.EMP_NAM FROM BSEMPMS,BSDPTMS WHERE BSEMPMS.DPT_NO=BSDPTMS.DPT_NO; 

 

  23. /*+USE_MERGE(TABLE)*/Connect 

 

  the specified table with other row sources through merge sort connection. 

 

  For example: 

 

  SELECT /*+USE_MERGE(BSEMPMS,BSDPTMS)*/ * FROM BSEMPMS,BSDPTMS WHERE BSEMPMS.DPT_NO=BSDPTMS.DPT_NO; 

 

  24. /*+USE_HASH(TABLE)*/ 

 

  Connect the specified table with other row sources by hash join For 

 

  example: 

 

  SELECT /*+USE_HASH(BSEMPMS,BSDPTMS)*/ * FROM BSEMPMS,BSDPTMS WHERE BSEMPMS.DPT_NO=BSDPTMS.DPT_NO; 

 

  25. /*+DRIVING_SITE(TABLE)*/ 

 

  Force a different location than ORACLE selected table for query execution. 

 

  For example: 

 

  SELECT /*+DRIVING_SITE(DEPT)*/ * FROM BSEMPMS,DEPT@BSDPTMS WHERE BSEMPMS.DPT_NO=DEPT.DPT_NO; 

 

  26. /*+LEADING(TABLE)*/ 

 

  Make the specified table the first table in the join order. 

 

  27 . /*+CACHE(TABLE)*/ 

  When performing a full table scan, the CACHE hint can place the retrieval block of the table on the most recently used end of the LRU in the buffer cache. 

 
For example: 

  SELECT /*+FULL(BSEMPMS) CAHE (BSEMPMS) */ EMP_NAM FROM BSEMPMS; 

 

  28. /*+NOCACHE(TABLE)*/ 

 

  When performing a full table scan, CACHE hints that the retrieval block of the table can be placed on the least recently used end of the LRU in the buffer cache, 

 

  for example : 

 

  SELECT /*+FULL(BSEMPMS) NOCAHE(BSEMPMS) */ EMP_NAM FROM BSEMPMS; 

 

  29. ​​/*+APPEND*/ 

 

  Insert directly to the end of the table, which can improve the speed. 

 

  insert /*+append*/ into test1 select * from test4 ; 

 

  30. /*+NOAPPEND*/ 

 

  Starts a regular insert by stopping parallel mode for the lifetime of the insert statement. 

 

  insert /*+noappend*/ into test1 select * from test4 ; 

 

  31. NO_INDEX: specify which indexes to not use 

 

  /*+ NO_INDEX ( table [index [index]...] ) */ 

 

  select /*+ no_index(emp ind_emp_sal ind_emp_deptno )*/ * from emp where deptno=200 and sal>300; 

 

32. parallel 

  select /*+ parallel(emp,4)*/ * from emp where deptno=200 and sal>300; 

  also: each SELECT/INSERT/ There can only be one /*+ */ after the UPDATE/DELETE command, but there can be multiple prompts, which can be separated by commas or spaces.


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326890717&siteId=291194637