mysql执行计划 优化_MySQL SQL执行计划分析与优化方案.pptx

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 **************************

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值