MySQL SQL执行计划分析与优化方案技术创新 变革未来CONTENTS读懂最简单的SQL“聪明的” SQL优化器Join 方式子查询视图有”缺陷的” MySQL优化器—如何纠正读懂最简单的SQL深入学习的基础.一个最简单的SQL的执行计划但含有丰富的信息. 1.1 范围查找range与等值查找refmysql> explain select * fromscore where sid>=0 andsid<=1\G*************************** 1. row ***************************id: 1 select_type: SIMPLEtable: score partitions: NULLtype: rangepossible_keys: sidkey: sidkey_len: 5 ref: NULL rows: 13filtered: 100.00Extra: Using index condition1 row in set, 1 warning (0.01 sec)mysql> explain select * fromscore where sid=1 \G*************************** 1. row *************************** id: 1select_type: SIMPLE table: score对比观察:Key相同Type不同partitions: NULL type: refpossible_keys: sidkey: sid key_len: 5ref: const rows: 13filtered: 100.00 Extra: NULL1 row in set, 1 warning (0.00 sec)5 1.2 范围查找range与全表扫描allmysql> explain select * fromscore where sid>=2 andsid<=3\G*************************** 1. row *************************** id: 1mysql> explainselect sid from scorewhere sid in (7,6) \Gselect_type: SIMPLE table: scorepartitions: NULL type: ALLpossible_keys: sidkey: NULLkey_len: NULL ref: NULL rows: 91filtered: 28.57Extra: Using where1 row in set, 1 warning (0.00 sec)*************************** 1. row *************************** id: 1select_type: SIMPLEtable: score partitions: NULLtype: rangepossible_keys: sidkey: sid key_len: 5ref: NULL rows: 26filtered: 100.00为什么where 条件为sid in(7,6)是范围查找?而sid=1的查询为ref查找?Extra: Using where; Using index 1 row in set, 1 warning (0.00 sec)6 1.3 全索引查找indexmysql> explain select sid fromscore\G*************************** 1. row *************************** id: 1select_type: SIMPLEtable: score partitions: NULLtype: indexpossible_keys: NULL key: sidkey_len: 10 ref: NULL rows: 91filtered: 100.00 Extra: Using index1 row in set, 1 warning (0.00 sec)7“聪明的”SQL优化器优化器到底有多聪明?为什么可以这么聪明? 2.1 为什么改变查找方式?mysql> explain select * fromscore where sid>=0 andsid<=1\G*************************** 1. row **************************
mysql执行计划 优化_MySQL SQL执行计划分析与优化方案.pptx
最新推荐文章于 2024-06-15 09:59:03 发布