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

mysql中条件查询加排序和索引的关系

时间:2014-10-11 01:58:15      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:光伏企业   mysql   article   title   

跟一个朋友,不错公司的主管交流时,对于mysql中条件查询和排序时 与索引的关系

mysql> explain select * from article where title=‘希望光伏企业挺过2个月‘ o

rder by id desc\\\\\\\\G

*************************** 1. row ***************************

           id: 1

  select_type: SIMPLE

        table: article

         type: index

possible_keys: NULL

          key: PRIMARY

      key_len: 4

          ref: NULL

         rows: 567

        Extra: Using where

1 row in set (0.00 sec)


mysql> select * from article where title=‘希望光伏企业挺过2个月‘;

+----+-------------+---------+--------+-----------------------------+----------+

-----------+-------+-------------+---------+---------+--------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------+--------+--

---------+--------+------------+------------+

| id | category_id | user_id | app_id | title                       | subtitle |

 professor | money | cooperation | project | address | discription


                                                                    | source | r

ecommend | status | ctime      | mtime      |

+----+-------------+---------+--------+-----------------------------+----------+

-----------+-------+-------------+---------+---------+--------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------+--------+--

---------+--------+------------+------------+

| 10 |           2 |       4 |      0 | 希望光伏企业挺过2个月 |          |

           |     0 |             |         |         | 希望企业挺过两个月。 |        |

        1 |      0 | 1371524848 | 1371525226 |

+----+-------------+---------+--------+-----------------------------+----------+

-----------+-------+-------------+---------+---------+--------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------+--------+--

---------+--------+------------+------------+

1 row in set (0.00 sec)


mysql> explain select * from article where title=‘希望光伏企业挺过2个月‘;

+----+-------------+---------+------+---------------+------+---------+------+---

---+-------------+

| id | select_type | table   | type | possible_keys | key  | key_len | ref  | ro

ws | Extra       |

+----+-------------+---------+------+---------------+------+---------+------+---

---+-------------+

|  1 | SIMPLE      | article | ALL  | NULL          | NULL | NULL    | NULL |  5

67 | Using where |

+----+-------------+---------+------+---------------+------+---------+------+---

---+-------------+

1 row in set (0.00 sec)


大部门的开发人员会认为第一种查询时,不会用到索引

本文出自 “Linux运维” 博客,请务必保留此出处http://2853725.blog.51cto.com/2843725/1562343

mysql中条件查询加排序和索引的关系

标签:光伏企业   mysql   article   title   

原文地址:http://2853725.blog.51cto.com/2843725/1562343

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