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的更多相关文章

  1. 跟我一起读postgresql源码(十二)——Executor(查询执行模块之——Materialization节点(下))

    接前文,我们继续说剩下的4个Materialization节点. 7.SetOp节点 SetOp节点用于处理集合操作,对应于SQL语句中的EXCEPT.INTERSECT两种集合操作,至于另一种集合操 ...

  2. 函数式编程里的Materialization应该翻译成什么?

    Materialization是函数式编程里的一个专业术语, 用于特指函数式编程中查询被实际执行并生成结果的这一过程. 首先, 搜了一下中文资料, 暂时没有对该词的中文翻译,  CSDN\博客园\阿里 ...

  3. semi-join子查询优化 -- semi-join Materialization策略

    semi-join Materialization 是用于semi-join的一种特殊的子查询物化技术.通常包含两种策略:1.Materialization/lookup2.Materializati ...

  4. 跟我一起读postgresql源码(十一)——Executor(查询执行模块之——Materialization节点(上))

    物化节点 顾名思义,物化节点是一类可缓存元组的节点.在执行过程中,很多扩展的物理操作符需要首先获取所有的元组后才能进行操作(例如聚集函数操作.没有索引辅助的排序等),这时要用物化节点将元组缓存起来.下 ...

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

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

  6. PayPal高级工程总监:读完这100篇论文 就能成大数据高手(附论文下载)

    100 open source Big Data architecture papers for data professionals. 读完这100篇论文 就能成大数据高手 作者 白宁超 2016年 ...

  7. 重新认识了下Entity Framework

    什么是Entity Framework Entity Framework是一个对象关系映射O/RM框架. Entity Framework让开发者可以像操作领域对象(domain-specific o ...

  8. Entity Framework 教程——DBContext

    DBContext: 在之前的章节<创建实体数据模型>中,EDM为我们创建了SchoolDBEntities 类,它派生子System.Data.Entity.DbContext这个类,这 ...

  9. 数据上下文【 DnContext】【EF基础系列7】

    DBContext: As you have seen in the previous Create Entity Data Model section, EDM generates the Scho ...

随机推荐

  1. 从零一起学Spring Boot之LayIM项目长成记(二) LayIM初体验

    前言 接上篇,已经完成了一个SpringBoot项目的基本搭建.那么现在就要考虑要做什么,怎么做的问题.所以本篇内容不多,带大家一起来简单了解一下要做的东西,之前有很多人不知道从哪里下手,那么今天我带 ...

  2. [转]C#如何获取客户端IP地址

    代码如下: /// <summary> /// 获取客户端IP地址    /// </summary> /// <returns></returns> ...

  3. 产线事故:删除创建mysql索引

    单表数据量:670W: 删除一个老的索引,新建一个新的索引. 事故原因: 先删除索引,应用访问量大,没有索引自然慢,数据库CPU飚到100%:新索引创建失败. 直接造成交易打烊. 日志: ------ ...

  4. waring L16: uncalled segement ----keil

    1.keil中出现waring:uncalled segement 2.waring L16:这个应该是一个waring等级 3.  转载自 wpb3dm 在Keil C中,如果没有显式调用到定义过的 ...

  5. springboot自定义异常页面

    废话不多,直接开始. 项目目录: 说明:springboot 静态文件放在static目录中,如images中放的图片:templates目录下error中存放的是错误页面,如500.html代表50 ...

  6. vue路由页面加载的几种方法~

    懒加载 (1)定义:懒加载也叫延迟加载,即在需要的时候进行加载,随用随载. (2)为什么需要懒加载: 在单页应用中,如果没有应用懒加载,运用webpack打包后的文件将会异常的大,造成进入首页时,需要 ...

  7. GoBelieve-国内唯一开源IM服务

    GoBelieve-国内唯一开源IM服务 1. 一小时接入 专注IM,无冗余功能 几行代码,一小时接入 省时省力. 2. 自由定制 提供最新源码, 自行二次开发,业务协议 交互视觉均可根据业务需求 自 ...

  8. Qt 项目主进程接收Alarm 后在GUI上显示,并且可以有选择性输出文件

    项目主进程接收报警后,将alarm msg 发送给代理, 并将其分发: else if (msg.name == "MesLCUalarmRep") { QString error ...

  9. C语言的乱七八糟

    Note For C Linux下C编程基础(gcc/gdb/make使用) 一.vi学习 二.初探emacs 三.gcc编译器 3.1 gcc所支持后缀名解释 后缀名 解释 后缀名 解释 .c C原 ...

  10. Vue-cli 3.0 使用Sass Scss Less预处理器

    项目中使用预处理器,可以有效减少css代码量,使用Sass||Scss||Less; 预处理器 你可以在创建项目的时候选择预处理器 (Sass/Less/Stylus).如果当时没有选好, 内置的 w ...