D. Richard Hipp wrote:
> You are both right and both wrong. There are two different integer
> representations used in SQLite.
>
> (1) "varint" or variable length integer is an encoding of 64-bit
> signed integers into between 1 and 9 bytes. Negative values use the
> full 9 bytes as do large positive values. But small non-negative
> integers use just one or two bytes. Varints are used in places where
> integers are expected to be small and non-negative, such as record
> sizes in the btree (usually less than 100 bytes) and also for rowids.
>
> (2) When you store an integer into a column (a column other than the
> rowid) it is stored as a 0-, 1-, 2-, 3-, 4-, 6-, or 8-byte signed
> integer. The smallest possible representation is used, depending on
> the magnitude of the integer. The size used is actually recorded in a
> separate varint (the "type" varint) that also determines that the
> value stored is an integer and not (say) a string or blob or floating
> point number or NULL. A type varint of 1 means store a 1-byte
> integer. A type varint of 2 means store a 2-byte integer. And so
> forth. A type varint of 8 (I think) means the value is exactly 0 so
> don't store anything. 9 means the value is exactly 1. And so forth.
> Notice that the type varints are all small integers and are thus
> themselves represented by a single byte. Every value stored has a
> type varint. Additional data is stored as necessary. A zero-byte
> string or blob stores uses no space beyond its type varint. A NULL
> uses no space beyond its type varint. A numeric 0 or 1 uses no space
> beyond its type varint. An integer between -127 and +127 uses 1
> additional byte beyond its varint. A 1MB blob uses a million bytes of
> additional space beyond its type varint. And so forth.
>
>
That makes sense. Thank you for clarifying. One further question. It
seems when we profile, that a lot of time is spent encoding and decoding
varints. Are there really that many multi-byte varints in use in the
system?
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users