G
G
ggagnidze2012-07-17 13:10:50
MySQL
ggagnidze, 2012-07-17 13:10:50

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

3 answer(s)
S
Sekira, 2012-07-17
@ggagnidze

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.

M
Melkij, 2012-07-17
@melkij

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.

I
ivnik, 2012-07-17
@ivnik

If I correctly understood the task, then CHAR (1) will not suit you at all.
In this case, you can use VARCHAR(5), but SET is definitely better.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question