mysql性能测试(索引)
2015-09-09 16:36
831 查看
首先,使用Talend随机生成一千万条数据:
数据库表中现在有1千万+的数据:
不加索引的情况下,查询一条记录的时间为3.02s
给表zhangchao的x列创建索引,耗时45.43s:
在执行同样的查询,耗时0.09s:
和没有加索引的性能差别:3.02/0.09 = 33.555倍
数据库表中现在有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倍
相关文章推荐
- mysql-proxy 初体验
- MySQL 5.7 mulit-source replication
- mysql 查询字段为null或者非null
- 《高性能MySQL》第四章
- MySQL Innodb Memcahed Introduction & Examples
- Mysql 5.6 command line Client闪退的解决方法
- talend 连接mysql数据库没有权限
- win7 64位配置mysql 5.6免安装版
- MySQL学习笔记(1)——启动停止与登录,显示相关信息
- MySQL数据库(修改表)
- mysql中如何使用一句话将一个表的数据导入到另一个表中:insert into ...select
- MySQL 配置优化
- MySQL配置项innodb_flush_log_at_trx_commit
- windows mysql处理ibdata1文件过大
- MySql错误处理(二) - Condition & Handle
- windows mysql处理ibdata1文件过大
- mysql主从复制
- 常用SQL语句(Mysql)总结
- 通过分区(Partition)提升MySQL性能
- mysql的分区