LooseScan Strategy

简介:

Losse_scan/松散扫描:在执行连接的时候,半连接的表S (R semi-join S)其元组需要有序(a in select b from t,b 上存在索引,其元组的顺序按照b成分组状,则使用b上可用的索引读取元组的时候,可以按序引序把相同的值的元组有序读到),此时,根据索引拿出每组重复元组中的第一个元组(其他重复元组被读到后跳过,所以要求S的元组有序),与R表进行连接。[LosseScan:使用索引扫描,基于索引进行分组只取分组的第一条记录与外部表进行匹配;在EXPLAIN的extra字段显示LooseScan(m,n)]

select * from Country  
where 
  Country.code in (select country_code from Satellite)

假设在Satellite.country_code上有一个索引。
image
LooseScan策略并不需要排序,它需要的是分组。 在上图中,卫星按国家分组。 并获得没有重复的国家列表:
image

[world]> explain select * from Country where Country.code in (select country_code from Satellite);
+----+-------------+-----------+--------+---------------+--------------+---------+------------------------------+------+-------------------------------------+
| id | select_type | table     | type   | possible_keys | key          | key_len | ref                          | rows | Extra                               |
+----+-------------+-----------+--------+---------------+--------------+---------+------------------------------+------+-------------------------------------+
|  1 | PRIMARY     | Satellite | index  | country_code  | country_code | 9       | NULL                         |  932 | Using where; Using index; LooseScan |
|  1 | PRIMARY     | Country   | eq_ref | PRIMARY       | PRIMARY      | 3       | world.Satellite.country_code |    1 | Using index condition               |
+----+-------------+-----------+--------+---------------+--------------+---------+------------------------------+------+-------------------------------------+

LooseScan通过首先放置子查询表并使用其索引从多个重复项中选择一个记录来避免重复记录组合的产生
因此,为了使LooseScan适用,子查询应该如下所示:
expr IN (SELECT tbl.keypart1 FROM tbl ...)

expr IN (SELECT tbl.keypart2 FROM tbl WHERE tbl.keypart1=const AND ...)

LooseScan可以处理相关的子查询
LooseScan可以通过设置optimizer_switch变量中的loosescan = off标志来关闭。

目录
相关文章
|
7月前
|
算法 C++
运用C++ 策略模式的艺术(The Art of Applying Strategy Pattern)
运用C++ 策略模式的艺术(The Art of Applying Strategy Pattern)
45 0
|
7月前
|
算法 搜索推荐 Java
策略模式 Strategy
策略模式 Strategy
71 0
|
SQL 消息中间件 JSON
SPARK中的FileSourceStrategy,DataSourceStrategy以及DataSourceV2Strategy规则
SPARK中的FileSourceStrategy,DataSourceStrategy以及DataSourceV2Strategy规则
489 0
Stock Removal Strategy A(Partial Pallet Quantity)in SAP WM
Stock Removal Strategy A(Partial Pallet Quantity)in SAP WM
Stock Removal Strategy A(Partial Pallet Quantity)in SAP WM
|
设计模式 缓存 算法
行为型-Strategy
策略模式的原理与实现 策略模式的原理与实现策略模式,英文全称是 Strategy Design Pattern。在 GoF 的《设计模式》一书中,它是这样定义的: Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. 翻译成中文就是:定义一族算法类,将每个算法分别封装起来,让它们可以互相替换。策略模式可以使算法的变化独立于使用它们的客户端
121 0
Is a multi-cloud strategy the new normal?
The global enterprise market's determination to leverage big data has been synonymous with adopting cloud infrastructure.
1706 0
A Brief Note about Boltzmann/Softmax Exploration Strategy
One method that is often used in combination with the RL algorithms is the Beltzmann or softmax exploration strategy. The action selection strategy is still random, but selection probabili
1530 0