Hieu Nguyen

Reading note: High Performance MySQL - Choose optimal types

Jun 6 2018


Things to remember

Example:

Steps to choose type

Whole Number

type name | TINYINT | SMALLINT | MEDIUMINT | INT    | BIGINT
------------------------------------------------------------
size      | 8 bit   | 16 bit   | 32 bit    | 32 bit | 64 bit

Real Number

String

type name |  VARCHAR                           | CHAR
---------------------------------------------------------------------------------------
attribute | - variable-length string           | - fixed length string
          | - preserves trailing white spaces  | - removes trailing while spaces
---------------------------------------------------------------------------------------
usage     | - maximum length is much bigger    | - fixed-size column like password hash
          | than average length                |

Datetime

type name | DATETIME                           | TIMESTAMP
----------------------------------------------------------------------------------------
attribute | - ranges from year 1001 to year    | - ranges from midnight 01/01/1970 (GMT)
          | 9999.                              | to 2038
          | - stores as an integer in          | - stores the seconds from the start
          | YYYYMMDDHH-MMSS format             | time as an integer
          | - value is timezone independent    | - value is timezone dependent

Bit-packed Data type

Choosing identifiers

type name   | Integers              | Set or Enum           | String
----------------------------------------------------------------------------------
Performance | Good                  | Good                  | Bad
----------------------------------------------------------------------------------
Simplicity  | Good - has            | Bad - No              | Normal - randomize
            | AUTO-INCREMENT        | AUTO-INCREMENT        |
----------------------------------------------------------------------------------
Flexibility | Good                  | Bad - should be used  | Good
            |                       | only for static table |