MySQL-default settings

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: unknown, value not set
empty string(''): empty, set but value is empty

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

I see that many blogs on the Internet write that null occupies one place in MyISAM, and empty string('') does not occupy one place. I feel that there is a problem (it should be that the field set to null when the table is created will have one more place to store null ) but using the DATA_LENGTH field of the tables table of the information_schema database to test and find that the increment of inserting null or empty string ('') is the same. .

ps: using the select length(''), length(null)query result is indeed '' with a length of 0

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

in conclusion:

Because the processing of null is laborious, and it is said that the index is not used when checking for null, except for special cases, it is convenient to use empty string('') (it seems to have nothing to do with the above).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325850572&siteId=291194637