mysql存储引擎MYISAM和INNODB对比测试

测试源码:

1header('Content-type:text/html;charset=utf-8;'); 2//for($num=0;$num<8;$num++){ 3 insert(); 4 insert(false); 5//} 6function insert($myisam =true){ 7 $mysqli = new mysqli('127.0.0.1','root','sa','t100w'); 8 $start = getMillisecond(); 9 $table = 'users'; 10 $type = 'innodb_group_h'; 11 if($myisam){ 12 $table.='_myisam'; 13 $type = 'myisam_group_h'; 14 } 15 $sql = ' SELECT count(*),gender FROM `'.$table.'` group by gender having count(*)>10000'; 16 /*for($i = 0 ;$i<10000;$i++) { 17 $data = array( 18 'username' => rand_string(), 19 'password' => '123456', 20 'gender' => rand_gender(), 21 'mobile' => $i % 6 == 0 ? rand_number() : '', 22 'email' => $i % 7 == 0 ? rand_string(10) : '', 23 'actived' => $i % 3 == 0 ? 1 : 0, 24 'created' => date('Y-m-d H:i:s', time()), 25 'is_del' => 0 26 ); 27 28 $sql = 'insert into '.$table.'(username,password,gender,mobile,email,actived,created,is_del) VALUES('; 29 $j=0; 30 foreach ($data as $d) { 31 if($j==7) 32 $sql .="'$d'"; 33 else 34 $sql .= "'$d'".','; 35 $j++; 36 } 37 $sql .= ')'; 38 $mysqli->query($sql); 39 unset($data); 40 }*/ 41 $mysqli->query($sql); 42 $exec_time = (getMillisecond()-$start); 43 $time_sql = "insert into time_looks(engine_table,exec_time) VALUES('$type','$exec_time')"; 44 $mysqli->query($time_sql); 45 $mysqli->close(); 46}

测试比较(极快表示小于等于1MS)

insert比较

myisam:平均5300MS innodb:平均22300MS

输入图片说明

可以看出myisam写入速度是innodb的3-4倍

大小比较:

输入图片说明

innodb占据空间近2倍于myisam

select比较

普通where子句
sqL:SELECT `id`, `username`, `password`, `gender`, `mobile`, `email`, `actived`, `created`, `is_del` FROM `users` WHERE actived=1 

输入图片说明

myisan:极快 innodb:慢

sqL:SELECT `id`, `username`, `password`, `gender`, `mobile`, `email`, `actived`, `created`, `is_del` FROM `users` WHERE actived=1 and gender=1

输入图片说明

制定越精确的条件,innodb速度提高。

like速度比较

输入图片说明

myisan:极快 innodb:慢

group by 、 distinct
 select count(*) from users group by gender;

输入图片说明 innodb稍胜

 select distinct(gender) from users where 1;

输入图片说明

myisam稍胜

having
 SELECT count(*),gender FROM `users` group by gender by count(*)>10000

输入图片说明

myisam近2倍

GROUP BY,WHERE,HAVING之间的区别和用法 1.WHERE 子句用来筛选 FROM 子句中指定的操作所产生的行。 2.GROUP BY 子句用来分组 WHERE 子句的输出。 3.HAVING 子句用来从分组的结果中筛选行。

update比较

输入图片说明

点赞
收藏

评论区

加载中...

相关推荐

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 )

KVM调整cpu和内存

一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid