使用duplicateweedout
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的更多相关文章
- 深入理解MySql子查询IN的执行和优化
IN为什么慢? 在应用程序中使用子查询后,SQL语句的查询性能变得非常糟糕.例如: SELECT driver_id FROM driver where driver_id in (SELECT dr ...
- MySQL中的两种临时表
MySQL中的两种临时表 伯乐在线2016-07-06 05:16:52阅读(4556)评论(3) 声明:本文由入驻搜狐公众平台的作者撰写,除搜狐官方账号外,观点仅代表作者本人,不代表搜狐立场.举报 ...
- MySQL版本升级之5.6到5.7
两种升级方式 In-Place Upgrade: Involves shutting down the old MySQL version, replacing the old MySQL binar ...
- mysql中的semi-join
1. 背景介绍 什么是semi-join? 所谓的semi-join是指semi-join子查询. 当一张表在另一张表找到匹配的记录之后,半连接(semi-jion)返回第一张表中的记录.与条件连接相 ...
- windows 下使用 zip安装包安装MySQL 5.7
以下内容参考官方文档:http://dev.mysql.com/doc/refman/5.7/en/windows-start-command-line.html 解压缩zip到D:\mysql-5. ...
- MySQL · 特性分析 · 内部临时表
http://mysql.taobao.org/monthly/2016/06/07/#rd MySQL中的两种临时表 外部临时表 通过CREATE TEMPORARY TABLE 创建的临时表,这种 ...
- mysql5.6子查询的优化
https://dev.mysql.com/doc/refman/5.6/en/subquery-optimization.html Semi-join in MySQL 5.6 MySQL 5. ...
- 认识Java虚拟机的内部体系结构、gc示例
认识Java虚拟机的内部体系结构 Java虚拟机的内部体系结构也许很少有人去关心,因为对于Java程序员来说,一般只需要跟API打交道就可以了.这些体系结构只是Java虚拟机内部的结构而已.但是如果理 ...
- MySQL 中的两种临时表
来源:阿里云RDS - 数据库内核组 链接:http://mysql.taobao.org/monthly/2016/06/07/ 外部临时表 通过CREATE TEMPORARY TABLE 创建的 ...
随机推荐
- 3.为JDeveloper添加不能的workspace
1.点击选中JDeveloper,在属性中,选中快捷方式, 可以看到目标中的值为C:\Oracle\Middleware\jdeveloper\jdeveloper.exe, 只需要在修改为C:\Or ...
- HDU 6467 简单数学题 【递推公式 && O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others) M ...
- Windows下我喜爱的那些体积小但功能强大的软件
我还是开门见山的说吧,接下来我给你大家介绍一些Windows上一些小软件,涉及到图片编辑,浏览器下载,文件搜索,音乐下载,文本编辑,视频录制等方面! 一:WinZIP中国 平常我们难免会遇到各种解压压 ...
- GitBash初始目录的修改
GitBash初始目录是定为到用户目录的,例如: 所以,每次打开都要手动调试到仓库所在的目录,可以通过修改目标和起始位置来定位到仓储文件夹下. 再次打开git,完美~~
- JSON数据转换之net.sf.json包的使用
转载 解析json之net.sf.json https://blog.csdn.net/itlwc/article/details/38442667 一.介绍 使用之前需要导入的jar包: json- ...
- CSS兼容性问题总结及解决方法
css兼容问题 兼容问题 1.文字本身的大小不兼容.同样是font-size:14px的宋体文字,在不同浏览器下占的空间是不一样的,ie下实际占高16px,下留白3px,ff下实际占高17px,上留白 ...
- MongoDB的角色作用(2)
数据压力大到机器支撑不了的时候能否做到自动扩展? 在系统早期,数据量还小的时候不会引起太大的问题,但是随着数据量持续增多,后续迟早会出现一台机器硬件瓶颈问题的.而MongoDB主打的就是海量数据架构, ...
- HDU 2018母牛的故事(类似斐波那契,找规律)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2018 母牛的故事 Time Limit: 2000/1000 MS (Java/Others) ...
- Jquery Mobile通过超链接跳转后CSS样式不起作用的解决办法
Jquery Mobile中的超链接默认是采用AJAX跳转的,ajax获取到页面的内容之后,就直接替换当前页面的内容了,它只是单纯的获取页面的HTML代码,并不会再去下载引用的CSS代码和JS代码,因 ...
- PL/SQL添加Oracle对象
1.首先用system的身份进入数据库 2.找到user文件夹 3.右击新建用户 在“创建用户”窗口中,输入新用户的名称.口令,默认表空间.临时表空间等 4.赋予新用户权限,赋予其角色权限:conne ...