{ "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "join_preparation": { "select_id": 2, "steps": [ { "derived": { "table": "dt", "select_id": 3, "algorithm": "materialized" } }, { "join_preparation": { "select_id": 3, "steps": [ { "expanded_query": "/* select#3 */ select t1.`id` AS `id`,avg(t1.a) AS `avg(a)`,t2.b AS b from (t1 join t2 on(t1.`id` = t2.id2))" } ] } }, { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "semijoin", "chosen": true } }, { "expanded_query": "/* select#2 */ select dt.`id` from (/* select#3 */ select t1.`id` AS `id`,avg(t1.a) AS `avg(a)`,t2.b AS b from (t1 join t2 on(t1.`id` = t2.id2))) dt" } ] } }, { "expanded_query": "/* select#1 */ select t1.`id` AS `id`,t1.a AS a from (t1 join t2 on(t1.`id` = t2.id2)) where t1.`id` in (/* select#2 */ select dt.`id` from (/* select#3 */ select t1.`id` AS `id`,avg(t1.a) AS `avg(a)`,t2.b AS b from (t1 join t2 on(t1.`id` = t2.id2))) dt)" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "materialization", "sjm_scan_allowed": true, "possible": true } }, { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "semijoin", "converted_to_semi_join": true } }, { "condition_processing": { "condition": "WHERE", "original_condition": "1 and t1.`id` = dt.`id` and t1.`id` = t2.id2", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "1 and multiple equal(t1.`id`, dt.`id`, t2.id2)" }, { "transformation": "constant_propagation", "resulting_condition": "1 and multiple equal(t1.`id`, dt.`id`, t2.id2)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(t1.`id`, dt.`id`, t2.id2)" } ] } }, { "join_optimization": { "select_id": 3, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t1.`id` = t2.id2", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "multiple equal(t1.`id`, t2.id2)" }, { "transformation": "constant_propagation", "resulting_condition": "multiple equal(t1.`id`, t2.id2)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(t1.`id`, t2.id2)" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t2", "row_may_be_null": false, "map_bit": 1, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [ { "table": "t1", "index": "id", "field": "id", "equals": "t2.id2", "null_rejecting": true } ] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 8, "read_cost": 0.0119028, "read_and_compare_cost": 0.0121588 } }, { "table": "t2", "table_scan": { "rows": 4, "read_cost": 0.0113788, "read_and_compare_cost": 0.0115068 } } ] }, { "considered_execution_plans": [ { "plan_prefix": "", "get_costs_for_tables": [ { "best_access_path": { "table": "t2", "plan_details": { "record_count": 1 }, "considered_access_paths": [ { "access_type": "scan", "rows": 4, "rows_after_filter": 4, "rows_out": 4, "cost": 0.0115068, "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "rows_read": 4, "rows_out": 4, "cost": 0.0115068, "uses_join_buffering": false } } }, { "best_access_path": { "table": "t1", "plan_details": { "record_count": 1 }, "considered_access_paths": [ { "access_type": "scan", "rows": 8, "rows_after_filter": 8, "rows_out": 8, "cost": 0.0121588, "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "rows_read": 8, "rows_out": 8, "cost": 0.0121588, "uses_join_buffering": false } } } ] }, { "plan_prefix": "", "table": "t2", "rows_for_plan": 4, "cost_for_plan": 0.0115068, "rest_of_plan": [ { "plan_prefix": "t2", "get_costs_for_tables": [ { "best_access_path": { "table": "t1", "plan_details": { "record_count": 4 }, "considered_access_paths": [ { "access_type": "ref", "index": "id", "used_range_estimates": false, "reason": "not available", "rows": 4, "cost": 0.02084032, "chosen": true }, { "access_type": "scan_with_join_cache", "rows": 8, "rows_after_filter": 8, "rows_out": 4, "cost": 0.015373976, "cost_without_join_buffer": 0.0461776, "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "rows_read": 8, "rows_out": 4, "cost": 0.015373976, "uses_join_buffering": true } } } ] }, { "plan_prefix": "t2", "table": "t1", "rows_for_plan": 16, "cost_for_plan": 0.026880776, "pushdown_cond_selectivity": 0.5, "filtered": 50, "rows_out": 4 } ] }, { "plan_prefix": "", "table": "t1", "rows_for_plan": 8, "cost_for_plan": 0.0121588, "pruned_by_heuristic": true } ] }, { "best_join_order": ["t2", "t1"], "rows": 16, "cost": 0.026880776 }, { "substitute_best_equal": { "condition": "WHERE", "resulting_condition": "t1.`id` = t2.id2" } }, { "attaching_conditions_to_tables": { "attached_conditions_computation": [ { "table": "t1", "range_analysis": { "table_scan": { "rows": 8, "cost": 0.0121588 }, "potential_range_indexes": [ { "index": "a", "usable": false, "cause": "not applicable" }, { "index": "id", "usable": true, "key_parts": ["id"] } ], "setup_range_conditions": [], "analyzing_range_alternatives": { "range_scan_alternatives": [ { "index": "id" } ], "analyzing_roworder_intersect": { "cause": "too few roworder scans" }, "analyzing_index_merge_union": [] }, "group_index_range": { "chosen": false, "cause": "not single_table" } } } ], "attached_conditions_summary": [ { "table": "t2", "attached_condition": null }, { "table": "t1", "attached_condition": "t1.`id` = t2.id2" } ] } }, { "make_join_readinfo": [] } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t2", "row_may_be_null": false, "map_bit": 1, "depends_on_map_bits": [] }, { "table": "", "row_may_be_null": false, "map_bit": 2, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [ { "table": "t1", "index": "id", "field": "id", "equals": "dt.`id`", "null_rejecting": true }, { "table": "t1", "index": "id", "field": "id", "equals": "t2.id2", "null_rejecting": true }, { "table": "", "index": "key1", "field": "id", "equals": "t1.`id`", "null_rejecting": true }, { "table": "", "index": "key2", "field": "id", "equals": "t2.id2", "null_rejecting": true } ] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 8, "read_cost": 0.0119028, "read_and_compare_cost": 0.0121588 } }, { "table": "t2", "table_scan": { "rows": 4, "read_cost": 0.0113788, "read_and_compare_cost": 0.0115068 } }, { "table": "", "table_scan": { "rows": 32, "read_cost": 0.116782, "read_and_compare_cost": 0.119753712 } } ] }, { "semijoin_table_pullout": { "pulled_out_tables": [] } }, { "execution_plan_for_potential_materialization": { "steps": [ { "considered_execution_plans": [ { "plan_prefix": "", "get_costs_for_tables": [ { "best_access_path": { "table": "", "plan_details": { "record_count": 1 }, "considered_access_paths": [ { "access_type": "scan", "rows": 32, "rows_after_filter": 32, "rows_out": 32, "cost": 0.119753712, "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "rows_read": 32, "rows_out": 32, "cost": 0.119753712, "uses_join_buffering": false } } } ] }, { "plan_prefix": "", "table": "", "rows_for_plan": 32, "cost_for_plan": 0.119753712 } ] } ] } }, { "considered_execution_plans": [ { "plan_prefix": "", "get_costs_for_tables": [ { "best_access_path": { "table": "t2", "plan_details": { "record_count": 1 }, "considered_access_paths": [ { "access_type": "scan", "rows": 4, "rows_after_filter": 4, "rows_out": 4, "cost": 0.0115068, "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "rows_read": 4, "rows_out": 4, "cost": 0.0115068, "uses_join_buffering": false } } }, { "best_access_path": { "table": "t1", "plan_details": { "record_count": 1 }, "considered_access_paths": [ { "access_type": "scan", "rows": 8, "rows_after_filter": 8, "rows_out": 8, "cost": 0.0121588, "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "rows_read": 8, "rows_out": 8, "cost": 0.0121588, "uses_join_buffering": false } } }, { "best_access_path": { "table": "", "plan_details": { "record_count": 1 }, "considered_access_paths": [ { "access_type": "ref", "index": "key1", "chosen": false, "cause": "no predicate for first keypart" }, { "access_type": "ref", "index": "key2", "chosen": false, "cause": "no predicate for first keypart" }, { "access_type": "scan", "rows": 32, "rows_after_filter": 32, "rows_out": 32, "cost": 0.119753712, "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "rows_read": 32, "rows_out": 32, "cost": 0.119753712, "uses_join_buffering": false } } } ] }, { "plan_prefix": "", "table": "t2", "rows_for_plan": 4, "cost_for_plan": 0.0115068, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": "t2", "get_costs_for_tables": [ { "best_access_path": { "table": "t1", "plan_details": { "record_count": 4 }, "considered_access_paths": [ { "access_type": "ref", "index": "id", "used_range_estimates": false, "reason": "not available", "rows": 4, "cost": 0.02084032, "chosen": true }, { "access_type": "scan_with_join_cache", "rows": 8, "rows_after_filter": 8, "rows_out": 4, "cost": 0.015373976, "cost_without_join_buffer": 0.0461776, "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "rows_read": 8, "rows_out": 4, "cost": 0.015373976, "uses_join_buffering": true } } }, { "best_access_path": { "table": "", "plan_details": { "record_count": 4 }, "considered_access_paths": [ { "access_type": "ref", "index": "key1", "chosen": false, "cause": "no predicate for first keypart" }, { "access_type": "ref", "index": "key2", "rec_per_key_stats_missing": true, "used_range_estimates": false, "reason": "not available", "rows": 3.2, "cost": 0.006420532, "chosen": true }, { "type": "scan", "chosen": false, "cause": "cost" } ], "chosen_access_method": { "type": "ref", "rows_read": 3.2, "rows_out": 3.2, "cost": 0.006420532, "uses_join_buffering": false } } } ] }, { "plan_prefix": "t2", "table": "t1", "rows_for_plan": 16, "cost_for_plan": 0.026880776, "semijoin_strategy_choice": [], "pushdown_cond_selectivity": 0.5, "filtered": 50, "rows_out": 4, "rest_of_plan": [ { "plan_prefix": "t2,t1", "get_costs_for_tables": [ { "best_access_path": { "table": "", "plan_details": { "record_count": 16 }, "considered_access_paths": [ { "access_type": "ref", "index": "key1", "rec_per_key_stats_missing": true, "used_range_estimates": false, "reason": "not available", "rows": 3.2, "cost": 0.024453328, "chosen": true }, { "access_type": "ref", "index": "key2", "rec_per_key_stats_missing": true, "used_range_estimates": false, "reason": "not available", "rows": 3.2, "cost": 0.024453328, "chosen": false, "cause": "cost" }, { "type": "scan", "chosen": false, "cause": "cost" } ], "chosen_access_method": { "type": "ref", "rows_read": 3.2, "rows_out": 3.2, "cost": 0.024453328, "uses_join_buffering": false } } } ] }, { "plan_prefix": "t2,t1", "table": "", "rows_for_plan": 51.2, "cost_for_plan": 0.051334104, "semijoin_strategy_choice": [ { "strategy": "FirstMatch", "rows": 16, "cost": 0.051334104 }, { "strategy": "SJ-Materialization", "rows": 16, "cost": 0.17998508 }, { "strategy": "DuplicateWeedout", "prefix_row_count": 16, "tmp_table_rows": 1, "sj_inner_fanout": 3.2, "rows": 16, "dups_cost": 0.051334104, "write_cost": 0.02757552, "full_lookup_cost": 0.008241664, "total_cost": 0.087151288 }, { "chosen_strategy": "FirstMatch" } ], "sj_rows_out": 1, "sj_rows_for_plan": 16, "sj_filtered": 31.25 } ] }, { "plan_prefix": "t2", "table": "", "rows_for_plan": 12.8, "cost_for_plan": 0.017927332, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": "t2,", "get_costs_for_tables": [ { "best_access_path": { "table": "t1", "plan_details": { "record_count": 12.8 }, "considered_access_paths": [ { "access_type": "ref", "index": "id", "used_range_estimates": false, "reason": "not available", "rows": 4, "cost": 0.063084544, "chosen": true }, { "access_type": "scan_with_join_cache", "rows": 8, "rows_after_filter": 8, "rows_out": 4, "cost": 0.028680042, "cost_without_join_buffer": 0.14596608, "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "rows_read": 8, "rows_out": 4, "cost": 0.028680042, "uses_join_buffering": true } } } ] }, { "plan_prefix": "t2,", "table": "t1", "rows_for_plan": 51.2, "cost_for_plan": 0.046607374, "semijoin_strategy_choice": [ { "strategy": "LooseScan", "rows": 16, "cost": 0.076401277 }, { "strategy": "SJ-Materialization-Scan", "rows": 512, "cost": 0.386648304 }, { "strategy": "DuplicateWeedout", "prefix_row_count": 4, "tmp_table_rows": 4, "sj_inner_fanout": 3.2, "rows": 16, "dups_cost": 0.046607374, "write_cost": 0.02757552, "full_lookup_cost": 0.008241664, "total_cost": 0.082424558 }, { "chosen_strategy": "LooseScan" } ], "sj_rows_out": 1.25, "sj_rows_for_plan": 16, "sj_filtered": 15.625, "pruned_by_cost": true, "current_cost": 0.076401277, "best_cost": 0.051334104 } ] } ] }, { "plan_prefix": "", "table": "t1", "rows_for_plan": 8, "cost_for_plan": 0.0121588, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, { "plan_prefix": "", "table": "", "rows_for_plan": 32, "cost_for_plan": 0.119753712, "semijoin_strategy_choice": [], "pruned_by_cost": true, "current_cost": 0.119753712, "best_cost": 0.051334104 } ] }, { "fix_semijoin_strategies_for_picked_join_order": [ { "semi_join_strategy": "FirstMatch", "join_order": [ { "table": "" } ] } ] }