Join performance of MyISAM and Innodb
We had discussion today which involved benchmarks of Join speed for MyISAM and Innodb storage engines for CPU bound workload, this is when data size is small enough to fit in memory and so buffer pool.
I tested very simple table, having with about 20.000 rows in it on 32bit Linux. The columns "id" "i" and "c" were populated with same integers so we can allow the same job to be done using different kinds of columns - primary key, integer indexed column and indexed char column. The query is also trivial - the point was to make sure it is not index covered query so it reads the rows and it does not return many rows. I varied the join clause to be id, i and C columns appropriately.
-
CREATE TABLE `t1` (
-
`id` int(10) UNSIGNED NOT NULL DEFAULT '0',
-
`i` int(10) UNSIGNED NOT NULL DEFAULT '0',
-
`c` char(15) DEFAULT NULL,
-
`pad` char(8) DEFAULT NULL,
-
PRIMARY KEY (`id`),
-
KEY `i` (`i`),
-
KEY `c` (`c`)
-
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-
-
SELECT count(t1.pad),count(t2.pad) FROM t1,t1 t2 WHERE t1.id=t2.id;
The result I've got are as follows
| Storage Engine | ID | I | C |
| MyISAM | 0.24s | 0.27s | 1.19s |
| Innodb | 0.07s | 0.30s | 0.38s |
As you see in such circumstances Innodb is actually faster than MyISAM in 2 cases out of 3. I guess the reasons are the following:
- Innodb primary key joins are very fast as data is clustered together with index and generally highly optimized
- Innodb builds hash indexes which helps to speed up lookup by indexes by passing BTREE index and using hash, which is faster
- MyISAM does compression for character keys which makes it perform slower for random lookups
- MyISAM generally has lower processing overhead due to its simplicity
- MyISAM still a bit better by primary key join than for secondary key join. I guess because it knows for sure there is no more than one row which matches the index, so there is no need for MySQL to request next row matching index
Note: This applies to CPU bound workload with all content fitting in memory. In other cases situation is very different and MyISAM compression for char keys could frequently positevely impact performance.
2 Comments
Trackbacks/Pingbacks
- MySQL Developer » Blog Archive » MyISAM to InnoDB
[...] Join Performance of MyISAM and InnoDB [via Planet MySQL] [...] - InnoDB is better for SugarCRM - Blog of Leonid Mamchenkov
[...] similarly brief Google search suggested (see here and here) and explained converting MySQL tables from MyISAM to InnoDB. A test has been performed and [...]











del.icio.us
digg
how different becomes the situation, when a join both myisam and innodb tables together.
exampe:
- table a is myisam, table b is innodd
- select … from a inner join b on a.x=b.x
additional question: lets assume both tables will be big, so will the table b (innodb) be locked by row, or as whole?
Comment :: August 7, 2006 @ 3:30 am
Feel fee to test it Stefan
Generally for join the table which gets random lookup is more important – table which is having full table scan or range scan contributes less to total prformance.
So in our case performance will be similar to join of two Innob tables.
…Also no locks will be happening. Innodb does not lock rows for normal selects, consistent reads are used instead.
Comment :: August 7, 2006 @ 9:05 am