MySQL Enum 性能优势?
在字段只有 5-10 个不同可能值的情况下,使用枚举是否有性能优势?如果不是,优势是什么?
Is there a performance advantage to using enum in situations where there are only 5-10 different possible values for a field? if not what is the advantage?
推荐答案
使用 ENUM
进行以下操作会带来巨大的性能惩罚:
There is a huge performance penalty to using ENUM
for operations such as:
查询
ENUM
中允许值的列表,例如填充下拉菜单.您必须从INFORMATION_SCHEMA
查询数据类型,并从返回的 BLOB 字段中解析列表.
Query the list of permitted values in the
ENUM
, for instance to populate a drop-down menu. You have to query the data type fromINFORMATION_SCHEMA
, and parse the list out of a BLOB field returned.
改变允许的值集.它需要一个 ALTER TABLE
语句,该语句会锁定表并可能进行重组.
Alter the set of permitted values. It requires an ALTER TABLE
statement, which locks the table and may do a restructure.
我不喜欢 MySQL 的 ENUM
.我更喜欢使用查找表.另请参阅我对How to处理数据库中没有枚举字段的枚举?"
I'm not a fan of MySQL's ENUM
. I prefer to use lookup tables. See also my answer to "How to handle enumerations without enum fields in a database?"
相关文章