mysql单表千万条数据测试

软件环境:win7,mysql版本5.5,InnoDB存储引擎。

硬件环境:普通笔记本,CPU P8700双核2.53GHz,内存3G,5400转机械硬盘1000GB。

建了一张表,id列是自增长bigint,再加上其他varchar、datetime型的字段,总共8个字段,通过java生成了insert的sql文件,一共62个文件,每个文件50万行(约88M),总共3100万行记录(约5.35G),通过source导入,从中午1:30一直到18:00才导完,花了快4个半小时,导完后,数据文件大小约2.5G。后来听说用load data infile可以加快导数据时间,改天再试试。

结论1:由此可见,mysql单表支持1000万条数据是完全可行的。

此时只有id列上有主键,聚集索引,测试开始。

1、整表数据行数统计(select count)

select count(*) from t_test; 

返回3100万条数据足足花了1分21秒,多次测试取平均值,也差不多要1分6秒。

select count(n_id) from t_test;

返回3100万条数据也要1分多,感觉比count(*)性能好不了多少,难道是数据量级还不够大?

给n_id建了一个非聚集索引,create index idx_nid on t_test(n_id) 耗时4分43秒。

再次 select count(n_id) from t_test;

返回3100万条数据耗时13.52秒;快了不少!

select count(*) from t_baginfo;

返回3100万条数据耗时12.86秒;比count(n_id)快约700毫秒;

结论2:在只有聚集索引的情况下,再给主键列建一个非聚集索引后,select count(*)速度可以得到很大提升

2、分页测试

a、取1万行后面10行记录:

select * from t_test limit 10000,10;耗时0.03秒

只取n_id

select n_id from t_test limit 10000,10;耗时0.01秒

b、取10万行后面10行记录:

select * from t_test limit 100000,10;耗时0.14秒

只取n_id

select n_id from t_test limit 100000,10;耗时0.08秒

c、取100万行后面的10行记录:

select * from t_test limit 1000000,10;耗时1.69秒

只取n_id

select n_id from t_test limit 1000000,10;耗时0.77秒

d、取1000万行后面的10行记录:

select * from t_test limit 10000000,10;耗时17.86秒

select * from t_test where n_id>(select n_id from t_test  limit 9999999,1 ) limit 10; 耗时18.27秒

加n_id排序:

select * from t_test order by n_id limit 10000000,10;耗时18.14秒

select * from t_test where n_id>(select n_id from t_test order by n_id limit 9999999,1 ) limit 10; 耗时18.27秒

只取n_id

select n_id from t_test limit 10000000,10;耗时4.22秒

select n_id from t_test where n_id>(select n_id from t_test  limit 9999999,1 ) limit 10; 耗时5.51秒

加n_id排序:

select n_id from t_test order by n_id limit 10000000,10;耗时17.25秒

select n_id from t_test where n_id>(select n_id from t_test order by n_id limit 9999999,1 ) limit 10; 耗时17.98秒

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

mysql设置时区

mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0