Post on 15-Jan-2017
MySQL 5.6 MemoryKristian Köhntopp
Memory
• .frm file on disk, data in memory
• table locks
• Hash Index, BTree available
• CREATE TABLE t ( id INT, INDEX USING BTREE(id)) ENGINE = MEMORY;
2
Limits
• Fixed Length Row Storage
• VARCHAR silently becomes CHAR
• c VARCHAR(255) CHARSET utf-8
• There are no TEXT and BLOB types
3
Limits
• max_heap_table_size = 16M
• Memory tables do not shrink by DELETE
• ALTER TABLE m ENGINE=memory
4
Empty after restart
• .frm file persists, so MEMORY tables do not go away
• Data does not persist
• --init-file=autostart.sql
• insert into memory select * from disk
• Replication?!? Fake DELETE!
5
Temporary Tables
• 'using temporary' in EXPLAIN:
• Implicit temporary tables
• subject to storage conversion
• > max_heap_table OR > tmp_table_size OR not possible in MEMORY:
• converted to MyISAM!
6
Temporary Tables
• SHOW GLOBAL STATUS LIKE ‘Created_tmp_%tables’; • Created_tmp_disk_tables =2566203
• Created_tmp_tables =4914265
• 2566203/4914265*100 = 52.2195% go to disk
• > 10% → too many → check SQL!
• Created_tmp_disk_tables per second (<10 → ignore)
7
Temporary Tables
• Disk Accesses are slow.
• We do not want conversion!
• tmp_table_size == max_heap_table_size
• No TEXT or BLOB in queries with 'using temporary'
• Check out the sizes of your VARCHARs in MEMORY
8