Bug #110928 Documentation about NULL saving storage looks false
Submitted: 5 May 2023 10:59 Modified: 16 May 2023 8:58
Reporter: Nikita Arykov Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any
Tags: innodb, NULL rows

[5 May 2023 10:59] Nikita Arykov
Description:
Documentation https://dev.mysql.com/doc/refman/8.0/en/data-size.html
"Declare columns to be NOT NULL if possible. It makes SQL operations faster, by enabling better use of indexes and eliminating overhead for testing whether each value is NULL. You also save some storage space, one bit per column. If you really need NULL values in your tables, use them. Just avoid the default setting that allows NULL values in every column."

I suppose "You also save some storage space, one bit per column." sentence is false. Maybe this sentence was written on MyISAM epoch and become outdated for InnoDB.

For MyISAM (https://dev.mysql.com/doc/refman/8.0/en/column-count-limit.html): NULLable columns required 1 additional byte 

For InnoDB Barracuda COMPACT row format (https://dev.mysql.com/doc/refman/8.0/en/innodb-row-format.html#innodb-row-format-compact): NULL take 1 byte or less. All other data types take 1 byte or more. As result NULL can take less space or same as other datatypes always.

How to repeat:
Just check https://dev.mysql.com/doc/refman/8.0/en/data-size.html
[5 May 2023 12:40] MySQL Verification Team
Hi Mr. Arykov,

Thank you for your bug report.

Verified as reported.
[11 May 2023 20:35] Ilya Kantor
InnoDB compact/dynamic: NULLable columns each take 1 bit always.
So total N/8 bytes for N NULLable columns.
[11 May 2023 20:35] Ilya Kantor
(rounded up)
[16 May 2023 8:58] Nikita Arykov
Hello Mr. Ilya,

Yes, you're correct. total N/8 bytes for N NULLable columns (rounded up).
Documentation say "You also save some storage space, one bit per column" (for NOT NULL columns)

However I cannot understand how it's possible to save storage. E.g.
* every NOT NULL column have some NOT NULL value and take 1 byte or more (we have no less than 1 byte data-type)
* every NULLulable column if have some NULL value take 1 byte or less

Looks like that NULL value take less space than NOT NULL
[16 May 2023 12:26] MySQL Verification Team
These are two distinct issues.

One is about saving space in the attributes and the other in table and tuples metadata.