zoukankan      html  css  js  c++  java
  • mysql性能测试(索引)

    首先,使用Talend随机生成一千万条数据:

    image

    数据库表中现在有1千万+的数据:

    mysql> select count(*) from zhangchao;
    +----------+
    | count(*) |
    +----------+
    | 10040005 |
    +----------+
    1 row in set (2.50 sec)

    不加索引的情况下,查询一条记录的时间为3.02s

    mysql> select * from zhangchao where x = "bq2i2T";
    +--------+--------+
    | x      | y      |
    +--------+--------+
    | bq2i2T | DRt5Mx |
    +--------+--------+
    1 row in set (3.02 sec)
    
    mysql> show create table zhangchao;
    +-----------+------------------------------------------------------------------------------------------------------------------------------------+
    | Table     | Create Table                                                                                                                       |
    +-----------+------------------------------------------------------------------------------------------------------------------------------------+
    | zhangchao | CREATE TABLE `zhangchao` (
      `x` varchar(100) DEFAULT NULL,
      `y` varchar(100) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
    +-----------+------------------------------------------------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)

    给表zhangchao的x列创建索引,耗时45.43s:

    mysql> alter table zhangchao add index (x);
    Query OK, 0 rows affected (45.43 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> show create table zhangchao;
    +-----------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
    | Table     | Create Table                                                                                                                                        |
    +-----------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
    | zhangchao | CREATE TABLE `zhangchao` (
      `x` varchar(100) DEFAULT NULL,
      `y` varchar(100) DEFAULT NULL,
      KEY `x` (`x`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
    +-----------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)

    在执行同样的查询,耗时0.09s:

    mysql> select * from zhangchao where x = "bq2i2T";
    +--------+--------+
    | x      | y      |
    +--------+--------+
    | bq2i2T | DRt5Mx |
    +--------+--------+
    1 row in set (0.09 sec)

    和没有加索引的性能差别:3.02/0.09 = 33.555倍

  • 相关阅读:
    解决DataGridView绑定List后不能排序的问题
    最新的皮肤下载
    我收录的名言
    HttpRequest访问Https带有证书并使用WSDL文档生成代理类方案(2)
    最新的Functions 类
    华兴软通短信接口简单使用WebServices版
    最新的SqlHelper 类
    闲来没事写个记事本玩玩!!!
    "基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系"证书验证失败的解决过程(3)
    FCK配置
  • 原文地址:https://www.cnblogs.com/justinzhang/p/4795160.html
Copyright © 2011-2022 走看看