1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
| { "steps": [ { "join_preparation": { "select#": 1, "steps": [ { "expanded_query": "/* select#1 */ select `people`.`name` AS `name`,count(0) AS `cnt`,group_concat(distinct `people`.`card` separator ',') AS `gd_card` from `people` where ((`people`.`age` > 10) and (`people`.`age` > -(1)) and (1 = 1) and (`people`.`age` < 99)) group by `people`.`name` having (`cnt` > 1) order by `cnt` desc limit 20000" } ] } }, { "join_optimization": { "select#": 1, "steps": [ { // 处理搜索条件 "condition_processing": { "condition": "WHERE", // 原始搜索条件 "original_condition": "((`people`.`age` > 10) and (`people`.`age` > -(1)) and (1 = 1) and (`people`.`age` < 99))", "steps": [ { // 等值传递转换 "transformation": "equality_propagation", "resulting_condition": "((`people`.`age` > 10) and (`people`.`age` > -(1)) and (1 = 1) and (`people`.`age` < 99))" }, { // 常量传递转换 "transformation": "constant_propagation", "resulting_condition": "((`people`.`age` > 10) and (`people`.`age` > -(1)) and (1 = 1) and (`people`.`age` < 99))" }, { // 去除没用的条件 "transformation": "trivial_condition_removal", "resulting_condition": "((`people`.`age` > 10) and (`people`.`age` > -(1)) and (`people`.`age` < 99))" } ] } }, { "condition_processing": { "condition": "HAVING", "original_condition": "(`cnt` > 1)", "steps": [ { "transformation": "constant_propagation", "resulting_condition": "(`cnt` > 1)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "(`cnt` > 1)" } ] } }, { // 替换虚拟生成列 "substitute_generated_columns": {} }, { // 表的依赖信息 "table_dependencies": [ { "table": "`people`", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { // 预估不同单表访问方法的访问成本 "rows_estimation": [ { "table": "`people`", "const_keys_added": { "keys": [ "name_age_key" ], "cause": "group_by" }, "range_analysis": { // 全表扫描的行数及成本 "table_scan": { "rows": 109674, "cost": 22482 }, // 分析可能使用的索引 "potential_range_indexes": [ { "index": "PRIMARY", "usable": false, "cause": "not_applicable" }, { "index": "card_UNIQUE", "usable": false, "cause": "not_applicable" }, { "index": "name_age_key", "usable": true, "key_parts": [ "name", "age", "id" ] } ], "setup_range_conditions": [], "group_index_range": { "chosen": false, "cause": "not_applicable_aggregate_function" }, // 分析各种可能使用的索引的成本 "analyzing_range_alternatives": { "range_scan_alternatives": [ { "index": "name_age_key", "chosen": false, "cause": "unknown" } ], "analyzing_roworder_intersect": { "usable": false, "cause": "too_few_roworder_scans" } } } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "`people`", "best_access_path": { "considered_access_paths": [ { "rows_to_scan": 109674, "access_type": "scan", "resulting_rows": 4060.8, "cost": 22480, "chosen": true } ] }, "condition_filtering_pct": 100, "rows_for_plan": 4060.8, "cost_for_plan": 22480, "chosen": true } ] }, { // 尝试给查询添加一些其他的查询条件 "attaching_conditions_to_tables": { "original_condition": "((`people`.`age` > 10) and (`people`.`age` > -(1)) and (`people`.`age` < 99))", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "`people`", "attached": "((`people`.`age` > 10) and (`people`.`age` > -(1)) and (`people`.`age` < 99))" } ] } }, { "clause_processing": { "clause": "ORDER BY", "original_clause": "`cnt` desc", "items": [ { "item": "count(0)" } ], "resulting_clause_is_simple": false, "resulting_clause": "`cnt` desc" } }, { "clause_processing": { "clause": "GROUP BY", "original_clause": "`people`.`name`", "items": [ { "item": "`people`.`name`" } ], "resulting_clause_is_simple": true, "resulting_clause": "`people`.`name`" } }, { "reconsidering_access_paths_for_index_ordering": { "clause": "GROUP BY", "steps": [], "index_order_summary": { "table": "`people`", "index_provides_order": true, "order_direction": "asc", "index": "name_age_key", "plan_changed": true, "access_type": "index" } } }, { "refine_plan": [ { "table": "`people`" } ] }, { "creating_tmp_table": { "tmp_table_info": { "table": "intermediate_tmp_table", "row_length": 130, "key_length": 0, "unique_constraint": false, "location": "memory (heap)", "row_limit_estimate": 129055 } } }, { "sort_using_internal_table": { "condition_for_sort": "(`cnt` > 1)", "having_after_sort": null } } ] } }, { "join_execution": { "select#": 1, "steps": [ { "creating_tmp_table": { "tmp_table_info": { "table": "intermediate_tmp_table", "row_length": 84, "key_length": 0, "unique_constraint": false, "location": "disk (InnoDB)", "record_format": "packed" } } }, { "filesort_information": [ { "direction": "desc", "table": "intermediate_tmp_table", "field": "cnt" } ], "filesort_priority_queue_optimization": { "usable": false, "cause": "not applicable (no LIMIT)" }, "filesort_execution": [], "filesort_summary": { // 排序过程中持有的行数 "rows": 27045, // 参与排序的行数,InnoDB 返回的行数 "examined_rows": 34054, // 排序使用的临时文件数量 "number_of_tmp_files": 24, // 内存排序使用的内存大小 "sort_buffer_size": 25744, // 排序模式 "sort_mode": "<sort_key, rowid>" } } ] } } ] }
|