前言
今天来分享一道美团高频面试题,5 分钟搞懂“为什么 MySQL 不建议使用 NULL 作为列默认值?”。
对于这个问题,通常能听到的答案是 使用了 NULL 值的列将会使索引失效,但是如果实际测试过一下,你就知道IS NULL会使用索引.所以上述说法有漏洞.
着急的人拉到最下边看结论
Null is a special constraint of columns. The columns in table will be
added null constrain if you do not define the column with “not null”
key words explicitly when creating the table.Many programmers like to
define columns by default because of the conveniences(reducing the
judgement code of nullibility) what consequently cause some
uncertainty of query and poor performance of database.
NULL值是一种对列的特殊约束,我们创建一个新列时,如果没有明确的使用关键字not null声明该数据列,Mysql会默认的为我们添加上NULL约束. 有些开发人员在创建数据表时,由于懒惰直接使用 Mysql 的默认推荐设置.(即允许字段使用NULL值).而这一陋习很容易在使用NULL的场景中得出不确定的查询结果以及引起数据库性能的下降.
介绍
Null is null means it is not anything at all,we cannot think of