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倍

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值