MySQL枚举性能优势? [英] MySQL Enum performance advantage?
问题描述
在一个字段中只有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
用于以下操作:
-
查询
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
的粉丝。我更喜欢使用查找表。另请参阅我的答案如何处理在数据库中没有枚举字段的枚举?
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?"
这篇关于MySQL枚举性能优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!