Home » Mysql » MySQL Enum performance advantage?

MySQL Enum performance advantage?

Posted by: admin November 1, 2017 Leave a comment

Questions:

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?

Answers:

There is a huge performance penalty to using ENUM for operations such as:

  • 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 the set of permitted values. It requires an ALTER TABLE statement, which locks the table and may do a restructure.

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?

Questions:
Answers:

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.

Questions:
Answers:

In this article http://fernandoipar.com/2009/03/09/using-the-enum-data-type-to-increase-performance/ Fernando looks into performances of Enum type for queries.

The result is that while using ENUM might seem a little less elegant from a design point of view (if your ENUM value are changing sometimes), the performance gain is obvious for large datasets.
See his article for details. Do you agree?

Questions:
Answers:

No, see a comparison here

The advantage lays in code readability.