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倍

  • 相关阅读:
    kafka 配置属性
    mybatis 启动流程源码分析(二)之 Configuration-Properties解析
    mybatis 配置文件
    mybatis 启动流程源码分析(一)
    mybatis configuration
    使用函数式编程替换if-else
    mybatis 基本使用
    第十二周学习笔记
    T-SQL的进阶:超越基本级别3:构建相关子查询——701小组
    第十周学习笔记
  • 原文地址:https://www.cnblogs.com/justinzhang/p/4795160.html
Copyright © 2011-2022 走看看