From 19970655726681abe5ecc7197316341c694ef1e1 Mon Sep 17 00:00:00 2001 From: Aleksander Alekseev Date: Wed, 17 Aug 2022 20:48:43 +0300 Subject: [PATCH v2] Clarify the comments about varlena header encoding This patch fixes somewhat misleading comments regarding the encoding of the varlena header. Author: Aleksander Alekseev Reviewed-by: John Naylor Discussion: https://postgr.es/m/CAJ7c6TOY_-mew61g4okz7H6%2B09JrwmTZEn3JnwVyeWhRXNzZGA%40mail.gmail.com --- src/include/postgres.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/include/postgres.h b/src/include/postgres.h index 13903fa022..405bb2bdfd 100644 --- a/src/include/postgres.h +++ b/src/include/postgres.h @@ -179,17 +179,17 @@ typedef struct /* * Bit layouts for varlena headers on big-endian machines: * - * 00xxxxxx 4-byte length word, aligned, uncompressed data (up to 1G) - * 01xxxxxx 4-byte length word, aligned, *compressed* data (up to 1G) - * 10000000 1-byte length word, unaligned, TOAST pointer - * 1xxxxxxx 1-byte length word, unaligned, uncompressed data (up to 126b) + * 0b00xxxxxx 4-byte length word (aligned), uncompressed data (up to 1G) + * 0b01xxxxxx 4-byte length word (aligned), *compressed* data (up to 1G) + * 0b10000000 1-byte length word (unaligned), type tag, TOAST pointer + * 0b1xxxxxxx 1-byte length word (unaligned), uncompressed data (up to 126b) * * Bit layouts for varlena headers on little-endian machines: * - * xxxxxx00 4-byte length word, aligned, uncompressed data (up to 1G) - * xxxxxx10 4-byte length word, aligned, *compressed* data (up to 1G) - * 00000001 1-byte length word, unaligned, TOAST pointer - * xxxxxxx1 1-byte length word, unaligned, uncompressed data (up to 126b) + * 0bxxxxxx00 4-byte length word (aligned), uncompressed data (up to 1G) + * 0bxxxxxx10 4-byte length word (aligned), *compressed* data (up to 1G) + * 0b00000001 1-byte length word (unaligned), type tag, TOAST pointer + * 0bxxxxxxx1 1-byte length word (unaligned), uncompressed data (up to 126b) * * The "xxx" bits are the length field (which includes itself in all cases). * In the big-endian case we mask to extract the length, in the little-endian @@ -198,8 +198,8 @@ typedef struct * this lets us disambiguate alignment padding bytes from the start of an * unaligned datum. (We now *require* pad bytes to be filled with zero!) * - * In TOAST pointers the va_tag field (see varattrib_1b_e) is used to discern - * the specific type and length of the pointer datum. + * For the TOAST pointers the type tag (see varattrib_1b_e.va_tag field) is + * used to discern the specific type and length of the pointer datum. */ /* -- 2.37.2