In web development MySQL is nowadays widely used database.So speed is a major issue for all operations of MySQL . But which DB engine should be used to execute a insert operation in MySQL. MyISAM or InnoDB ? Well i had a test to track the execution time for this two types of DB engine. I was amazed with seeing the performance of these two engines.MyISAM is extremly faster than the InnoDB to execute a insert query.I executed same query several times and all the times the same thing happened.
I had two table one is with InnoDB and other is with MyISAM.Both of the table was same except the table name and DB engine used while i created these two tables.
Here is my table definitions…..
Table 1:
CREATE TABLE data(
id int not null auto_increment primary key,
name varchar(120) not null,
text varchar(120) not null) ENGINE=InnoDB;
Table 2 :
CREATE TABLE dataisam(
id int not null auto_increment primary key,
name varchar(120) not null,
text varchar(120) not null) ENGINE=MyISAM;
Here is the PHP codes to track the executing time :
<?php
ini_set('max_execution_time',600);
$connection = mysql_connect('localhost','root','') or die('error in connection!');
mysql_select_db('timetest',$connection) or die('cannot connect to database!');
$let = "abcdefghijklmnopqrstuvwxyz";
$row = 1000;
$sttime = time();
for($i=0;$i<$row;$i++)
{
$s = rand(0,25);
$l = rand(4,10);
$name = substr($let,$s,$l);
$query=mysql_query("insert into dataisam(id,name,text) values('','$name','text')");
}
$end1 = time();
for($i=0;$i<$row;$i++)
{
$s = rand(0,25);
$l = rand(4,10);
$name = substr($let,$s,$l);
$query=mysql_query("insert into data(id,name,text) values('','$name','text')");
}
$end2 = time();
$isam = $end1 - $sttime;
$inno = $end2 - $end1;
echo "MyIsam takes:".$isam."sec";
echo "Innodb takes:".$inno."sec";
?>
Now let see the execution time for these two engine:
Execution 1:
MyIsam takes:1 sec
Innodb takes:33 sec
Execution 2:
MyIsam takes:0 sec
Innodb takes:29 sec
Execution 3:
MyIsam takes:1 sec
Innodb takes:30 sec
The computer used for this test is DELL inspirion 1501(Processor: AMD Turion X2 1.6 GHz, 1024 MB ram)