Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum vs String/Integer Enum

I notice that some databases like Postgres add Enum but the question is,

At what point integer/string based enum becomes a performance issue?

Following this answer about differences Postgresql enum what are the advantages and disadvantages?

Because when you use Rails or in this case Ecto from Elixir language, there is a level of abstraction so the one of the two advantages listed there becomes no an problem at all so there is only missing performance concern.

So when that advantage is really important that you dropped the disadvantages listed there

like image 453
Yordis Prieto Lazo Avatar asked Jul 05 '17 04:07

Yordis Prieto Lazo


1 Answers

Enum in PostgreSQL

  1. supported by PostgreSQL for Create Data Type.

  2. static data with ordered set values (Which is can be sort by PostgreSQL)

  3. case sensitive 'happy' is not same with 'HAPPY'
  4. Cannot input other values if not created in data type.

For Performance issue: PostgreSQL never has performance issue cause by data-type. most of them cause by indexing, configuration, and bad database design.

For Enum: in PostgreSQL They are equivalent to the enum types supported in a number of programming languages. An example of an enum type might be the days of the week, or a set of status values for a piece of data.

The translations from internal enum values to textual labels are kept in the system catalog pg_enum. Querying this catalog directly can be useful.

Note: both Native or String/Integer based type enum can't cause performance issue.

like image 108
Adrian Hartanto Avatar answered Oct 30 '22 21:10

Adrian Hartanto