MySQL Enum 性能优势? [英] MySQL Enum performance advantage?

查看:43
本文介绍了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 from INFORMATION_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 性能优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆