Domanda

I have fields defined as integer and other defined as numeric (8,4), while it is enough for the first to be smallint and the second to be numeric (3,4) so I am just curious to know if I changed or reduced the data type limits of these fields will have any effect on db space or performance ?

È stato utile?

Soluzione

A NUMERIC(3,4) is not possible (scale has to be between 0 and the precision). Internally Firebird uses either a SMALLINT, INTEGER or BIGINT for NUMERIC and DECIMAL. For a precision up to 4 it uses SMALLINT (INTEGER for DECIMAL), 5 to 9 uses INTEGER and 10 to 18 uses BIGINT. A SMALLINT is smaller than an INTEGER (2 bytes vs 4 bytes), so it could take less space in storage.

Now if this is something that actually saves storage space or improves performance is a bit hard to tell; Firebird applies a form of Run Length Encoding on the stored record, and a prefix-compression in indexes. This makes it harder to make a definite statement about it, although I'd expect a choice for SMALLINT (and NUMERIC with scale <= 4) to actually save some space. And of course the decompressed in-memory image of the record will be smaller.

As always with performance (and this case: storage): you need to make non-trivial tests with real (or a good approximate) data to be sure. You should also ask yourself if it really matters for your specific application and usage. You can spend a lot time optimizing (or testing) something that is not really important or relevant.

Another reason for choosing smaller datatypes would be the limited size of a Firebird record (64 kilobyte total, where blobs only count for 8 bytes each), using smaller types could mean having room for additional columns.

However - IMHO - the ultimate reason for choosing a smaller datatype should be that you don't need a larger type and you want to express that limitation in the choice of datatype.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top