index_join提示
RDBMS 12.2.0.1
Index_join
index_join把同一个表上的索引合并在一起,在查询的时候,只需要访问这些索引就可以了,省略了回表这个动作。
参考文档:
Optimizer Access Paths (oracle.com)
8.3.7 Index Join Scans
An index join scan is a hash join of multiple indexes that together return all columns requested by a query. The database does not need to access the table because all data is retrieved from the indexes.
This section contains the following topics:
8.3.7.1 When the Optimizer Considers Index Join Scans
In some cases, avoiding table access is the most cost efficient option.
The optimizer considers an index join in the following circumstances:
-
A hash join of multiple indexes retrieves all data requested by the query, without requiring table access.
-
The cost of retrieving rows from the table is higher than reading the indexes without retrieving rows from the table. An index join is often expensive. For example, when scanning two indexes and joining them, it is often less costly to choose the most selective index, and then probe the table.
You can specify an index join with the INDEX_JOIN(table_name)
hint.
See Also:
Oracle Database SQL Language Reference
8.3.7.2 How Index Join Scans Work
An index join involves scanning multiple indexes, and then using a hash join on the rowids obtained from these scans to return the rows.
In an index join scan, table access is always avoided. For example, the process for joining two indexes on a single table is as follows:
-
Scan the first index to retrieve rowids.
-
Scan the second index to retrieve rowids.
-
Perform a hash join by rowid to obtain the rows.
8.3.7.3 Index Join Scans: Example
--创建测试用的索引(略,使用hr schema中默认的索引 )
-- 不使用hint index_join的执行计划,可以发现,回表了employees.
select
employee_id,last_name
from employees
where employee_id = 7750
and department_id =1 ;
select * from table(dbms_xplan.display);
[email protected]> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
Plan hash value: 1833546154
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 15 | 1 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 15 | 1 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | EMP_EMP_ID_PK | 1 | | 0 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("DEPARTMENT_ID"=1)
2 - access("EMPLOYEE_ID"=7750)
15 rows selected.
[email protected]>
-- 使用hint index_join,可以发现,数据直接在index中就可以找到,没有访问任何表
select /*+ index_join(employees emp_emp_id_pk emp_department_ix) */
employee_id,last_name
from employees
where employee_id = 7750
and department_id =1 ;
[email protected]> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
Plan hash value: 3824254325
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 15 | 2 (0)| 00:00:01 |
|* 1 | VIEW | index$_join$_001 | 1 | 15 | 2 (0)| 00:00:01 |
|* 2 | HASH JOIN | | | | | |
|* 3 | HASH JOIN | | | | | |
|* 4 | INDEX RANGE SCAN | EMP_EMP_ID_PK | 1 | 15 | 0 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | EMP_DEPARTMENT_IX | 1 | 15 | 1 (0)| 00:00:01 |
| 6 | INDEX FAST FULL SCAN| EMP_NAME_IX | 1 | 15 | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("EMPLOYEE_ID"=7750 AND "DEPARTMENT_ID"=1)
2 - access(ROWID=ROWID)
3 - access(ROWID=ROWID)
4 - access("EMPLOYEE_ID"=7750)
5 - access("DEPARTMENT_ID"=1)
22 rows selected.
[email protected]>
END
上一篇: jdbc连接Mysql数据库出现Access denied for user 'root'@'localhost' (using password: YES) 拒绝访问问题解决
下一篇: Linux服务器安装GRUB步骤
推荐阅读
-
微信小程序表单验证form提交错误提示效果
-
用纯Node.JS弹出Windows系统消息提示框实例(MessageBox)
-
解决Hyper-V启动虚拟机提示无法启动虚拟机…监控程序未运行
-
Win7 X64 安装TortoiseSVN提示“此操作只对目前安装的产品有效”的解决方法
-
联想thinkpad笔记本提示“电源已接通 未充电”怎么办 什么原因如何解决
-
SpringBoot 配置提示功能
-
vue单页面实现当前页面刷新或跳转时提示保存
-
win10系统中命令提示符闪退该怎么解决?
-
Win8系统发生蓝屏提示reference by pointer错误的故障原因及解决方法
-
Win7系统开机提示An operating system wasnt found错误的原因及三种解决方法