Created
October 15, 2021 19:27
-
-
Save kmorozov/7962fa56b90e67fbf7160f600dd0a992 to your computer and use it in GitHub Desktop.
MySql optimizer trace. No prepared statement.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"steps": [ | |
{ | |
"join_preparation": { | |
"select#": 1, | |
"steps": [ | |
{ | |
"expanded_query": "/* select#1 */ select `samples`.`id` AS `id`,`samples`.`organization_id` AS `organization_id`,`samples`.`device_id` AS `device_id`,`samples`.`percent_remaining` AS `percent_remaining`,`samples`.`percent_remaining_2` AS `percent_remaining_2`,`samples`.`created_at` AS `created_at`,`samples`.`updated_at` AS `updated_at`,`samples`.`raw_reading` AS `raw_reading`,`samples`.`filtered_reading` AS `filtered_reading`,`samples`.`raw_reading_2` AS `raw_reading_2`,`samples`.`signal_strength` AS `signal_strength`,`samples`.`battery_reading` AS `battery_reading`,`samples`.`basestation_id` AS `basestation_id` from `samples` where ((`samples`.`device_id` = 5852) and (`samples`.`device_id` is not null) and (`samples`.`id` <> 188315308)) order by `samples`.`created_at` desc limit 1" | |
} | |
] | |
} | |
}, | |
{ | |
"join_optimization": { | |
"select#": 1, | |
"steps": [ | |
{ | |
"condition_processing": { | |
"condition": "WHERE", | |
"original_condition": "((`samples`.`device_id` = 5852) and (`samples`.`device_id` is not null) and (`samples`.`id` <> 188315308))", | |
"steps": [ | |
{ | |
"transformation": "equality_propagation", | |
"resulting_condition": "((5852 is not null) and (`samples`.`id` <> 188315308) and multiple equal(5852, `samples`.`device_id`))" | |
}, | |
{ | |
"transformation": "constant_propagation", | |
"resulting_condition": "((5852 is not null) and (`samples`.`id` <> 188315308) and multiple equal(5852, `samples`.`device_id`))" | |
}, | |
{ | |
"transformation": "trivial_condition_removal", | |
"resulting_condition": "((`samples`.`id` <> 188315308) and multiple equal(5852, `samples`.`device_id`))" | |
} | |
] | |
} | |
}, | |
{ | |
"substitute_generated_columns": { | |
} | |
}, | |
{ | |
"table_dependencies": [ | |
{ | |
"table": "`samples`", | |
"row_may_be_null": false, | |
"map_bit": 0, | |
"depends_on_map_bits": [ | |
] | |
} | |
] | |
}, | |
{ | |
"ref_optimizer_key_uses": [ | |
{ | |
"table": "`samples`", | |
"field": "device_id", | |
"equals": "5852", | |
"null_rejecting": true | |
} | |
] | |
}, | |
{ | |
"rows_estimation": [ | |
{ | |
"table": "`samples`", | |
"range_analysis": { | |
"table_scan": { | |
"rows": 179018862, | |
"cost": 1.85e7 | |
}, | |
"potential_range_indexes": [ | |
{ | |
"index": "PRIMARY", | |
"usable": true, | |
"key_parts": [ | |
"id" | |
] | |
}, | |
{ | |
"index": "samples_organization_id_foreign", | |
"usable": false, | |
"cause": "not_applicable" | |
}, | |
{ | |
"index": "samples_basestation_id_created_at_index", | |
"usable": false, | |
"cause": "not_applicable" | |
}, | |
{ | |
"index": "samples_reverse_device_id_created_at_organization_id_index", | |
"usable": true, | |
"key_parts": [ | |
"device_id", | |
"created_at", | |
"organization_id", | |
"id" | |
] | |
} | |
], | |
"setup_range_conditions": [ | |
], | |
"group_index_range": { | |
"chosen": false, | |
"cause": "not_group_by_or_distinct" | |
}, | |
"skip_scan_range": { | |
"potential_skip_scan_indexes": [ | |
{ | |
"index": "PRIMARY", | |
"usable": false, | |
"cause": "query_references_nonkey_column" | |
}, | |
{ | |
"index": "samples_reverse_device_id_created_at_organization_id_index", | |
"usable": false, | |
"cause": "query_references_nonkey_column" | |
} | |
] | |
}, | |
"analyzing_range_alternatives": { | |
"range_scan_alternatives": [ | |
{ | |
"index": "PRIMARY", | |
"ranges": [ | |
"id < 188315308", | |
"188315308 < id" | |
], | |
"index_dives_for_eq_ranges": true, | |
"rowid_ordered": true, | |
"using_mrr": false, | |
"index_only": false, | |
"rows": 89509436, | |
"cost": 9.12e6, | |
"chosen": true | |
}, | |
{ | |
"index": "samples_reverse_device_id_created_at_organization_id_index", | |
"ranges": [ | |
"5852 <= device_id <= 5852" | |
], | |
"index_dives_for_eq_ranges": true, | |
"rowid_ordered": false, | |
"using_mrr": false, | |
"index_only": false, | |
"rows": 647136, | |
"cost": 550775, | |
"chosen": true | |
} | |
], | |
"analyzing_roworder_intersect": { | |
"usable": false, | |
"cause": "too_few_roworder_scans" | |
} | |
}, | |
"chosen_range_access_summary": { | |
"range_access_plan": { | |
"type": "range_scan", | |
"index": "samples_reverse_device_id_created_at_organization_id_index", | |
"rows": 647136, | |
"ranges": [ | |
"5852 <= device_id <= 5852" | |
] | |
}, | |
"rows_for_plan": 647136, | |
"cost_for_plan": 550775, | |
"chosen": true | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"considered_execution_plans": [ | |
{ | |
"plan_prefix": [ | |
], | |
"table": "`samples`", | |
"best_access_path": { | |
"considered_access_paths": [ | |
{ | |
"access_type": "ref", | |
"index": "samples_reverse_device_id_created_at_organization_id_index", | |
"rows": 647136, | |
"cost": 550774, | |
"chosen": true | |
}, | |
{ | |
"access_type": "range", | |
"range_details": { | |
"used_index": "samples_reverse_device_id_created_at_organization_id_index" | |
}, | |
"chosen": false, | |
"cause": "heuristic_index_cheaper" | |
} | |
] | |
}, | |
"condition_filtering_pct": 50, | |
"rows_for_plan": 323568, | |
"cost_for_plan": 550774, | |
"chosen": true | |
} | |
] | |
}, | |
{ | |
"attaching_conditions_to_tables": { | |
"original_condition": "((`samples`.`device_id` = 5852) and (`samples`.`id` <> 188315308))", | |
"attached_conditions_computation": [ | |
], | |
"attached_conditions_summary": [ | |
{ | |
"table": "`samples`", | |
"attached": "((`samples`.`device_id` = 5852) and (`samples`.`id` <> 188315308))" | |
} | |
] | |
} | |
}, | |
{ | |
"optimizing_distinct_group_by_order_by": { | |
"simplifying_order_by": { | |
"original_clause": "`samples`.`created_at` desc", | |
"items": [ | |
{ | |
"item": "`samples`.`created_at`" | |
} | |
], | |
"resulting_clause_is_simple": true, | |
"resulting_clause": "`samples`.`created_at` desc" | |
} | |
} | |
}, | |
{ | |
"reconsidering_access_paths_for_index_ordering": { | |
"clause": "ORDER BY", | |
"steps": [ | |
], | |
"index_order_summary": { | |
"table": "`samples`", | |
"index_provides_order": true, | |
"order_direction": "asc", | |
"index": "samples_reverse_device_id_created_at_organization_id_index", | |
"plan_changed": false | |
} | |
} | |
}, | |
{ | |
"finalizing_table_conditions": [ | |
{ | |
"table": "`samples`", | |
"original_table_condition": "((`samples`.`device_id` = 5852) and (`samples`.`id` <> 188315308))", | |
"final_table_condition ": "(`samples`.`id` <> 188315308)" | |
} | |
] | |
}, | |
{ | |
"refine_plan": [ | |
{ | |
"table": "`samples`", | |
"pushed_index_condition": "(`samples`.`id` <> 188315308)", | |
"table_condition_attached": null | |
} | |
] | |
}, | |
{ | |
"considering_tmp_tables": [ | |
] | |
} | |
] | |
} | |
}, | |
{ | |
"join_execution": { | |
"select#": 1, | |
"steps": [ | |
] | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment