Have feelings, have dry goods, wechat search [ancient Legends] pay attention to this different programmer.

`operator` varchar(30) NOT NULL DEFAULT '' COMMENT 'Last Operator'.Copy the code

MySQL > NOT NULL MySQL > NOT NULL MySQL > NOT NULL

Here’s why:

1, take up space difference


The null value (”) has length 0 and does not take up space. NULL; NULL; NULL; NULL; NULL;

NULL columns require additional space in the row to record whether their values are NULL. For MyISAM tables, each NULL column takes one bit extra, rounded up to the nearest byte.

NULL columns require extra space in the row to record whether their value is NULL.

2, is not conducive to query optimization

If a query contains nullable columns, it is more difficult for MySQL to optimize because nullable columns complicate indexes, index statistics, and value comparisons.

When nullable columns are indexed, an extra byte is required for each index record, which in MyISAM can cause even fixed-size indexes (such as indexes with only one integer column) to become variable-size indexes.

References:

  • MySQL database optimizes fields to avoid NULL as much as possible
  • MySQL field attributes should be set to NOT NULL as far as possible

The article is constantly updated, you can search “ancient Tales” on wechat for the first time to read.