MySQL Enum performance advantage?(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?"
这篇关于MySQL Enum 性能优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL Enum 性能优势?


基础教程推荐
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01