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 性能优势?
基础教程推荐
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
