码迷,mamicode.com
首页 > 数据库 > 详细

MySQL-default设置

时间:2018-05-08 14:43:53      阅读:468      评论:0      收藏:0      [点我收藏+]

标签:reference   5.4   sql   ati   nal   schema   extra   lock   can   

Both statements insert a value into the phone column, but the first inserts a NULL value and the second inserts an empty string. The meaning of the first can be regarded as “phone number is not known” and the meaning of the second can be regarded as “the person is known to have no phone, and thus no phone number.”
MySQL :: MySQL 8.0 Reference Manual :: B.5.4.3 Problems with NULL Values

null:未知,未设置值
empty string(‘‘):空,设置但值为空

For MyISAM tables, NULL columns require additional space in the row to record whether their values are NULL. Each NULL column takes one bit extra, rounded up to the nearest byte.
MySQL :: MySQL 5.7 Reference Manual :: C.10.4 Limits on Table Column Count and Row Size

我见网上很多博客写的是在MyISAM中null占一位,empty string(‘‘)一位都不占,我感觉有点问题(应该是创建表时设置为null的字段会多一位来存null)但使用information_schema数据库的tables表的DATA_LENGTH字段测试时发现不论插入null还是empty string(‘‘)的增量都一样。。

ps:使用select length(‘‘), length(null)查询结果确实是‘‘长度为0

mysql> select length(‘‘), length(null);
+------------+--------------+
| length(‘‘) | length(null) |
+------------+--------------+
|          0 |         NULL |
+------------+--------------+

结论:

因为null的处理费劲,且查null的时候据说不走索引,除特殊情况还是用empty string(‘‘)方便点(好像和上面没什么关系了)。

MySQL-default设置

标签:reference   5.4   sql   ati   nal   schema   extra   lock   can   

原文地址:https://www.cnblogs.com/jffun-blog/p/9007605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!