MySQL--use the index to avoid null values

Source: Internet
Author: User

Due to the complexity of the database, baseless assertion space is very large, fast catching up with TCM regimen. Avoid using NULL for reasons that are mentioned in high-performance MySQL for a while. We suggest that you read more books and watch less artifice on the Internet. The book has been deliberately turned out to extract the following for reference:

To avoid NULL as much as possible
To do so, define the field as not NULL. Even if the application does not need to save NULL (no value), there are many tables that contain nullable columns (Nullable column), just because it is the default option. Unless you really want to save NULL, the column is defined as NOT NULL.

MySQL makes it difficult to optimize queries that reference nullable columns, which make indexes, index statistics, and values more complex. Empty columns require more storage space, and special processing is required within MySQL. When a nullable column is indexed, an extra byte is required for each record, which can also cause a fixed-size index in MyISAM (for example, an index on an integer column) to become a variable-size index.

Even if you want to store a field with "No value" in the table, you might not use NULL. Consider using 0, a special value, or an empty string to replace it.

Changing the null column to NOT NULL brings a small performance boost, so do not treat it as a priority optimization unless you are sure it introduces a problem. Then, if you plan to index the column, you should try to avoid setting it to nullable.

[1]. High Performance MySQL second edition page64

MySQL--use the index to avoid null values

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.