Learned:
NULL semantics are unclear
Query is not easy to optimize
If it represents a null value, there can be other alternatives (logically)
VARCHAR(100) NOT NULL DEFAULT '';
INT NOT NULL DEFAULT 0;
I hope to understand the attitude towards NULL when designing a scheme (I remember reading an article saying that you should try: NOT NULL DEFAULT XXX)
是,应该尽可能避免可为NULL的列,且尽可能显示设置默认值,尤其是被索引的列。mysql中,null占空间,如果该值被索引,那么其索引无效。
是的,判断字段不为空的时候,还要用 is not null,mysql中的NULL其实是占用空间的,B树索引时不会存储NULL值的,所以如果索引的字段可以为NULL,索引的效率会下降很多。