Answer the question
In order to leave comments, you need to log in
Which field type is better: SET or CHAR(1)?
Good day.
The field can store a limited number of values (no more than 5, SET logic).
From the point of view of saving memory, which is more correct to use:
SET('atype1', 'btype2', 'ctype3', 'dtype4')
or
CHAR (1) and use a, b, c, d?
Explain the answer.
Thank you.
Answer the question
In order to leave comments, you need to log in
SET is better, since it is stored as a number, and the comparison of numbers to names is separate. And CHAR is text.
Searching by numbers is faster, so SET.
Just in case - don't you confuse SET and ENUM? The first one is a bit mask, which allows storing multiple flags at the same time.
Therefore, if you need set logic, char is not suitable for you (well, except for the case that you yourself, for some reason, on a character field, will make a bit mask).
And I will additionally correct Sekira:
mysql operate on symbols. Therefore, for utf8, char(1) will take 3 bytes, and varchar(5) will take 2-17 bytes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question