Avoid NULL if possible in mysql

You should define fields as NOT NULL whenever you can. A lot of tables include
nullable columns even when the application does not need to store NULL (the
absence of a value), merely because it’s the default. You should be careful to
specify columns as NOT NULL unless you intend to store NULL in them.
It’s harder for MySQL to optimize queries that refer to nullable columns,
because they make indexes, index statistics, and value comparisons more complicated.
A nullable column uses more storage space and requires special processing
inside MySQL. When a nullable column is indexed, it requires an extra
byte per entry and can even cause a fixed-size index (such as an index on a single
integer column) to be converted to a variable-sized one in MyISAM.
Even when you do need to store a “no value” fact in a table, you might not need
to use NULL. Consider using zero, a special value, or an empty string instead.
The performance improvement from changing NULL columns to NOT NULL is usually
small, so don’t make finding and changing them on an existing schema a priority
unless you know they are causing problems. However, if you’re planning to
index columns, avoid making them nullable if possible.

转载于:https://www.cnblogs.com/perfectdesign/archive/2009/12/08/1619422.html

猜你喜欢

转载自blog.csdn.net/weixin_34319111/article/details/94233384
今日推荐