Optimal engine for small lookup tables in MySQL
-
26-09-2020 - |
Question
I have following question: I am designing web application with several dozens of small lookup tables: These tables usualy contain three columns (ID, Name, Description) and a couple of rows (mostly fewer than 50, max is about 450).
These lookup tables are expected to change only rarely (they come from standard, which changes once in several years) and will be used only to:
- fill options in html select
- be joined to other records in reports
There will be only SELECT
statements on these tables 99 % of times, but there will be quite a lot of them.
I am wondering, which database engine would be most efficient to use?
Here are my considerations:
MEMORY
- pro: very fast
- con: if the server crashes, all data are lost and need to be recreated
- con: does not support foreign keys
compressed MyISAM
- pro: fast
- con: does not support foreign keys
InnoDB
- pro: foreign key support
What I would like to ask, is whether there will be significant advantage in using something different than InnoDB - performance-wise
Thanks, Zbynek
Solution
I answered a similar question in Aug 2011 : Which DBMS is good for super-fast reads and a simple data structure?
Since you are asking about MySQL and which storage engine. To be honest, it is hard to say because there are rare occasions when MyISAM can outperform InnoDB when it comes to SELECTs.
Here are some of my past posts on this controversy
Sep 20, 2011
: Best of MyISAM and InnoDBMay 03, 2012
: Which is faster, InnoDB or MyISAM?Jul 05, 2012
: InnoDB vs MyISAM with many indexesSep 26, 2012
: Choosing MyISAM over InnoDB for these project requirements; and long term options
You might asking right now : Why would I ever favor MyISAM over InnoDB ?
Take a look at this diagram (created by Vadim Tkachenko, Percona CTO)
MyISAM will cache indexes and your table would have 2 indexes (PRIMARY KEY on id and an index of Name). On the other hand, InnoDB has too many moving parts to accommodate for, especially if the InnoDB Buffer Pool has to load and dismiss 16K pages periodically.
To be fair, you should do an experiment.
- Go to my post What are the main differences between InnoDB and MyISAM?. Read it carefully.
- Setup a server using MyISAM and all your tables using
ROW_FORMAT=Fixed
(See my post What is the performance impact of using CHAR vs VARCHAR on a fixed-size field?) and use a large key_buffer_size. - Setup another server using InnoDB and a large innodb_buffer_pool_size.
- Add your data to both server and query them like crazy.
This will give you the best assessment for Storage Engine choice for your dataset.
GIVE IT A TRY !!!
OTHER TIPS
- "Compressed MyISAM" -- what is that? Maybe "Archive"?
- Compression is not needed; the tables are too small, and will quickly be fully cached.
FOREIGN KEYS
-- Why? You have debugged you code, haven't you? There will be no dangling things to check.MEMORY
is not unreasonable, if you write 'reload' code that executes whenever you bring up the server, and any updates to the table are writen to both to theMEMORY
table an the persistent backup.MyISAM
ROW_FORMAT=FIXED
-- that's an old wive's tale; useDYNAMIC
andVARCHARs
.- InnoDB's "clustered"
PRIMARY KEY
makes lookups a little faster than MyISAM for your purpose. - Do you know that the lookup tables are causing a noticeable slowdown? I seriously doubt that they are.
- Do not use lookup tables for "continuous" values, such as
FLOATs
andDATEs
.
I vote for InnoDB without FKs.