zoukankan      html  css  js  c++  java
  • 100W数据,测试索引

    两张表,结构相同,数据内容相同。唯一不同的就是是否包含索引。tf_user_index表中包含索引。
    这100w数据,我造了近一天时间。

    mysql> select count(*) from tf_user_index where score = 30;
    +----------+
    | count(*) |
    +----------+
    |   126306 |
    +----------+
    1 row in set (0.03 sec)
    
    mysql> select count(*) from tf_user where score = 30;
    +----------+
    | count(*) |
    +----------+
    |   126306 |
    +----------+
    1 row in set (1.94 sec)
    
    

    score字段,加了索引。

    mysql> select count(*) from tf_user_index where score > 80;
    +----------+
    | count(*) |
    +----------+
    |  2525607 |
    +----------+
    1 row in set (0.49 sec)
    
    mysql> select count(*) from tf_user where score > 80;
    +----------+
    | count(*) |
    +----------+
    |  2525607 |
    +----------+
    1 row in set (2.02 sec)
    
    

    很明显,加了索引的查询要快很多。
    sql会根据条件去索引中查找,然后去表中查找。如果在索引中匹配的越多,那么查找的时间就越长,索引的意义就越小。
    看下面的例子,

    mysql> select count(*) from tf_user_index where score > 0;
    +----------+
    | count(*) |
    +----------+
    | 10000000 |
    +----------+
    1 row in set (1.91 sec)
    
    mysql> select count(*) from tf_user where score > 0;
    +----------+
    | count(*) |
    +----------+
    | 10000000 |
    +----------+
    1 row in set (2.03 sec)
    
    

    大于0,基本上匹配了所有的数据,索引的意义就不大了。

    大数据实验,才能更好的看出效果。让微观世界宏观化。

    下面看看,sex性别这个字段。

    mysql> select count(*) from tf_user where sex = 1;
    +----------+
    | count(*) |
    +----------+
    |  5001500 |
    +----------+
    1 row in set (2.29 sec)
    
    mysql> select count(*) from tf_user_index where sex = 1;
    +----------+
    | count(*) |
    +----------+
    |  5001500 |
    +----------+
    1 row in set (1.04 sec)
    
    

    加索引也还是有点提升速度的。但是意义不是很大,因为每次查询,基本上都是要扫描一半的数据表。总体来说,还是有一定的提升的。效果不是那么明显,比如上面的score快起来,只有几毫秒的查询时间。

  • 相关阅读:
    bzoj千题计划108:bzoj1018: [SHOI2008]堵塞的交通traffic
    bzoj千题计划106:bzoj1014 [JSOI2008]火星人prefix
    2017 清北济南考前刷题Day 7 morning
    2017 清北济南考前刷题Day 7 afternoon
    2017 清北济南考前刷题Day 6 afternoon
    2017 清北济南考前刷题Day 6 morning
    2017 清北济南考前刷题Day 5 afternoon
    怎么样在线创建索引或者重构索引
    10g RAC常用开启关闭命令 – SRVCTL用法
    安装Oracle 10g RAC是否需要安装HACMP
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/10135777.html
Copyright © 2011-2022 走看看