I have a table with ~100mln rows. One of the columns is a VARCHAR(64)
with utf8mb4
encoding for storing user nicknames (others are few integers).
The data in that column has MAX(LENGTH()) == 42
and MAX(CHAR_LENGTH()) == 24
(I can attach an image of distribution of lengths if needed). ~90% of rows only use ASCII characters.
From the MySQL docs,
CHAR(30) can hold up to 30 characters. [...] a CHAR(255) column can exceed 768 bytes
So does it mean it can store N characters, even multibyte? How about a varchar, does the specified size mean bytes or characters?
My table is mostly write-intensive (INSERT O.D.K. UPDATE
). Is it a good idea to switch to constant-length field (especially with such not-very-long strings) versus having them as a varying-length field, probably stored somewhere else on the disk?
Byte length distribution:
Char_length distribution:
CHAR
andVARCHAR
refer to characters.mb4
) theCHAR(255)
can exceed3*256
bytes. Obviously. So now the only question is whether it is worth to reduce the length of myvarchar
column (or maybe switch tovarbinary
?). I've added the distribution plots to the post.VARCHAR(..)
would consume, on average, 2+13 bytes. While `CHAR(20) would always take 20 bytes. Less space is better.