在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

MySQL SQL优化方法是什么

156次阅读
没有评论

共计 3244 个字符,预计需要花费 9 分钟才能阅读完成。

这篇文章主要讲解了“MySQL SQL 优化方法是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着丸趣 TV 小编的思路慢慢深入,一起来研究和学习“MySQL SQL 优化方法是什么”吧!

slowlog 里查到一条 sql 执行了 10 秒钟以上

# Time: 2017-03-02T18:41:50.201376+08:00

# User@Host: oms_readonly[oms_readonly] @ [10.xx.xx.xx] Id: 54124620

# Query_time: 11.005894 Lock_time: 0.000223 Rows_sent: 20 Rows_examined: 1838114

SET timestamp=1488451310;

select * from customers where `type` = 1 AND `status`   7 AND `isarea` = 6 AND `into_time` = 2016-12-01 AND `into_time` = 2017-01-02 23:59:59  order by score desc limit 40,20;

查看执行计划

mysql  explain select * from customers where `type` = 1 AND `status`   7 AND `isarea` = 6 AND `into_time` = 2016-12-01 AND `into_time` = 2017-01-02 23:59:59  order by score desc limit 40,20;

+—-+————-+———–+————+——-+—————————————————————–+——-+———+——+——+———-+————-+

| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |

+—-+————-+———–+————+——-+—————————————————————–+——-+———+——+——+———-+————-+

| 1 | SIMPLE | customers | NULL | index | type,into_time,isarea,status,idx_isarea_renew_owner,type_status | score | 2 | NULL | 603 | 0.21 | Using where |

+—-+————-+———–+————+——-+—————————————————————–+——-+———+——+——+———-+————-+

1 row in set, 1 warning (0.00 sec)

看下列的选择性,很明显 isarea 列的选择性更好

mysql  select count(*) from customers where `type` = 1;

+———-+

| count(*) |

+———-+

| 2373175 |

+———-+

1 row in set (1.53 sec)

mysql  select count(*) from customers where `status`   7;

 –  ;

+———-+

| count(*) |

+———-+

| 2494232 |

+———-+

1 row in set (3.16 sec)

mysql  select count(*) from customers where `isarea` = 6;

+———-+

| count(*) |

+———-+

| 135347 |

+———-+

1 row in set (0.15 sec)

mysql  select count(*) from customers where `into_time` = 2016-12-01 AND `into_time` = 2017-01-02 23:59:59

+———-+

| count(*) |

+———-+

| 106158 |

+———-+

1 row in set (0.12 sec)

isarea 有索引,强制用这个列的索引

mysql  explain select * from customers use index(isarea) where `type` = 1 AND `status`   7 AND `isarea` = 6 AND `into_time` = 2016-12-01 AND `into_time` = 2017-01-02 23:59:59  order by score desc limit 40,20;

+—-+————-+———–+————+——+—————+——–+———+——-+——–+———-+—————————————————-+

| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |

+—-+————-+———–+————+——+—————+——–+———+——-+——–+———-+—————————————————-+

| 1 | SIMPLE | customers | NULL | ref | isarea | isarea | 5 | const | 249438 | 1.85 | Using index condition; Using where; Using filesort |

+—-+————-+———–+————+——+—————+——–+———+——-+——–+———-+—————————————————-+

1 row in set, 1 warning (0.00 sec)

优化前 10 几秒出结果,优化后 0.5 秒出结果。

感谢各位的阅读,以上就是“MySQL SQL 优化方法是什么”的内容了,经过本文的学习后,相信大家对 MySQL SQL 优化方法是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是丸趣 TV,丸趣 TV 小编将为大家推送更多相关知识点的文章,欢迎关注!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-19发表,共计3244字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 亚洲不卡视频在线观看 | 亚洲mv大片欧洲mv大片 | a级毛片视频免费观看 | 亚洲精品国产成人无码区a片 | 亚洲在线国产日韩欧美 | 国产精品日韩欧美一区二区三区 | 国产suv精品一区二区 | 色婷婷国产 | 亚洲高清中文字幕 | 久久天天拍天天爱天天躁 | 国产精品一区二区久久精品 | 亚洲欧洲美洲无码精品va | 亚洲日韩乱码中文无码蜜桃臀网站 | 国产真实偷乱视频在线观看 | 日韩精品无码成人专区 | 狠狠久久精品中文字幕无码 | 欧美大黄大色一级毛片出红 | 黄色一级毛片看一级毛片 | 一级做a爱片特黄在线观看 一级做a爱片特黄在线观看yy | 日本免费a视频 | 二区三区不卡不卡视频 | 国产一区二区三区内射高清 | 日本欧美韩国一区二区三区 | 最新国产区 | 国产91激情对白露脸全程 | 久久频 | 亚洲三级小说 | 又黄又爽又色视频 | 伊人亚洲综合青草青草久热 | 男女在线无遮挡毛片免费 | 伊人久久大香线蕉综合影院首页 | 亚洲国产精品久久久久666 | 国产日韩综合一区二区性色av | 国产伦子系列沙发午睡 | 久久99精品久久久久久青青91 | 俄罗斯大荫蒂女人毛茸茸 | 国产男女性特黄录像 | 欧美性大战久久久久久 | 欧美视频在线观看视频 | 韩国午夜一级伦理片 | 免费观看黄色小视频 |