"explain SELECT `ServerID`, `ServerIP`, `ServerPort`, ROUND(IFNULL(CAST(`SessionCount` AS UNSIGNED),CONVERT(0,UNSIGNED)) / 10) AS `SessionBucket` FROM `servers` LEFT JOIN (SELECT `Servers_ServerID`,CONVERT(COUNT(1),UNSIGNED) AS `SessionCount` FROM `session` GROUP BY `Servers_ServerID`) `SC` ON (`ServerID` = `SC`.`Servers_ServerID`)" "{ "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "derived": { "table": "SC", "select_id": 2, "algorithm": "materialized" } }, { "join_preparation": { "select_id": 2, "steps": [ { "expanded_query": "/* select#2 */ select `session`.Servers_ServerID AS Servers_ServerID,cast(count(1) as unsigned) AS SessionCount from `session` group by `session`.Servers_ServerID" } ] } }, { "expanded_query": "/* select#1 */ select servers.ServerID AS ServerID,servers.ServerIP AS ServerIP,servers.ServerPort AS ServerPort,round(ifnull(cast(sc.SessionCount as unsigned),cast(0 as unsigned)) / 10,0) AS SessionBucket from (servers left join (/* select#2 */ select `session`.Servers_ServerID AS Servers_ServerID,cast(count(1) as unsigned) AS SessionCount from `session` group by `session`.Servers_ServerID) sc on(servers.ServerID = sc.Servers_ServerID))" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "build_equal_items": { "condition": "ON expr", "attached_to": "SC", "resulting_condition": "multiple equal(servers.ServerID, sc.Servers_ServerID)" } }, { "join_optimization": { "select_id": 2, "steps": [ { "table_dependencies": [ { "table": "session", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "rows_estimation": [ { "table": "session", "range_analysis": { "table_scan": { "rows": 12489, "cost": 2596.8 }, "potential_range_indexes": [ { "index": "PRIMARY", "usable": false, "cause": "not applicable" }, { "index": "fk_Session_Servers_idx", "usable": true, "key_parts": ["Servers_ServerID", "SessionID"] } ], "best_covering_index_scan": { "index": "fk_Session_Servers_idx", "cost": 2654.227537, "chosen": false, "cause": "cost" }, "group_index_range": { "chosen": false, "cause": "not applicable aggregate function" } } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "get_costs_for_tables": [ { "best_access_path": { "table": "session", "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 12489, "cost": 97, "chosen": true, "use_tmp_table": true } ], "chosen_access_method": { "type": "scan", "records": 12489, "cost": 97, "uses_join_buffering": false } } } ] }, { "plan_prefix": [], "table": "session", "rows_for_plan": 12489, "cost_for_plan": 2594.8, "cost_for_sorting": 12489 } ] }, { "check_split_materialized": { "split_candidates": ["`session`.Servers_ServerID"] } } ] } }, { "table_dependencies": [ { "table": "servers", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "", "row_may_be_null": true, "map_bit": 1, "depends_on_map_bits": ["0"] } ] }, { "ref_optimizer_key_uses": [ { "table": "", "index": "key0", "field": "Servers_ServerID", "equals": "servers.ServerID", "null_rejecting": true } ] }, { "eliminated_tables": [] }, { "rows_estimation": [ { "table": "servers", "table_scan": { "rows": 244, "cost": 1 } }, { "table": "", "table_scan": { "rows": 12489, "cost": 12489 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "get_costs_for_tables": [ { "best_access_path": { "table": "servers", "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 244, "cost": 1, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 244, "cost": 1, "uses_join_buffering": false } } } ] }, { "plan_prefix": [], "table": "servers", "rows_for_plan": 244, "cost_for_plan": 49.8, "rest_of_plan": [ { "plan_prefix": ["servers"], "get_costs_for_tables": [ { "best_access_path": { "table": "", "choose_best_splitting": { "considered_keys": [ { "table_name": "session", "index": "fk_Session_Servers_idx", "rec_per_key": 1, "param_tables": 1 } ], "refills": 244, "spl_pd_boundary": 2, "split_plan_search": [ { "considered_execution_plans": [ { "plan_prefix": [], "get_costs_for_tables": [ { "best_access_path": { "table": "session", "considered_access_paths": [ { "access_type": "ref", "index": "fk_Session_Servers_idx", "rows": 1, "cost": 1.001635642, "chosen": true }, { "type": "scan", "chosen": false, "cause": "cost" } ], "chosen_access_method": { "type": "ref", "records": 1, "cost": 1.001635642, "uses_join_buffering": false } } } ] }, { "plan_prefix": [], "table": "session", "rows_for_plan": 1, "cost_for_plan": 1.201635642, "cost_for_sorting": 1 } ] } ], "lead_table": "session", "index": "fk_Session_Servers_idx", "parts": 1, "split_sel": 8.007046e-5, "cost": 1.151635642, "unsplit_cost": 4745.048744, "records": 1, "chosen": true }, "considered_access_paths": [ { "access_type": "ref", "index": "key0", "rec_per_key_stats_missing": true, "used_range_estimates": false, "reason": "not available", "rows": 2, "cost": 341.9990967, "chosen": true }, { "type": "scan", "chosen": false, "cause": "cost" } ], "chosen_access_method": { "type": "ref", "records": 2, "cost": 341.9990967, "uses_join_buffering": false } } } ] }, { "plan_prefix": ["servers"], "table": "", "rows_for_plan": 488, "cost_for_plan": 489.3990967 } ] } ] }, { "best_join_order": ["servers", ""] }, { "best_join_order": ["session"] }, { "substitute_best_equal": { "condition": "WHERE", "resulting_condition": "`session`.Servers_ServerID = servers.ServerID" } }, { "attaching_conditions_to_tables": { "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "session", "attached": null } ] } }, { "prepare_sum_aggregators": { "function": "count(1)", "aggregator_type": "simple" } }, { "substitute_best_equal": { "condition": "WHERE", "resulting_condition": "1" } }, { "substitute_best_equal": { "condition": "ON expr", "attached_to": "SC", "resulting_condition": "sc.Servers_ServerID = servers.ServerID" } }, { "condition_on_constant_tables": "1", "computing_condition": [] }, { "attaching_conditions_to_tables": { "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "servers", "attached": null }, { "table": "", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [ { "join_execution": { "select_id": 2, "steps": [] } } ] } } ] }" 0 false