Home  >  Article  >  Database  >  mysql的索引使用不当速度比没加索引还慢_MySQL

mysql的索引使用不当速度比没加索引还慢_MySQL

WBOY
WBOYOriginal
2016-06-01 13:51:591064browse

  mysql的索引使用不当速度比没加索引还慢,我们举个例子来解释一下。

  下面是我们插入到这个tuangou表的数据:

  id         web           city            type
  1        拉手网         北京          餐饮美食
  2       拉手网          上海          休闲娱乐
  3       百分团          天津          餐饮美食
  4       拉手网          深圳          网上购物
  5       百分团        石家庄         优惠卷票
  6       百分团         邯郸           美容保健
..
4999   百分团         重庆            旅游酒店
5000   拉手网         西安            优惠卷票

 执行mysql语句:
 $sql = "select from tuangou where web='拉手网' and city='上海'";

(1)如果没有加索引,执行时间是:0.0041秒

(2)如果只给web加索引,执行时间:0.0064秒

(3)如果web和city都加上索引,执行时间:0.0007 秒

  在(2)中虽然加上索引,但查询时间比不加索引用的时间还多。所以我建议大家,需要经常查询的字段都加上索引。




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn