码迷,mamicode.com
首页 > 数据库 > 详细

mysql 优化

时间:2018-01-30 16:40:05      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:blog   har   mysql   body   gpo   arc   条件   pos   rom   

1. 查询

1-1 group by 比distinct 快

[SQL]select driver_id from XXX where created_time > ‘2017-12-27 00:00:00‘ and created_time<‘2017-12-28 00:00:00‘ group by driver_id
受影响的行: 0
时间: 0.418s
=============

[SQL]select DISTINCT(driver_id) from XXX where created_time > ‘2017-12-27 00:00:00‘ and created_time<‘2017-12-28 00:00:00‘
受影响的行: 0
时间: 0.556s

 

1-2 where 条件顺序 先过滤掉最多的、过滤最快的(int 比varchar快 比timestamp快)

[SQL]select driver_id,integral,source,city_id from XXX where created_time > ‘2017-12-27 00:00:00‘ and created_time<‘2017-12-28 00:00:00‘ and driver_id=216654
受影响的行: 0
时间: 0.030s

==========

[SQL]select driver_id,integral,source,city_id from XXX where driver_id=216654 and created_time > ‘2017-12-27 00:00:00‘ and created_time<‘2017-12-28 00:00:00‘
受影响的行: 0
时间: 0.017s

 

mysql 优化

标签:blog   har   mysql   body   gpo   arc   条件   pos   rom   

原文地址:https://www.cnblogs.com/rocky-fang/p/8384082.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!