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

mysql索引及优化学习

时间:2018-02-08 15:29:35      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:mys   select   using   表达   class   row   化学   div   学习   

一般优化mysql首先看查找的数据有没有用到索引,没有索引就加索引,有索引时候避免索引失效。

看下面两条语句

MySQL [release_test_oa]> EXPLAIN SELECT * FROM WORKFLOW_LOGS WHERE ID -100 < 300000;
+----+-------------+---------------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table         | type | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+---------------+------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | WORKFLOW_LOGS | ALL  | NULL          | NULL | NULL    | NULL | 3998 | Using where |
+----+-------------+---------------+------+---------------+------+---------+------+------+-------------+

 

MySQL [release_test_oa]> EXPLAIN SELECT * FROM WORKFLOW_LOGS WHERE ID < 300000-100 ;
+----+-------------+---------------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table         | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+---------------+-------+---------------+---------+---------+------+------+-------------+
|  1 | SIMPLE      | WORKFLOW_LOGS | range | PRIMARY       | PRIMARY | 8       | NULL | 1999 | Using where |
+----+-------------+---------------+-------+---------------+---------+---------+------+------+-------------+

 上面那句没有使用到ID字段上的索引,而下面使用到了,所以要避免在列上进行表达式计算。

mysql索引及优化学习

标签:mys   select   using   表达   class   row   化学   div   学习   

原文地址:https://www.cnblogs.com/songgj/p/8431252.html

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