One performance gotcha with MEMORY tables you might know about comes from the fact it is the only MySQL storage engine which defaults to HASH index type by default, instead of BTREE which makes indexes unusable for prefix matches or range lookups. This is however not performance gotcha I'm going to write about. There is one more thing you should be aware which again comes from the fact MEMORY tables use HASH indexes by default.
I've created rather similar test table:
PLAIN TEXT SQL:
- CREATE TABLE `test` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `c` tinyint(4) DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `c` (`c`)
- ) ENGINE=MEMORY
and populated it with 1.000.000 rows ALL of them having same value for c column.
Now I'm performing random deletes by primary key (DELETE FROM test WHERE …
[Read more]