日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

MySQL高级 trace工具

發布時間:2024/4/14 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL高级 trace工具 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

trace分析優化器執行計劃

MySQL5.6提供了對SQL的跟蹤trace, 通過trace文件能夠進一步了解為什么優化器選擇A計劃, 而不是選擇B計劃。

打開trace , 設置格式為 JSON,并設置trace最大能夠使用的內存大小,避免解析過程中因為默認內存過小而不能夠完整展示。

SET optimizer_trace="enabled=on",end_markers_in_json=on; set optimizer_trace_max_mem_size=1000000;

執行SQL語句 :

select * from tb_item where id < 4;

最后, 檢查information_schema.optimizer_trace就可以知道MySQL是如何執行SQL的 :

select * from information_schema.optimizer_trace\G; *************************** 1. row *************************** QUERY: select * from tb_item where id < 4 TRACE: {"steps": [{"join_preparation": {"select#": 1,"steps": [{"expanded_query": "/* select#1 */ select `tb_item`.`id` AS `id`,`tb_item`.`title` AS `title`,`tb_item`.`price` AS `price`,`tb_item`.`num` AS `num`,`tb_item`.`categoryid` AS `categoryid`,`tb_item`.`status` AS `status`,`tb_item`.`sellerid` AS `sellerid`,`tb_item`.`createtime` AS `createtime`,`tb_item`.`updatetime` AS `updatetime` from `tb_item` where (`tb_item`.`id` < 4)"}] /* steps */} /* join_preparation */},{"join_optimization": {"select#": 1,"steps": [{"condition_processing": {"condition": "WHERE","original_condition": "(`tb_item`.`id` < 4)","steps": [{"transformation": "equality_propagation","resulting_condition": "(`tb_item`.`id` < 4)"},{"transformation": "constant_propagation","resulting_condition": "(`tb_item`.`id` < 4)"},{"transformation": "trivial_condition_removal","resulting_condition": "(`tb_item`.`id` < 4)"}] /* steps */} /* condition_processing */},{"table_dependencies": [{"table": "`tb_item`","row_may_be_null": false,"map_bit": 0,"depends_on_map_bits": [] /* depends_on_map_bits */}] /* table_dependencies */},{"ref_optimizer_key_uses": [] /* ref_optimizer_key_uses */},{"rows_estimation": [{"table": "`tb_item`","range_analysis": {"table_scan": {"rows": 9816098,"cost": 2.04e6} /* table_scan */,"potential_range_indices": [{"index": "PRIMARY","usable": true,"key_parts": ["id"] /* key_parts */}] /* potential_range_indices */,"setup_range_conditions": [] /* setup_range_conditions */,"group_index_range": {"chosen": false,"cause": "not_group_by_or_distinct"} /* group_index_range */,"analyzing_range_alternatives": {"range_scan_alternatives": [{"index": "PRIMARY","ranges": ["id < 4"] /* ranges */,"index_dives_for_eq_ranges": true,"rowid_ordered": true,"using_mrr": false,"index_only": false,"rows": 3,"cost": 1.6154,"chosen": true}] /* range_scan_alternatives */,"analyzing_roworder_intersect": {"usable": false,"cause": "too_few_roworder_scans"} /* analyzing_roworder_intersect */} /* analyzing_range_alternatives */,"chosen_range_access_summary": {"range_access_plan": {"type": "range_scan","index": "PRIMARY","rows": 3,"ranges": ["id < 4"] /* ranges */} /* range_access_plan */,"rows_for_plan": 3,"cost_for_plan": 1.6154,"chosen": true} /* chosen_range_access_summary */} /* range_analysis */}] /* rows_estimation */},{"considered_execution_plans": [{"plan_prefix": [] /* plan_prefix */,"table": "`tb_item`","best_access_path": {"considered_access_paths": [{"access_type": "range","rows": 3,"cost": 2.2154,"chosen": true}] /* considered_access_paths */} /* best_access_path */,"cost_for_plan": 2.2154,"rows_for_plan": 3,"chosen": true}] /* considered_execution_plans */},{"attaching_conditions_to_tables": {"original_condition": "(`tb_item`.`id` < 4)","attached_conditions_computation": [] /* attached_conditions_computation */,"attached_conditions_summary": [{"table": "`tb_item`","attached": "(`tb_item`.`id` < 4)"}] /* attached_conditions_summary */} /* attaching_conditions_to_tables */},{"refine_plan": [{"table": "`tb_item`","access_type": "range"}] /* refine_plan */}] /* steps */} /* join_optimization */},{"join_execution": {"select#": 1,"steps": [] /* steps */} /* join_execution */}] /* steps */ }

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的MySQL高级 trace工具的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。