High performance Mysql-schema and data type optimization

Source: Internet
Author: User

MySQL supports a very high number of data types, and choosing the right data type is critical to gaining performance.
Several principles for choosing a data type
1, smaller is usually better
2, simple is good, such as using Date,time,datetime to store time instead of string

3, try to avoid null, a field if you plan to build an index, you should try to design this field as not NULL

DATETIME and TIMESTAMP
The TIMESTAMP is smaller, but the allowed time range is small.


Integer type
TINYINT 8-bit storage space, SMALLINT 16-bit storage, mediumint 24-bit storage space,
INT 32-bit storage space, BIGINT 64-bit storage

The UNSIGNED property, which represents an unsigned data type that does not allow negative values, can increase the upper limit of a positive number by 1 time times.

Int (1) and int (20) are just a little different from the display of some MySQL command-line clients, and Int (1) and int (20) are the same for storage and computation.

VarChar saves storage space, but when you update, you need to do extra work.

Char is suitable for storing very short strings, or all values are close to the same length, such as the MD5 value
Char is also better than varchar for frequently changing data, because fixed-length char is not prone to fragmentation.
char (1) and varchar store only the values of Y and N, char (1) requires only 1 bytes, and varchar (1) requires two bytes.

Int (1) and int (20) are just a little different from the display of some MySQL command-line clients, and Int (1) and int (20) are the same for storage and computation.

High performance Mysql-schema and data type optimization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.