Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

space consumption of null columns in sqlite db

Tags:

sqlite

Say I have a db column that's only used rarely by records in my sqlite db (for the rest of the records, the value is null), would those null columns consume as much space comparable to if those columns were non-existent?

like image 367
jingyin Avatar asked Aug 13 '11 16:08

jingyin


People also ask

Do null columns take up space?

One common misconception about NULL values is that they represent “nothing” or “no value.” NULLs are indeed a value. They take up space on your database hard drive as opposed to “nothing” that indicates there is no value.

How much space does a null value takes in SQL Server?

A NULL value in databases is a system value that takes up one byte of storage and indicates that a value is not present as opposed to a space or zero or any other default value.

How much space does SQLite use?

The maximum size of a database file is 4294967294 pages. At the maximum page size of 65536 bytes, this translates into a maximum database size of approximately 1.4e+14 bytes (281 terabytes, or 256 tebibytes, or 281474 gigabytes or 256,000 gibibytes).

How does SQL store null values?

Each row has a null bitmap for columns that allow nulls. If the row in that column is null then a bit in the bitmap is 1 else it's 0. For variable size datatypes the acctual size is 0 bytes.


1 Answers

In my test program, NULL values have consumed one byte per row. If the average row size in your table will be above 100 bytes, then yes, it's comparable to nonexistent.

like image 179
hamstergene Avatar answered Sep 27 '22 20:09

hamstergene