Previous Topic: NDB Key Structure

Next Topic: Suggested Key Ranges

Storage of Values

Field values and sequence key values are stored as follows:

CHAR fields

The character field value, padded to (keylen-8) with blanks.

NUM fields

4 bytes, binary, with the sign bit inverted (that is, 0 is stored as X'80000000', 100 is X'80000064'). Padded to (keylen-8) with binary 0.

HEX fields

Stored in compressed hexadecimal format. Padded to (keylen-9) with binary 0. The last byte (of the value part, not of the total key) contains the significant length in binary (so X'ABCD' and X'ABCD00' are distinct; X'ABCD' is stored as X'ABCD0000...02' and X'ABCD00' is stored as X'ABCD0000...03').

DATE fields

Stored in unsigned packed. For example, 21 September 2004 is stored as X'040921'. Padded to (keylen-8) with binary 0.

FLOAT fields

Stored in 8-byte floating point, with the following change to force character compares to work correctly:

CDATE fields

Stored internally in 3-byte binary with value 1 (x'000001') representing 1/1/0001. Key length padding is binary 0.

TIME fields

Stored internally in 5-byte binary as a number of micro-seconds, values from 0 to 86,399,999,999 (86,400 seconds in a day, times 1000000 for microseconds, -1 microsecond). The largest hexadecimal value is x'141DD75FFF'. Key length padding is binary 0.

TIMESTAMP fields

Stored internally as a concatenation of the CDATE (3-byte) and TIME (5-byte) fields (CDATE first). Thus a TIMESTAMP takes 8-bytes. Key length padding is binary 0.