[PATCH] Clarify the comments about varlena header encoding - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject [PATCH] Clarify the comments about varlena header encoding
Date
Msg-id CAJ7c6TOY_-mew61g4okz7H6+09JrwmTZEn3JnwVyeWhRXNzZGA@mail.gmail.com
Whole thread Raw
Responses Re: [PATCH] Clarify the comments about varlena header encoding
List pgsql-hackers
Hi hackers,

I noticed that the comments regarding bit layouts for varlena headers
in postgres.h are somewhat misleading. For instance, when reading:

```
00xxxxxx 4-byte length word, aligned, uncompressed data (up to 1G)
```

... one can assume this is a 00xxxxxx byte followed by another 4 bytes
(which is wrong). Also one can read this as "aligned, uncompressed
data" (which again is wrong).

```
10000000 1-byte length word, unaligned, TOAST pointer
```

This is misleading too. The comments above this line say that `struct
varatt_external` is a TOAST pointer. sizeof(varatt_external) = 16,
plus 1 byte equals 17, right? However the documentation [1] claims the
result should be 18:

"""
Allowing for the varlena header bytes, the total size of an on-disk
TOAST pointer datum is therefore 18 bytes regardless of the actual
size of the represented value.
"""

I did my best to get rid of any ambiguity. The patch is attached.

[1]: https://www.postgresql.org/docs/current/storage-toast.html

-- 
Best regards,
Aleksander Alekseev

Attachment

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: pg_walinspect: ReadNextXLogRecord's first_record argument
Next
From: Alvaro Herrera
Date:
Subject: cataloguing NOT NULL constraints