I’m trying to create tables to store very large volume of data, and I wonder if I can use null TIMESTAMP to save storage?
I have a variable update_at, which will be updated to NOW() whenever I modify the associated row – most of the rows will not be modified. In this case, when creating the table, will update_at TIMESTAMPTZ save me some space compared to update_at TIMESTAMPTZ NOT NULL DEFAULT NOW()?
Given Checking if string has letter e (case insensitive) sql query using one where condition, I know that:
For fixed width fields like nullable int the storage space required is
always the same regardless of whether the value is null or not.For variable width nullable fields the value ’NULL‘ takes zero bytes
of storage space (ignoring the bit to store whether the value is null
or not).
But how about TIMESTAMPTZ or DATE data types?
I’m not sure if they were "variable width nullable fields" or "fixed width nullable fields" – consequently, not sure if I can save some storage space using Null.
Thank you so much for your help!
2
Answers
A simple test could resolve this, as
Checking table size in stoge
Fiddle to test
This is not the best order for the columns, because of the data types:
The same data can be stored slightly better optimized, in blocks of 8 bytes:
Is it correct that the autorId can be NULL? If not, why do you create a unique constraint instead of a primary key? It’s also rather unusual to have a table without a primary key.
Using UpperCase in your object names like table and column names, will cause bugs forever. Also because you now have a mix of snake_case and CamelCase in your naming convention.