Skip to content

encode_key_value (crates/strata-sql/src/codec.rs:267) turns one SQL value into bytes whose bytewise order equals the value order. Keys for rows and indexes are built by concatenating these encodings.

Type Bytes
NULL 0x01
BOOL 0x02 ‖ 0x00/0x01
INT (i64) 0x03 ‖ BE u64(v ^ 2^63)
FLOAT (f64) 0x04 ‖ BE u64(o); bits = 0 for ±0.0; o = !bits if negative else bits ^ 2^63
TIMESTAMP (i64 µs) 0x05 ‖ BE u64(v ^ 2^63)
TEXT 0x06 ‖ escape(utf8)
BYTES 0x07 ‖ escape(bytes)
JSON not encodable; indexes on JSON use extracted scalar values

The signed integer rule flips the sign bit, so negative numbers sort before positive ones. For FLOAT, bits is the IEEE 754 bit pattern of the value, and both zeros use bits = 0.

escape replaces each 0x00 byte with 0x00 0xFF, then appends the terminator 0x00 0x00. The terminator sorts below every escaped content byte, so a shorter value sorts before a longer value that starts with it.

A composite key concatenates the encodings. The result sorts like the tuple. INT and FLOAT never mix in one column, because values are coerced to the column type first.

DESC index parts are catalog metadata only, see Ext D: DESC flags. Key bytes are always ascending, and descending order is served by reverse scans. No inversion exists in the encoder.