聊一聊MySQL的存储引擎
mysql> showengines;
+--------------------+---------+---------+--------------+------+------------+
| Engine | Support | Comment | Transactions| XA | Savepoints |
+--------------------+---------+---------+--------------+------+------------+
| FEDERATED | NO | | NULL | NULL | NULL |
| MEMORY | YES | | NO | NO | NO |
| InnoDB | DEFAULT | | YES | YES | YES |
|PERFORMANCE_SCHEMA | YES | | NO | NO | NO |
| MyISAM | YES | ... | NO | NO | NO |
| MRG_MYISAM | YES | | NO | NO | NO |
| BLACKHOLE | YES | | NO | NO | NO |
| CSV | YES | | NO | NO | NO |
| ARCHIVE | YES | | NO | NO | NO |
+--------------------+---------+---------+--------------+------+------------+
9 rows in set (0.00sec)
2.2 Memory
2.4 Blackhole
create table tb_myisam(
id integer primarykey,
value integer) engine=myisam;
create table tb_innodb(
id integer primarykey,
value integer) engine=innodb;
clock_gettime(CLOCK_REALTIME,&ts_start);
for(int i=1; i<=10000; i++)
{
sprintf(buf, "insert into tb_xxx(id,value)values(%d,%d)", i, i);
mysql_real_query(&conn, buf,strlen(buf));
}
clock_gettime(CLOCK_REALTIME, &ts_end);
clock_gettime(CLOCK_REALTIME,&ts_start);
for(int i=1; i<=10000;i++)
{
sprintf(buf,"select * from tb_xxx where value=%d", i);
mysql_real_query(&conn,buf, strlen(buf));
MYSQL_RES*mysql_res = mysql_store_result(&conn);
MYSQL_ROW row =mysql_fetch_row(mysql_res);
mysql_free_result(mysql_res);
}
clock_gettime(CLOCK_REALTIME,&ts_end);
sprintf(buf, "select * from tb_xxx where id=%d", i);
clock_gettime(CLOCK_REALTIME,&ts_start);
for(int i=1; i<=10000; i++)
{
sprintf(buf, "update tb_xxx setvalue=%d where id=%d", i+1, i);
mysql_real_query(&conn, buf,strlen(buf));
}
clock_gettime(CLOCK_REALTIME, &ts_end);
clock_gettime(CLOCK_REALTIME,&ts_start);
for(int i=1; i<=10000; i++)
{
sprintf(buf, "delete from tb_xxxwhere id=%d", i);
mysql_real_query(&conn, buf,strlen(buf));
}
clock_gettime(CLOCK_REALTIME, &ts_end);
相关文章