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. 「SLYZ Online Judge#74 Be」

    只有学校里的电脑才能看的题目 昊哥从牛客搬的,懒得找原题了 题意就是多组询问,每次询问一条树上路径,将这条路径上的点拿下来做\(0/1\)背包,求使得点权和为\(K\)的倍数的方案有几种 \(n< ...

  2. Kali-linux攻击WordPress和其他应用程序

    今天越来越多的企业利用SAAS(Software as a Service)工具应用在他们的业务中.例如,他们经常使用WordPress作为他们网站的内容管理系统,或者在局域网中使用Drupal框架. ...

  3. es6之类与对象

    一.类的定义 class Parent{ constructor(name="mukewang"){ this.name=name; } } let v_parant=new Pa ...

  4. 使用npm uninstall卸载express无效

    最近在看<node.js开发指南>学习node.js,因为书是2012年的书,对应的各种软件.包的版本就特别老,其中第五章用到express,书中版本用的是2.X版本,而我这边通过npm ...

  5. ui-element消息类型 MessageBox 弹框 type类型

    MessageBox 弹框 type字段表明消息类型,可以为success,error,info和warning

  6. 清空oracle session

    select 'alter system kill session '''||sid|| ','||serial#||''';' from v$session where username =' ';

  7. js中array(数组).map

    使用前 使用后 代码:

  8. [转载]对iOS开发中内存管理的一点总结与理解

    对iOS开发中内存管理的一点总结与理解   做iOS开发也已经有两年的时间,觉得有必要沉下心去整理一些东西了,特别是一些基础的东西,虽然现在有ARC这种东西,但是我一直也没有去用过,个人觉得对内存操作 ...

  9. 在CentOS 7上安装Docker环境

    官网文档:https://docs.docker.com/engine/installation/linux/centos/ ,本文大部分是照搬官方文档写的,如果你英文还不错,那么就直接移步官方文档吧 ...

  10. Spring Bean自动注册的实现方案

    这里Spring管理的Bean,可以认为是一个个的Service,每个Service都是一个服务接口 自动注册Service的好处: 1.根据指定的name/id获取对应的Service,实现简单工厂 ...