When to use NULL in MySQL tables

后端 未结 11 1818
春和景丽
春和景丽 2020-11-29 22:59

I appreciate the semantic meaning of a NULL value in a database table, different from both false and the empty string \'\'. However, I have often read about performance pro

11条回答
  •  有刺的猬
    2020-11-29 23:38

    The main benefit, of course, is the semantic meaning of NULL, which you mentioned.

    In addition to that -- and it may depend on your storage engine, as always, check the documentation -- but in at least some databases, NULLs take up a lot less room than a regular value. For example, if you have a "varchar" column declared to be 20 characters, and it's rarely filled in, you can save a lot of disk space by making it NULL instead of an empty string.

    I have never heard of any performance issues with using NULLs, one the opposite. I've heard of people mucking up their counts because they counted NULLs wrong, but never performance. If that's a real thing, I would love to hear about it!

提交回复
热议问题