使用materialization
explain select `countries`.`id` AS `id`,`countries`.`sortname` AS `sortname`,`countries`.`name` AS `name`,`countries`.`phonecode` AS `phonecode` from `countries` where `countries`.`id` in (/* select#2 */ select `states`.`country_id` from `states`);
+----+--------------+-------------+--------+---------------+------------+---------+-------------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------+-------------+--------+---------------+------------+---------+-------------------+------+-------------+
| 1 | SIMPLE | countries | ALL | PRIMARY | NULL | NULL | NULL | 246 | Using where |
| 1 | SIMPLE | <subquery2> | eq_ref | <auto_key> | <auto_key> | 4 | test.countries.id | 1 | NULL |
| 2 | MATERIALIZED | states | ALL | NULL | NULL | NULL | NULL | 4120 | NULL |
+----+--------------+-------------+--------+---------------+------------+---------+-------------------+------+-------------+
QUERY: explain select `countries`.`id` AS `id`,`countries`.`sortname` AS `sortname`,`countries`.`name` AS `name`,`countries`.`phonecode` AS `phonecode` from `countries` where `countries`.`id` in ( select `states`.`country_id` from `states`)
TRACE: {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"join_preparation": {
"select#": 2,
"steps": [
{
"expanded_query": "/* select#2 */ select `states`.`country_id` from `states`"
},
{
"transformation": {
"select#": 2,
"from": "IN (SELECT)",
"to": "semijoin",
"chosen": true
}
}
]
}
},
{
"expanded_query": "/* select#1 */ select `countries`.`id` AS `id`,`countries`.`sortname` AS `sortname`,`countries`.`name` AS `name`,`countries`.`phonecode` AS `phonecode` from `countries` where `countries`.`id` in (/* select#2 */ select `states`.`country_id` from `states`)"
}
]
}
},
{
"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 `countries`.`id` AS `id`,`countries`.`sortname` AS `sortname`,`countries`.`name` AS `name`,`countries`.`phonecode` AS `phonecode` from `countries` semi join (`states`) where (1 and (`countries`.`id` = `states`.`country_id`))"
}
},
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "(1 and (`countries`.`id` = `states`.`country_id`))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(1 and multiple equal(`countries`.`id`, `states`.`country_id`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(1 and multiple equal(`countries`.`id`, `states`.`country_id`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "multiple equal(`countries`.`id`, `states`.`country_id`)"
}
]
}
},
{
"table_dependencies": [
{
"table": "`countries`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
]
},
{
"table": "`states`",
"row_may_be_null": false,
"map_bit": 1,
"depends_on_map_bits": [
]
}
]
},
{
"ref_optimizer_key_uses": [
{
"table": "`countries`",
"field": "id",
"equals": "`states`.`country_id`",
"null_rejecting": false
}
]
},
{
"pulled_out_semijoin_tables": [
]
},
{
"rows_estimation": [
{
"table": "`countries`",
"table_scan": {
"rows": 246,
"cost": 1
}
},
{
"table": "`states`",
"table_scan": {
"rows": 4120,
"cost": 12
}
}
]
},
{
"execution_plan_for_potential_materialization": {
"steps": [
{
"considered_execution_plans": [
{
"plan_prefix": [
],
"table": "`states`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "scan",
"rows": 4120,
"cost": 836,
"chosen": true
}
]
},
"cost_for_plan": 836,
"rows_for_plan": 4120,
"chosen": true
}
]
}
]
}
},
{
"considered_execution_plans": [
{
"plan_prefix": [
],
"table": "`states`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "scan",
"rows": 4120,
"cost": 836,
"chosen": true
}
]
},
"cost_for_plan": 836,
"rows_for_plan": 4120,
"semijoin_strategy_choice": [
{
"strategy": "MaterializeScan",
"choice": "deferred"
}
],
"rest_of_plan": [
{
"plan_prefix": [
"`states`"
],
"table": "`countries`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "PRIMARY",
"rows": 1,
"cost": 4120.2,
"chosen": true
},
{
"access_type": "scan",
"using_join_cache": true,
"rows": 185,
"cost": 152453,
"chosen": false
}
]
},
"cost_for_plan": 5780,
"rows_for_plan": 4120,
"semijoin_strategy_choice": [
{
"strategy": "MaterializeScan",
"recalculate_access_paths_and_cost": {
"tables": [
{
"table": "`countries`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "PRIMARY",
"rows": 1,
"cost": 4120.2,
"chosen": true
},
{
"access_type": "scan",
"using_join_cache": true,
"rows": 185,
"cost": 152453,
"chosen": false
}
]
}
}
]
},
"cost": 7430,
"rows": 1,
"duplicate_tables_left": true,
"chosen": true
},
{
"strategy": "DuplicatesWeedout",
"cost": 6606.2,
"rows": 1,
"duplicate_tables_left": false,
"chosen": true
}
],
"chosen": true
}
]
},
{
"plan_prefix": [
],
"table": "`countries`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "PRIMARY",
"usable": false,
"chosen": false
},
{
"access_type": "scan",
"rows": 246,
"cost": 50.2,
"chosen": true
}
]
},
"cost_for_plan": 50.2,
"rows_for_plan": 246,
"semijoin_strategy_choice": [
],
"rest_of_plan": [
{
"plan_prefix": [
"`countries`"
],
"table": "`states`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "scan",
"using_join_cache": true,
"rows": 4120,
"cost": 202721,
"chosen": true
}
]
},
"cost_for_plan": 202771,
"rows_for_plan": 1.01e6,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"recalculate_access_paths_and_cost": {
"tables": [
{
"table": "`states`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "scan",
"using_join_cache": true,
"rows": 4120,
"cost": 202721,
"chosen": true
}
]
}
}
]
},
"cost": 202771,
"rows": 246,
"chosen": true
},
{
"strategy": "MaterializeLookup",
"cost": 1761.4,
"rows": 246,
"duplicate_tables_left": false,
"chosen": true
},
{
"strategy": "DuplicatesWeedout",
"cost": 405527,
"rows": 246,
"duplicate_tables_left": false,
"chosen": false
}
],
"chosen": true
}
]
},
{
"final_semijoin_strategy": "MaterializeLookup"
}
]
},
{
"creating_tmp_table": {
"tmp_table_info": {
"row_length": 5,
"key_length": 4,
"unique_constraint": false,
"location": "memory (heap)",
"row_limit_estimate": 3355443
}
}
},
{
"attaching_conditions_to_tables": {
"original_condition": "(`<subquery2>`.`country_id` = `countries`.`id`)",
"attached_conditions_computation": [
],
"attached_conditions_summary": [
{
"table": "`countries`",
"attached": "(`countries`.`id` is not null)"
},
{
"table": "``.`<subquery2>`",
"attached": null
},
{
"table": "`states`",
"attached": null
}
]
}
},
{
"refine_plan": [
{
"table": "`countries`",
"access_type": "table_scan"
},
{
"table": "``.`<subquery2>`"
},
{
"table": "`states`",
"access_type": "table_scan"
}
]
}
]
}
},
{
"join_explain": {
"select#": 1,
"steps": [
]
}
}
]
}
使用materialization的更多相关文章
- 跟我一起读postgresql源码(十二)——Executor(查询执行模块之——Materialization节点(下))
		
接前文,我们继续说剩下的4个Materialization节点. 7.SetOp节点 SetOp节点用于处理集合操作,对应于SQL语句中的EXCEPT.INTERSECT两种集合操作,至于另一种集合操 ...
 - 函数式编程里的Materialization应该翻译成什么?
		
Materialization是函数式编程里的一个专业术语, 用于特指函数式编程中查询被实际执行并生成结果的这一过程. 首先, 搜了一下中文资料, 暂时没有对该词的中文翻译, CSDN\博客园\阿里 ...
 - semi-join子查询优化 -- semi-join Materialization策略
		
semi-join Materialization 是用于semi-join的一种特殊的子查询物化技术.通常包含两种策略:1.Materialization/lookup2.Materializati ...
 - 跟我一起读postgresql源码(十一)——Executor(查询执行模块之——Materialization节点(上))
		
物化节点 顾名思义,物化节点是一类可缓存元组的节点.在执行过程中,很多扩展的物理操作符需要首先获取所有的元组后才能进行操作(例如聚集函数操作.没有索引辅助的排序等),这时要用物化节点将元组缓存起来.下 ...
 - 深入理解MySql子查询IN的执行和优化
		
IN为什么慢? 在应用程序中使用子查询后,SQL语句的查询性能变得非常糟糕.例如: SELECT driver_id FROM driver where driver_id in (SELECT dr ...
 - PayPal高级工程总监:读完这100篇论文 就能成大数据高手(附论文下载)
		
100 open source Big Data architecture papers for data professionals. 读完这100篇论文 就能成大数据高手 作者 白宁超 2016年 ...
 - 重新认识了下Entity Framework
		
什么是Entity Framework Entity Framework是一个对象关系映射O/RM框架. Entity Framework让开发者可以像操作领域对象(domain-specific o ...
 - Entity Framework 教程——DBContext
		
DBContext: 在之前的章节<创建实体数据模型>中,EDM为我们创建了SchoolDBEntities 类,它派生子System.Data.Entity.DbContext这个类,这 ...
 - 数据上下文【 DnContext】【EF基础系列7】
		
DBContext: As you have seen in the previous Create Entity Data Model section, EDM generates the Scho ...
 
随机推荐
- 体验了Sublime + Emmet,才体会到原来前端开发可以这么痛快!
			
从当初用notepad写出第一个web页面,到现在偶尔使用Editplus做一些HTML5的消遣,不知不觉已经15年了 --! 在这中间,和那些老顽固一样,坚决远离FP.DW那些半自动的前端开发工具 ...
 - [USACO07DEC]Sightseeing Cows
			
嘟嘟嘟 这题好像属于01分数规划问题,叫什么最优比率生成环. 题目概括一下,就是求一个环,满足∑v[i] / ∑c[i]最大. 我们可以堆上面的式子变个型:令 x = ∑v[i] / ∑c[i],则x ...
 - MVC学习八:MVC View提交数据
			
学习编程最主要的就是数据交互,MVC中数据交互是怎么样的呢? 1.Controller向View传输数据在http://www.cnblogs.com/WarBlog/p/7127574.html中有 ...
 - IOS开发,摄像头对焦状态监控
			
camera autofocus observer? I find the solution for my case to find when autofocus starts / ends. It' ...
 - 大数据框架-HDFS
			
HDFS:分布式文件系统,运行文件通过网络在多台主机分享的文件系统,分块写入(128M),适用于一次写入多次查询,不支持并发写(只能一块一块写),小文件不合适. nameNode(主节点,单个): 保 ...
 - 一点一点看JDK源码(五)java.util.ArrayList 后篇之sort与Comparator
			
一点一点看JDK源码(五)java.util.ArrayList 后篇之sort与Comparator liuyuhang原创,未经允许禁止转载 本文举例使用的是JDK8的API 目录:一点一点看JD ...
 - IF()判断变量是否为空
			
一 变量是字符串,判断为空 第一种:strs == null string strs = "test"; if (strs == null) { //这里是为空的字符串,返回你指定 ...
 - iOS运用runtime全局修改UILabel的默认字体
			
iOS运用runtime全局修改UILabel的默认字体 一.需求背景介绍 在项目比较成熟的基础上,遇到了这样一个需求,应用中需要引入新的字体,需要更换所有Label的默认字体,但是同时,对于一些特殊 ...
 - DB数据源之SpringBoot+MyBatis踏坑过程(五)手动使用Hikari连接池
			
DB数据源之SpringBoot+MyBatis踏坑过程(五)手动使用Hikari连接池 liuyuhang原创,未经允许禁止转载 系列目录连接 DB数据源之SpringBoot+Mybatis踏坑 ...
 - HTML中汉字空格占位符
			
== 普通的英文半角空格 == == == no-break space (普通的英文半角空格但不换行) == 中文全角空格 (一个中文宽度) == == en空格 (半个中文 ...