1. Select the type of data optimization
Several principles: smaller is usually better to avoid it simple NULL
When selecting the type of data, to choose the right major types: numeric, string, and time. Next select the particular type.
Specific types include:
1.1 integer types
If the integer is stored, you can use the following types of data:
TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT. They were used 8,16,24,32,64 bit memory space. Optional UNSIGNED attribute.
1.2 Real type
If the real storage type: FLOAT and DOUBLE support the use of approximate calculation standard floating-point arithmetic, and for storing DECIMAL type exact decimal.
In the same type of floating-point value range of the storage, generally use less space than DECIMAL. It uses 4 bytes storage FLOAT, and DOUBLE 8 bytes. Because of the cost, unless you want an accurate calculation of the fractional Do not use DECIMAL.
1.3 string type
VARCHAR
VARCHAR for storing variable length strings, less space than CHAR. VARCHAR using 1 or 2 additional bytes record length of the string. VARCHAR saves storage space, so the performance can also help.
The following case is suitable for use VARCHAR:
1. The maximum length of a string column is much larger than the average length;
2. Update column rarely;
3.UTF-8 character set, each character is stored with a different number of bytes
CHAR
CHAR type is a fixed length: MySQL always allocated enough space defined according to string length.
When CHAR values are stored, MySQL will remove all trailing spaces. CHAR adapted to store a very short string, or all values are close to the same length.
BINARY and VARBINARY binary strings are stored.
BLOB and TEXT types
String data type for the storage of large data designed, and the characters are stored in binary.
Enum (the ENUM) instead of a string type
Let's reduce the size of the table, and when after the column are converted to ENUM, and soon became associated.
1.4 Date and Time Types
DATETIME
TIMESTAMP
Usually try to use TIMESTAMP, because it is higher than the DATETIME space efficiency.
1.5 Data Type
BIT
SET
Bit column operations on integer
1.6 selection identifiers
Integer type
It is usually an integer column identifies the best choice, because they can be used quickly and AUTO_INCREMENT.
ENUM and SET types
avoid
String type
avoid
2.MySQL schema design trap
Great columns
Almighty enumeration
3. paradigm and counter-paradigm