MySQL Enum performance advantage?

后端 未结 4 2079
鱼传尺愫
鱼传尺愫 2020-11-29 04:06

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?

4条回答
  •  抹茶落季
    2020-11-29 04:18

    ENUMs are represented internally by 1 or 2 bytes, depending on the number of values. If the strings you're storing are larger than 2 bytes and rarely change, then an ENUM is the way to go. Comparison will be faster with an enum and they take up less space on disk, which in turn can lead to faster seek times.

    The downside is that enums are less flexible when it comes to adding/removing values.

提交回复
热议问题