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