mysql> explain extended select * from cities where id in (select phonecode from  countries  group by name);
+----+-------------+-----------+--------+---------------+---------+---------+--------------------------+------+----------+-----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-----------+--------+---------------+---------+---------+--------------------------+------+----------+-----------------+
| 1 | SIMPLE | countries | ALL | NULL | NULL | NULL | NULL | 246 | 100.00 | Start temporary |
| 1 | SIMPLE | cities | eq_ref | PRIMARY | PRIMARY | 4 | test.countries.phonecode | 1 | 100.00 | End temporary |
+----+-------------+-----------+--------+---------------+---------+---------+--------------------------+------+----------+-----------------+
2 rows in set, 1 warning (5.65 sec)
QUERY: explain extended select * from cities where id in (select phonecode from  countries  group by name)
TRACE: {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"join_preparation": {
"select#": 2,
"steps": [
{
"transformations_to_subquery": [
"removed_grouping"
]
},
{
"expanded_query": "/* select#2 */ select `countries`.`phonecode` from `countries`"
},
{
"transformation": {
"select#": 2,
"from": "IN (SELECT)",
"to": "semijoin",
"chosen": true
}
}
]
}
},
{
"expanded_query": "/* select#1 */ select `cities`.`id` AS `id`,`cities`.`name` AS `name`,`cities`.`state_id` AS `state_id` from `cities` where `cities`.`id` in (/* select#2 */ select `countries`.`phonecode` from `countries`)"
}
]
}
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"transformation": {
"select#": 2,
"from": "IN (SELECT)",
"to": "semijoin",
"chosen": true,
"evaluating_constant_semijoin_conditions": [
]
}
},
{
"transformations_to_nested_joins": {
"transformations": [
"semijoin"
],
"expanded_query": "/* select#1 */ select `cities`.`id` AS `id`,`cities`.`name` AS `name`,`cities`.`state_id` AS `state_id` from `cities` semi join (`countries`) where (1 and (`cities`.`id` = `countries`.`phonecode`))"
}
},
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "(1 and (`cities`.`id` = `countries`.`phonecode`))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(1 and multiple equal(`cities`.`id`, `countries`.`phonecode`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(1 and multiple equal(`cities`.`id`, `countries`.`phonecode`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "multiple equal(`cities`.`id`, `countries`.`phonecode`)"
}
]
}
},
{
"table_dependencies": [
{
"table": "`cities`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
]
},
{
"table": "`countries`",
"row_may_be_null": false,
"map_bit": 1,
"depends_on_map_bits": [
]
}
]
},
{
"ref_optimizer_key_uses": [
{
"table": "`cities`",
"field": "id",
"equals": "`countries`.`phonecode`",
"null_rejecting": false
}
]
},
{
"pulled_out_semijoin_tables": [
]
},
{
"rows_estimation": [
{
"table": "`cities`",
"table_scan": {
"rows": 47478,
"cost": 161
}
},
{
"table": "`countries`",
"table_scan": {
"rows": 246,
"cost": 1
}
}
]
},
{
"execution_plan_for_potential_materialization": {
"steps": [
{
"considered_execution_plans": [
{
"plan_prefix": [
],
"table": "`countries`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "scan",
"rows": 246,
"cost": 50.2,
"chosen": true
}
]
},
"cost_for_plan": 50.2,
"rows_for_plan": 246,
"chosen": true
}
]
}
]
}
},
{
"considered_execution_plans": [
{
"plan_prefix": [
],
"table": "`countries`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "scan",
"rows": 246,
"cost": 50.2,
"chosen": true
}
]
},
"cost_for_plan": 50.2,
"rows_for_plan": 246,
"semijoin_strategy_choice": [
{
"strategy": "MaterializeScan",
"choice": "deferred"
}
],
"rest_of_plan": [
{
"plan_prefix": [
"`countries`"
],
"table": "`cities`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "PRIMARY",
"rows": 1,
"cost": 246.2,
"chosen": true
},
{
"access_type": "scan",
"using_join_cache": true,
"rows": 35609,
"cost": 1.75e6,
"chosen": false
}
]
},
"cost_for_plan": 345.4,
"rows_for_plan": 246,
"semijoin_strategy_choice": [
{
"strategy": "MaterializeScan",
"recalculate_access_paths_and_cost": {
"tables": [
{
"table": "`cities`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "PRIMARY",
"rows": 1,
"cost": 246.2,
"chosen": true
},
{
"access_type": "scan",
"using_join_cache": true,
"rows": 35609,
"cost": 1.75e6,
"chosen": false
}
]
}
}
]
},
"cost": 445.8,
"rows": 1,
"duplicate_tables_left": true,
"chosen": true
},
{
"strategy": "DuplicatesWeedout",
"cost": 396.8,
"rows": 1,
"duplicate_tables_left": false,
"chosen": true
}
],
"chosen": true
}
]
},
{
"plan_prefix": [
],
"table": "`cities`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "PRIMARY",
"usable": false,
"chosen": false
},
{
"access_type": "scan",
"rows": 47478,
"cost": 9656.6,
"chosen": true
}
]
},
"cost_for_plan": 9656.6,
"rows_for_plan": 47478,
"semijoin_strategy_choice": [
],
"pruned_by_cost": true
},
{
"final_semijoin_strategy": "DuplicateWeedout"
}
]
},
{
"attaching_conditions_to_tables": {
"original_condition": "(`cities`.`id` = `countries`.`phonecode`)",
"attached_conditions_computation": [
],
"attached_conditions_summary": [
{
"table": "`countries`",
"attached": null
},
{
"table": "`cities`",
"attached": null
}
]
}
},
{
"refine_plan": [
{
"creating_tmp_table": {
"tmp_table_info": {
"row_length": 6,
"key_length": 4,
"unique_constraint": false,
"location": "memory (heap)",
"row_limit_estimate": 2796202
}
}
},
{
"table": "`countries`",
"access_type": "table_scan"
},
{
"table": "`cities`"
}
]
}
]
}
},
{
"join_explain": {
"select#": 1,
"steps": [
]
}
}
]
}

使用duplicateweedout的更多相关文章

  1. 深入理解MySql子查询IN的执行和优化

    IN为什么慢? 在应用程序中使用子查询后,SQL语句的查询性能变得非常糟糕.例如: SELECT driver_id FROM driver where driver_id in (SELECT dr ...

  2. MySQL中的两种临时表

    MySQL中的两种临时表 伯乐在线2016-07-06 05:16:52阅读(4556)评论(3) 声明:本文由入驻搜狐公众平台的作者撰写,除搜狐官方账号外,观点仅代表作者本人,不代表搜狐立场.举报 ...

  3. MySQL版本升级之5.6到5.7

    两种升级方式 In-Place Upgrade: Involves shutting down the old MySQL version, replacing the old MySQL binar ...

  4. mysql中的semi-join

    1. 背景介绍 什么是semi-join? 所谓的semi-join是指semi-join子查询. 当一张表在另一张表找到匹配的记录之后,半连接(semi-jion)返回第一张表中的记录.与条件连接相 ...

  5. windows 下使用 zip安装包安装MySQL 5.7

    以下内容参考官方文档:http://dev.mysql.com/doc/refman/5.7/en/windows-start-command-line.html 解压缩zip到D:\mysql-5. ...

  6. MySQL · 特性分析 · 内部临时表

    http://mysql.taobao.org/monthly/2016/06/07/#rd MySQL中的两种临时表 外部临时表 通过CREATE TEMPORARY TABLE 创建的临时表,这种 ...

  7. mysql5.6子查询的优化

    https://dev.mysql.com/doc/refman/5.6/en/subquery-optimization.html Semi-join in MySQL 5.6   MySQL 5. ...

  8. 认识Java虚拟机的内部体系结构、gc示例

    认识Java虚拟机的内部体系结构 Java虚拟机的内部体系结构也许很少有人去关心,因为对于Java程序员来说,一般只需要跟API打交道就可以了.这些体系结构只是Java虚拟机内部的结构而已.但是如果理 ...

  9. MySQL 中的两种临时表

    来源:阿里云RDS - 数据库内核组 链接:http://mysql.taobao.org/monthly/2016/06/07/ 外部临时表 通过CREATE TEMPORARY TABLE 创建的 ...

随机推荐

  1. 网络解析json

    public class myActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceSta ...

  2. Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】

    传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...

  3. Spring data JPA先排序再分页。

    //工具类,增删改查等等package com.yunqing.service.impl; import java.util.Map; import org.springframework.beans ...

  4. HDU 4864 Task(经典贪心)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=4864 Task Time Limit: 4000/2000 MS (Java/Others)    M ...

  5. YUV display in OpenGL

    http://stackoverflow.com/questions/1106741/need-help-with-yuv-display-in-opengl  I am having trouble ...

  6. @RestController失效

    @RestController 注解失效.就是本来应该是直接返回数据.而不是去查找视图.但是去查找视图了.我这人不喜欢弄一些无用的配置文件.所以用到什么.引用什么.但是也容易犯错误.不过也好.对哪里出 ...

  7. java SSM 框架 代码生成器 websocket即时通讯 shiro redis

    1.   权限管理:点开二级菜单进入三级菜单显示 角色(基础权限)和按钮权限      角色(基础权限): 分角色组和角色,独立分配菜单权限和增删改查权限.      按钮权限: 给角色分配按钮权限. ...

  8. Swift_方法

    Swift_方法 点击查看源码 ///方法 class Methods: NSObject { func test() { // self.testInstanceMethods() //实例方法 s ...

  9. 画布与SVG区别

  10. OS--lab0+lab1+lab4+lab5+lab6+lab7

    URL:https://github.com/Chasssser/MytestOR(Linux) git clone https://github.com/Chasssser/Mytest