Consider this example – the table item has two columns, key and value. Data are as follows:
> SELECT * FROM item;
key value
------------------
1 a
2 b
87 c
Suppose we have SELECT queries by random keys between 1 to 100, and the dataset is large. My questions are:
-
does InnoDB somehow caches the “missing” keys so that it knows the key such as 3 and 4 do not exists, or must it go to the disk every time?
-
will the performance be better if we fill up the remaining key values with dummy records?
Innodb stores frequently used pages in memory so it doesn’t go to disk on every query. The size of memory buffer is defined in configuration file (usually my.cnf) and the option name is innodb_buffer_pool_size. Innodb files may also be cached by the operating system.
If you have a lot of memory available on the server consider increasing innodb_buffer_pool_size to appropriate value. More information on this: http://www.mysqlperformanceblog.com/2007/11/03/choosing-innodb_buffer_pool_size/
Inserting dummy records will make it worse – the table will be bigger.