我正在尝试了解索引提示,但即使在查询中提供提示后它也没有被使用。这是我遵循的步骤,我错过了什么吗?
SQL> desc emp_1;
Name Type Nullable Default Comments
-------- ------------ -------- ------- --------
EMP_ID NUMBER
EMP_NAME VARCHAR2(20) Y
DEPTNO NUMBER(10) Y
SQL> desc dept
Name Type Nullable Default Comments
--------- ------------ -------- ------- --------
DEPT_ID NUMBER Y
DEPT_NAME VARCHAR2(20) Y
SQL> CREATE INDEX abc_idex ON emp_1 (deptno);
Index created
select /*+ index(emp_1.abc_idex) */ emp_name from emp_1
INNER JOIN dept ON emp_1.deptno = dept.dept_id
解释计划:-
SELECT STATEMENT, GOAL = ALL_ROWS 6 1 28
HASH JOIN 6 1 28
TABLE ACCESS FULL EXAMINBI EMP_1 2 1 25
TABLE ACCESS FULL EXAMINBI DEPT 3 4 12
根据 Rene 的回答
select /*+ index(emp_1 abc_idex) */ emp_name from emp_1
INNER JOIN dept ON emp_1.deptno = dept.dept_id
解释计划
SELECT STATEMENT, GOAL = ALL_ROWS 271 100000 800000
MERGE JOIN 271 100000 800000
TABLE ACCESS BY INDEX ROWID EXAMINBI EMP_1 267 100000 500000
INDEX FULL SCAN EXAMINBI ABC_IDEX 131 100000
SORT JOIN 4 4 12
TABLE ACCESS FULL EXAMINBI DEPT 3 4 12