S
S
Stepan2012-07-24 18:31:08
MySQL
Stepan, 2012-07-24 18:31:08

TINYINT or SET?

In MySQL, I often use fields that only have a few values. For example 0,1,2,3…
Which type is better to use, TINYINT or SET ? And why?
I mainly make these fields as keys ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Melkij, 2012-07-24
@melkij

Do we remember/know that set is a bitmask that can store multiple values ​​at the same time?
The tinyint equivalent is enum. (well, or set, but then with the implementation of a bit mask, otherwise why was it necessary to do a set?)
If there can be only one value at 1 point in time - enum.
If there are several - set.
Simply because the textual representation is easier to understand than the numerical one.
All three on identical data ranges occupy an equal place. dev.mysql.com/doc/refman/5.1/en/storage-requirements.html

A
Anatoly, 2012-07-24
@taliban

And it depends where you use it. In fact, both are small, both will take up little space, but for me personally the difference is obvious:
SELECT * FROM `cars` WHERE type = 4
and
SELECT * FROM `cars` WHERE type = 'hatchback'
These queries are the same, but they say one essential advantage of set (aka enum)

E
EugeneOZ, 2012-07-24
@EugeneOZ

TINYINT. Based on advice from this book: www.amazon.com/High-Performance-MySQL-Optimization-Replication/dp/0596101716

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question