Subject Re: [firebird-support] Calculate table size
Author Ivan Prenosil
> Hi, I have a table with the following columns:
>
> ID BIGINT NOT NULL,
> A_ID BIGINT,
> EVENT_NUMBER BIGINT,
> EVENT_SOURCE VARCHAR(50),
> EVENT_TYPE SMALLINT,
> EVENT_TIME TIMESTAMP,
> EVENT_MESSAGE VARCHAR(10240),
> B_ID BIGINT
>
> I added one record of
> {1, 1, 1, 'abcdefghij', 1, '1/8/2006 12:00:00',
> 'abcdefghijklmnopqrstuvwxyz1234', null}. (The character set is
> UNICODE_FSS)
>
> gstat shows the record length is 556,

Which is right.

> which is far more than my
> calculation of
>
> 4 * BIGINT + 1 * TIMESTAMP + 1 * SMALLINT + 10(/*EVENT_SOURCE*/) *
> 2(/*UNICODE*/) + 30(/*EVENT_MESSAGE*/) * 2(/*UNICODE*/) = 122 BYTES.
>
> How does gstat calculate record length?

gstat does not calculate anything, it just shows what it finds.
Each row is stored in memory in its full declared length
(for your unicode_fss varchar(10240) field it is 30720 bytes).
Before storing it onto db page, whole row is rle compressed.
The maximum "performance" rle can offer is that it compresses
128 identical consecutive bytes into 2 bytes. It means that even if your
long field is empty it will consume at least 30720/128*2 = 480 bytes.

You can find some short notes here
http://www.volny.cz/iprenosil/interbase/ip_ib_strings.htm

Ivan