gotchasqlMinor
Why does a MySQL MEMORY-backed table take so much more space than on disk?
Viewed 0 times
whyspacemuchdisktakethanmoremysqlmemorybacked
Problem
I have a single InnoDB table on disk, with ~1,107,423 rows and taking up 45.6 MiB disk space. The structure is:
When I create a MEMORY-backed version of this table, it takes up 803.5 MiB of memory!
It seems reasonable there'd be some expansion: a lot of extra pointers from the B-tree index or something, but increasing by a factor of 16 seems awfully excessive! What's the reason behind this?
messageid int(11)
signature varchar(255)When I create a MEMORY-backed version of this table, it takes up 803.5 MiB of memory!
It seems reasonable there'd be some expansion: a lot of extra pointers from the B-tree index or something, but increasing by a factor of 16 seems awfully excessive! What's the reason behind this?
Solution
VARCHARs are stored with a fixed length in memory, so your max length of 255 will be using a lot of space. Your InnoDB disk table will be storing the rows with a dynamic length.
http://dev.mysql.com/doc/refman/5.0/en/memory-storage-engine.html says...
types such as VARCHAR are stored using a fixed length.
http://dev.mysql.com/doc/refman/5.0/en/memory-storage-engine.html says...
- MEMORY tables use a fixed-length row-storage format. Variable-length
types such as VARCHAR are stored using a fixed length.
Context
StackExchange Database Administrators Q#28314, answer score: 4
Revisions (0)
No revisions yet.