Subject RE: [firebird-support] Varchar - NULL vs blank
Author Rick Debay
Thanks. That means it's something I should bother with. Time to
requisition some more storage.

-----Original Message-----
[] On Behalf Of Ann W. Harrison
Sent: Wednesday, October 18, 2006 6:26 PM
Subject: Re: [firebird-support] Varchar - NULL vs blank

Rick Debay wrote:
> In this case I really need to know if there is a difference in the
> storage requirements.

For storage, an empty varchar and a null varchar are both blank filled,
then subjected to run-length compression. Both start with
two bytes of zero. The only slight difference is that at the
beginning of the record there's a string of bytes which represent the
null flags. A record with 14 columns will have two bytes of null flags.
If the fourth field is null, the fourth bit of the first byte will be
set. The null bytes are also subject to run length compression. If
none of the fields are null, then the null bytes are all zeros and
compressible. That's a really small difference.



Run length compression works like this. First there's a byte.
If its positive, it's followed by that many bytes of data. If it's
negative, it's followed by one byte to be repeated -1 multiplied by that
number of times. For example, this string of bytes 3, 'a', 'b', 'c',
-4, 'd' represents this string:
'abcdddd'. A 100 byte null varchar would be represented (probably,
depending on what preceded and followed it) as 2, 0, 0, -100, ' '. The
compression is done on row as a whole, not field by field.