Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Your statement is wrong in the general case. It probably depends on the DB engine and several parameters, but, at least with MariaDB/MySQL, allowing NULL increases the disk usage. See https://stackoverflow.com/questions/13207838/disk-space-impl...


Their statement is not “in the general case” though, it’s specifically for postgres.

Postgres uses a fixed-size null bitmap and variable-size rows, so a NULL value takes one bit in the bitmap (and additional nullable columns may require a wider bitmap), but they are skipped in the row itself.


Postgres uses 1 bit per NULL value, though the reality is more complex as everything is padded for alignment. So fewer than 8 nullable columns are free, and above that you pay probably 8 bytes at once (I'm not totally sure on the exact numbers here).

So for Postgres it is generally true that storing NULLs is very cheap in most cases.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: