使用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 ...
随机推荐
- 利用arduino给PCB800099液晶驱动板烧录程序
某宝上购买了一块PCB800099液晶驱动板, 卖家出货的时候刷的驱动不对,遂需要重新烧录程序 可是苦于没有编程器,寻遍网络后找到几种解决方案: arduino刷,树莓派I2C口刷,linux下用vg ...
- HDU 1078 FatMouse and Cheese ( DP, DFS)
HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...
- Xcode 7.0 SDK(Software Development Kit) 及 Sandbox(沙盒) 存放路径
1. Sandbox(沙盒) 存放路径 我的硬盘/Users/wj121/Library/Developer/CoreSimulator/Devices/879D7E35-BE50-4620-97E1 ...
- 全渠道价值链整合云服务 B2B SOLOMO(组图)
最近看到>中谈到“全渠道零售”(Omni-channel Retailing),指在互联网和电子商务的当今时代“零售商将能通过各种渠道与顾客互动,包括网站.实体店.服务终端.直邮和目录.呼叫中心 ...
- 用js写三个数,让三个数从小到大排列
console.log('请输入三个数:'); let num1 = readline.question() - 0; let num2 = readline.question() - 0; let ...
- 前端基础-CSS的属性相关设置
一 字体属性 二 文本属性 三 背景属性 四 盒子模型 五 盒子模型各部分详解 一. 字体属性 1.font-weight:文字粗细(表格中*为重点) 取值 描述 normal 默认值,标准粗细 ...
- mysql获取正在运行的sql
select id,db,host,time,info,command from information_schema.processlist where command<>'sleep' ...
- Swift_属性
Swift_属性 点击查看源码 class DataImporter { var fileName = "data.txt" init() { print("初始化&qu ...
- Grub4dos boot
Grub4dos 0.4.6a http://grub4dos.chenall.net/ Ghost11.5 bcdedit bcdedit /create /d "Grub4dos&quo ...
- 分布式版本控制系统之Git
Git Git 是目前世界上最先进的分布式版本控制系统(没有之一) 作用 源代码管理 为什么要进行源代码管理? 方便多人协同开发 方便版本控制 Git的诞生 作者是 Linux 之父:Linus Be ...