Skip to content Skip to sidebar Skip to footer

Is There Any Difference In Saving Same Value In Different Integer Types?

The main integer fields in Django are the following, Integer Field An integer. Values from -2147483648 to 2147483647 are safe in all databases supported by Django. The default for

Solution 1:

Most operations are fastest for plain integer, but the difference is very small and typically the least of your concerns when optimizing performance.

Storage size is more relevant, but the difference between various integer types is still very small and often hardly relevant, sometimes lost to padding and alignment. There are other data types that can waste much more space.

smallint (int2) occupies 2 bytes on disk and in RAM. integer (int, int4) occupies 4 bytes on disk and in RAM. bigint (int8) occupies 8 bytes on disk and in RAM.

Details for numeric types in Postgres in the manual.

There are various other factors for actual storage size. You have to consider page and tuple overhead, alignment and padding, possible NULL values, indexing ...

Details:

There is some potential for optimizing, but typically not much. Best concentrate on choosing an appropriate data type for your data and don't worry about minor differences in storage and performance, unless you know exactly what you are doing.

Solution 2:

Yes, the memory storage and runtime memory allocated for your numeric data will be directly proportional to the byte size of the numeric structure you choose.

There are some compression methods such as changing integers and decimals to the variable-length format instead of their native fixed-length format for SQL server. However, they introduce higher CPU usage as mentioned here.

Post a Comment for "Is There Any Difference In Saving Same Value In Different Integer Types?"