Jump to content

Recommended Posts

What are the benefits of using ENUM over small reference tables ?  IE.

 

property (

 

property_status    ENUM('open', 'closed')

 

);

 

vs.

 

property_status (

 

  id            int primary key,

  type        char(6)

)

 

insert into property_status(type) values ('open'), ('closed')

 

 

As I understand it, Mysql seems to be the only database system to support ENUM.  And it sort of violates normalization rules ( atomic values ).  Other than the benefit of easier to query and less JOIN statements, is there a performance gain to be had by using ENUM ?

Link to comment
https://forums.phpfreaks.com/topic/51805-benefits-of-using-enum/
Share on other sites

Use of ENUM should save alot of space given a column that can only have a certain values.

 

ENUM [storage requirements]...1 or 2 bytes, depending on the number of enumeration values (65,535 values maximum)

 

So, in your first example, every row would need 1 byte to store that column.  In the second example, with CHAR(6), each row would take six bytes to store that information.

 

(It seems like a colunmn could even use less -- as little as one bit for a no-null, two-value column -- but it doesn't appear it is implemented as such.)

 

So there's a storage benefit, and there may be a performance benefit on searching, but I don't know for sure.

 

As I understand it, Mysql seems to be the only database system to support ENUM.  And it sort of violates normalization rules ( atomic values ).  Other than the benefit of easier to query and less JOIN statements, is there a performance gain to be had by using ENUM ?

 

It's either "open" or "closed" - still a single value  except it's now stored as 0 or 1.

 

SETS, on the other hand, do go against the grain when it comes to normalizing repeating data items.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.