FILTER的适用范围:
1. 主表返回的记录数较少 2.子查询返回记录数较小
下面做实验证明:
select department_name
from hr.dept_1 dept
where department_id IN (select department_id from hr.employees_1 emp); SQL> select count(*) from dept_1; COUNT(*)
----------
2 SQL> select count(*) from employees_1; COUNT(*)
----------
3506176 SQL> select department_name
from hr.dept_1 dept
where department_id IN (select department_id from hr.employees_1 emp); 2 3 Execution Plan
----------------------------------------------------------
Plan hash value: 3257593059 ---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 40 | 7 (0)| 00:00:01 |
| 1 | NESTED LOOPS SEMI | | 2 | 40 | 7 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL| DEPT_1 | 2 | 32 | 3 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | EMPLOYEES_1_IDX1 | 3508K| 13M| 2 (0)| 00:00:01 |
--------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 3 - access("DEPARTMENT_ID"="DEPARTMENT_ID") Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
10 consistent gets
0 physical reads
0 redo size
486 bytes sent via SQL*Net to client
419 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed 那么走FILTER呢?
SQL> select department_name
from hr.dept_1 dept
where department_id IN (select /*+ NO_UNNEST */ department_id from hr.employees_1 emp); 2 3 Execution Plan
----------------------------------------------------------
Plan hash value: 1766326341 ---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 16 | 6 (0)| 00:00:01 |
|* 1 | FILTER | | | | | |
| 2 | TABLE ACCESS FULL| DEPT_1 | 2 | 32 | 3 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | EMPLOYEES_1_IDX1 | 2 | 8 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - filter( EXISTS (SELECT /*+ NO_UNNEST */ 0 FROM "HR"."EMPLOYEES_1" "EMP"
WHERE "DEPARTMENT_ID"=:B1))
3 - access("DEPARTMENT_ID"=:B1) Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
10 consistent gets
0 physical reads
0 redo size
486 bytes sent via SQL*Net to client
419 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed 此时效率一样,说明当from ...主表 返回数据 只返回几条 走FILTER没问题(主表小是之返回行数少) 那么还有什么情况,可以走FILTER呢? SQL> select * from test a where object_id in (select department_id
from hr.dept_1 dept
where department_id IN (select department_id from hr.employees_1 emp)); 2 3 64 rows selected. Execution Plan
----------------------------------------------------------
Plan hash value: 717021958 --------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 207 | 9747 (7)| 00:01:57 |
| 1 | VIEW | VM_NWVW_2 | 1 | 207 | 9747 (7)| 00:01:57 |
| 2 | HASH UNIQUE | | 1 | 226 | 9747 (7)| 00:01:57 |
|* 3 | HASH JOIN | | 14M| 3134M| 9264 (2)| 00:01:52 |
|* 4 | HASH JOIN | | 46 | 10212 | 7400 (1)| 00:01:29 |
| 5 | TABLE ACCESS FULL | DEPT_1 | 2 | 6 | 3 (0)| 00:00:01 |
| 6 | TABLE ACCESS FULL | TEST | 2511K| 524M| 7389 (1)| 00:01:29 |
| 7 | INDEX FAST FULL SCAN| EMPLOYEES_1_IDX1 | 3508K| 13M| 1819 (1)| 00:00:22 |
-------------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 3 - access("DEPARTMENT_ID"="DEPARTMENT_ID")
4 - access("OBJECT_ID"="DEPARTMENT_ID") Note
-----
- dynamic sampling used for this statement (level=2) Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
57221 consistent gets
41372 physical reads
0 redo size
2850 bytes sent via SQL*Net to client
463 bytes received via SQL*Net from client
6 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
64 rows processed 这里子查询被展开了,导致test和dept_1先关联了,但是子查询
SQL> (select department_id
from hr.dept_1 dept
where department_id IN (select department_id from hr.employees_1 emp)) 2 3 ; DEPARTMENT_ID
-------------
10
20
只返回了2条记录,可以让它走FILTER。 SQL> select * from test a where object_id in (select department_id
from hr.dept_1 dept
where department_id IN (select /*+ NO_UNNEST */ department_id from hr.employees_1 emp)); 2 3 64 rows selected. Execution Plan
----------------------------------------------------------
Plan hash value: 1506439343 -----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 23 | 5060 | 7403 (1)| 00:01:29 |
|* 1 | HASH JOIN RIGHT SEMI| | 23 | 5060 | 7403 (1)| 00:01:29 |
| 2 | VIEW | VW_NSO_1 | 1 | 13 | 6 (0)| 00:00:01 |
|* 3 | FILTER | | | | | |
| 4 | TABLE ACCESS FULL| DEPT_1 | 2 | 6 | 3 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | EMPLOYEES_1_IDX1 | 2 | 8 | 3 (0)| 00:00:01 |
| 6 | TABLE ACCESS FULL | TEST | 2511K| 495M| 7389 (1)| 00:01:29 |
----------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("OBJECT_ID"="DEPARTMENT_ID")
3 - filter( EXISTS (SELECT /*+ NO_UNNEST */ 0 FROM "HR"."EMPLOYEES_1" "EMP"
WHERE "DEPARTMENT_ID"=:B1))
5 - access("DEPARTMENT_ID"=:B1) Note
-----
- dynamic sampling used for this statement (level=2) Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
48871 consistent gets
33065 physical reads
0 redo size
4119 bytes sent via SQL*Net to client
463 bytes received via SQL*Net from client
6 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
64 rows processed 走FILTER后逻辑读下降到了 48871 。 总结如果子查询返回数据很少,那么不妨让它走filter,这种情况如果子查询被展开,那么会导致执行计划混乱,导致大表先和子查询里的大表关联。





												

走FILTER效率高的2种情况的更多相关文章

  1. JS获取元素宽高的两种情况

    JS获取元素宽高分两种情况, 一.内联样式,也就是直接把width和height写在HTML元素中的style里: 这种情况使用     document.getElementById('xxx'). ...

  2. oracle数据库中索引失效的几种情况

    原文1:https://blog.csdn.net/u012255097/article/details/102792683 原文2:https://www.cnblogs.com/lanseyita ...

  3. char、varchar 哪种的搜索效率高

    在MySQL 中char 和 varchar 都是存储字符串的,区别在于char有固定的长度,而varchar属于可变长的字符类型.char(M)类型的数据列里,每个值都占用M个字节,如果某个长度小于 ...

  4. C# 设置Excel数据自适应行高、列宽的2种情况

    Excel表格中,由于各种数据的复杂性,可能存在单元格中的数据字号大小.数据内容长度不一而出现,列宽过宽.过窄或者行高过大.过小的问题.常见的解决方法是调整行高.列宽.在Microsoft Excel ...

  5. Tomcat内存溢出的三种情况及解决办法分析

    Tomcat内存溢出的原因 在生产环境中tomcat内存设置不好很容易出现内存溢出.造成内存溢出是不一样的,当然处理方式也不一样. 这里根据平时遇到的情况和相关资料进行一个总结.常见的一般会有下面三种 ...

  6. 为什么说在使用多条件判断时switch case语句比if语句效率高?

    在学习JavaScript中的if控制语句和switch控制语句的时候,提到了使用多条件判断时switch case语句比if语句效率高,但是身为小白的我并没有在代码中看出有什么不同.去度娘找了半个小 ...

  7. SQLSERVER语句 in和exists哪个效率高本人测试证明

    SQLSERVR语句 in和exists哪个效率高本人测试证明 最近很多人讨论in和exists哪个效率高,今天就自己测试一下 我使用的是客户的数据库GPOSDB(已经有数据) 环境:SQLSERVE ...

  8. in和exists哪个效率高本人测试证明

    in和exists哪个效率高本人测试证明 SQLSERVR语句 in和exists哪个效率高自己测试本人测试证明 最近很多人讨论in和exists哪个效率高,今天就自己测试一下 我使用的是客户的数据库 ...

  9. 笨重的mfc还在基于系统控件,熟练的mfc工程师还比不过学习Qt一个月的学生开发效率高(比较精彩,韦易笑)

    作者:韦易笑链接:https://www.zhihu.com/question/29636221/answer/45102191来源:知乎著作权归作者所有,转载请联系作者获得授权. 更新:擦,本来只有 ...

随机推荐

  1. Object -C NSSet -- 笔记

    // //  main.m //  NSSET // //  Created by facial on 25/8/15. //  Copyright (c) 2015 facial_huo. All ...

  2. Jenkins+maven+git+sonar 系统持续集成&代码单測管理

    Jenkins+maven+git+sonar 系统持续集成&代码单測管理 Jenkins的安装 Jenkins是基于Java开发的一种持续集成工具,用于监控持续反复的工作.功能包含: 1.持 ...

  3. hdu5032 Always Cook Mushroom

    题意是这样,给定一个1000x1000的点阵.m组询问.每次询问一个由(0,0).(x,0)点一以及从原点出发的方向向量(a,b)构成的直角三角形包围的点的权值和. 点的权值是(x+A)(y+B),当 ...

  4. [ES6] Object.assign (with defaults value object)

    function spinner(target, options = {}){ let defaults = { message: "Please wait", spinningS ...

  5. 使用单例模式实现自己的HttpClient工具类

    引子 在Android开发中我们经常会用到网络连接功能与服务器进行数据的交互,为此Android的SDK提供了Apache的HttpClient 来方便我们使用各种Http服务.你可以把HttpCli ...

  6. MaterialDialog的用法:

    MaterialDialog的用法:/** * * @author smiling * @date 2016/10 */ Github:https://github.com/drakeet/Mater ...

  7. mysql 热备

    全备份:(生成时间戳文件夹:2016-04-20_16-12-01)innobackupex --users=root --password=root /tmp/backup 第一次增量备份:(生成时 ...

  8. 判断直线与线段相交 POJ 3304 Segments

    题意:在二维平面中,给定一些线段,然后判断在某直线上的投影是否有公共点. 转化,既然是投影,那么就是求是否存在一条直线L和所有的线段都相交. 证明: 下面给出具体的分析:先考虑一个特殊的情况,即n=1 ...

  9. OD: ActiveX Vulnerabilities

    通过一个精心构造的页面 exploit 第三方软件中的 ActiveX 已经成为一种惯用攻击手段,众多知名软件公司都曾被发现其注册的 ActiveX 中存在严重的缓冲区溢出漏洞,一个被广泛使用的第三方 ...

  10. svg text文字居中

    <text x="100" y="100" text-anchor="middle" dominant-baseline=" ...