Oracle Tuning - HintsSometimes These execution plans are actually not the best and there is a better plan than Optimizer’s. But Optimizer doesn’t select that plan and you should instruct it forcibly. Hints are used to alter execution plans and force the optimizer to use the optimal execution plan. Oracle Hints influence the Optimizer decisions and select a certain execution plan based on the specific criteria. How to Use Hints in Oracle : For example: Your query is not using Index, but it should use it. You can use the hint in this case to force the Optimizer to use this index. The usage of Hints are as follows. ![]() You can use the Index hint as follows.
SQL> select deptno from emp where empno=7698;
DEPTNO
----------
30
You can add /*+ index(c COMP_NDX) */ clause the SQL Statements as follows to force using COMP_NDX Index.
SQL> SELECT /*+index(emp pk_emp) */ deptno from emp where empno=7698;
DEPTNO
----------
30
You can use the Parallel hint to force parallel running the SQL Statement
1 SELECT /*+ PARALLEL(emp 4) */ emp.ename
2 FROM emp
3* WHERE deptno=20
SQL> /
ENAME
----------
SMITH
JONES
SCOTT
ADAMS
FORD
You need to place hints immediately after the first SQL keyword of a statement block (MERGE, SELECT, INSERT, DELETE, or UPDATE) Each SQL Statement can have only one hint comment, but it can contain multiple hints as follows.
SELECT /*+ LEADING(emp2 emp1) USE_NL(emp1) INDEX(emp1 emp_emp_id_pk) USE_MERGE(jh) FULL(jh) */ emp1.first_name,
emp1.last_name, jh.job_id, sum(emp2.salary) total_sal
FROM employees emp1, employees emp2, job_history jh
WHERE emp1.employee_id = emp2.manager_id
AND emp1.employee_id = jh.employee_id
GROUP BY emp1.first_name, emp1.last_name, jh.job_id
ORDER BY emp1.first_name;
Hint Types in Oracle : There are 4 types of hints in the Oracle database as follows. Hints Categories are as follows : Oracle Hints and Definitions : Most important and popular Oracle hints and their definitions are as follows. ![]() « Previous Next Topic » (Oracle Tuning- Tuning SGA) |

