As per memsql docs, we should use VARCHAR instead of CHAR since CHAR takes 3*length. Could somebody answer the below questions.
Is there any difference between using CHAR and VARCHAR other than the storage size. We are migrating from a Db2 database on mainframe and most of our keys are CHAR in Db2. Will there be any issue if we convert these to VARCHAR in memsql.
Following is my assumption of the length for CHAR vs VARCHAR.
CHAR - 3*Length, VARCHAR - 7 bytes for pointer + Length of the VARCHAR + 4 bytes for storing the length. But if the length of the VARCHAR is less than 7 bytes, then it is directly stored in the 7 bytes pointer.
LENGTH CHAR VARCHAR 1 3 bytes 8 bytes 2 6 bytes 8 bytes 3 9 bytes 8 bytes 4 12 bytes 8 bytes 5 15 bytes 8 bytes 6 18 bytes 8 bytes 7 21 bytes 7+8+4 - 19 bytes 8 24 bytes 8+8+4 - 20 bytes
So should we start using VARCHAR if the length is greater than 2 bytes to not waste storage ?