pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedVARDATA_COMPRESSED_GET_COMPRESS_METHOD comment?
5+ messages / 3 participants
[nested] [flat]
* VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment?
@ 2021-09-07 15:55 Christoph Berg <myon@debian.org>
2021-09-07 18:13 ` Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Robert Haas <robertmhaas@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Christoph Berg @ 2021-09-07 15:55 UTC (permalink / raw)
To: pgsql-hackers
In postgres.h, there are these macros for working with compressed
toast:
vvvvvvvv
/* Decompressed size and compression method of an external compressed Datum */
#define VARDATA_COMPRESSED_GET_EXTSIZE(PTR) \
(((varattrib_4b *) (PTR))->va_compressed.va_tcinfo & VARLENA_EXTSIZE_MASK)
#define VARDATA_COMPRESSED_GET_COMPRESS_METHOD(PTR) \
(((varattrib_4b *) (PTR))->va_compressed.va_tcinfo >> VARLENA_EXTSIZE_BITS)
/* Same, when working directly with a struct varatt_external */
#define VARATT_EXTERNAL_GET_EXTSIZE(toast_pointer) \
((toast_pointer).va_extinfo & VARLENA_EXTSIZE_MASK)
#define VARATT_EXTERNAL_GET_COMPRESS_METHOD(toast_pointer) \
((toast_pointer).va_extinfo >> VARLENA_EXTSIZE_BITS)
On the first line, is the comment "external" correct? It took me quite
a while to realize that the first two macros are the methods to be
used on an *inline* compressed Datum, when the second set is used for
varlenas in toast tables.
Context: Me figuring out https://github.com/credativ/toastinfo/blob/master/toastinfo.c#L119-L128
Christoph
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment?
2021-09-07 15:55 VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Christoph Berg <myon@debian.org>
@ 2021-09-07 18:13 ` Robert Haas <robertmhaas@gmail.com>
2021-09-08 15:33 ` Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Christoph Berg <myon@debian.org>
0 siblings, 1 reply; 5+ messages in thread
From: Robert Haas @ 2021-09-07 18:13 UTC (permalink / raw)
To: Christoph Berg <myon@debian.org>; pgsql-hackers
On Tue, Sep 7, 2021 at 11:56 AM Christoph Berg <myon@debian.org> wrote:
> In postgres.h, there are these macros for working with compressed
> toast:
>
> vvvvvvvv
> /* Decompressed size and compression method of an external compressed Datum */
> #define VARDATA_COMPRESSED_GET_EXTSIZE(PTR) \
> (((varattrib_4b *) (PTR))->va_compressed.va_tcinfo & VARLENA_EXTSIZE_MASK)
> #define VARDATA_COMPRESSED_GET_COMPRESS_METHOD(PTR) \
> (((varattrib_4b *) (PTR))->va_compressed.va_tcinfo >> VARLENA_EXTSIZE_BITS)
>
> /* Same, when working directly with a struct varatt_external */
> #define VARATT_EXTERNAL_GET_EXTSIZE(toast_pointer) \
> ((toast_pointer).va_extinfo & VARLENA_EXTSIZE_MASK)
> #define VARATT_EXTERNAL_GET_COMPRESS_METHOD(toast_pointer) \
> ((toast_pointer).va_extinfo >> VARLENA_EXTSIZE_BITS)
>
> On the first line, is the comment "external" correct? It took me quite
> a while to realize that the first two macros are the methods to be
> used on an *inline* compressed Datum, when the second set is used for
> varlenas in toast tables.
Well ... technically the second set are used on a TOAST pointer, which
is not really the same thing as a varlena. The varlena would start
with a 1-byte header identifying it as a TOAST pointer, and then
there'd be a 1-byte saying what kind of TOAST pointer it is, which
would be VARTAG_ONDISK if this is coming from a tuple on disk, and
then the TOAST pointer would start after that. So toast_pointer =
varlena_pointer + 2, if I'm not confused here.
But I agree with you that referring to the argument to
VARDATA_COMPRESSED_GET_EXTSIZE or
VARDATA_COMPRESSED_GET_COMPRESS_METHOD as an "external compressed
Datum" doesn't seem quite right. It is compressed, but it is not
external, at least in the sense that I understand that term.
--
Robert Haas
EDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment?
2021-09-07 15:55 VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Christoph Berg <myon@debian.org>
2021-09-07 18:13 ` Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Robert Haas <robertmhaas@gmail.com>
@ 2021-09-08 15:33 ` Christoph Berg <myon@debian.org>
2021-09-08 16:27 ` Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Robert Haas <robertmhaas@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Christoph Berg @ 2021-09-08 15:33 UTC (permalink / raw)
To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-hackers
Re: Robert Haas
> But I agree with you that referring to the argument to
> VARDATA_COMPRESSED_GET_EXTSIZE or
> VARDATA_COMPRESSED_GET_COMPRESS_METHOD as an "external compressed
> Datum" doesn't seem quite right. It is compressed, but it is not
> external, at least in the sense that I understand that term.
How about "compressed-in-line Datum" like on the comment 5 lines above?
/* caution: this will not work on an external or compressed-in-line Datum */
/* caution: this will return a possibly unaligned pointer */
#define VARDATA_ANY(PTR) \
(VARATT_IS_1B(PTR) ? VARDATA_1B(PTR) : VARDATA_4B(PTR))
/* Decompressed size and compression method of an external compressed Datum */
#define VARDATA_COMPRESSED_GET_EXTSIZE(PTR) \
(((varattrib_4b *) (PTR))->va_compressed.va_tcinfo & VARLENA_EXTSIZE_MASK)
#define VARDATA_COMPRESSED_GET_COMPRESS_METHOD(PTR) \
(((varattrib_4b *) (PTR))->va_compressed.va_tcinfo >> VARLENA_EXTSIZE_BITS)
This "external" there cost me about one hour of extra poking around
until I realized this is actually the macro I wanted.
-> /* Decompressed size and compression method of a compressed-in-line Datum */
Christoph
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment?
2021-09-07 15:55 VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Christoph Berg <myon@debian.org>
2021-09-07 18:13 ` Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Robert Haas <robertmhaas@gmail.com>
2021-09-08 15:33 ` Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Christoph Berg <myon@debian.org>
@ 2021-09-08 16:27 ` Robert Haas <robertmhaas@gmail.com>
2021-09-08 18:01 ` Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: Robert Haas @ 2021-09-08 16:27 UTC (permalink / raw)
To: Christoph Berg <myon@debian.org>; Robert Haas <robertmhaas@gmail.com>; pgsql-hackers; +Cc: Tom Lane <tgl@sss.pgh.pa.us>
On Wed, Sep 8, 2021 at 11:33 AM Christoph Berg <myon@debian.org> wrote:
> How about "compressed-in-line Datum" like on the comment 5 lines above?
That seems reasonable to me, but I think Tom Lane is responsible for
the current form of that comment, so it'd be nice to hear what he
thinks.
--
Robert Haas
EDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment?
2021-09-07 15:55 VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Christoph Berg <myon@debian.org>
2021-09-07 18:13 ` Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Robert Haas <robertmhaas@gmail.com>
2021-09-08 15:33 ` Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Christoph Berg <myon@debian.org>
2021-09-08 16:27 ` Re: VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Robert Haas <robertmhaas@gmail.com>
@ 2021-09-08 18:01 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2021-09-08 18:01 UTC (permalink / raw)
To: Robert Haas <robertmhaas@gmail.com>; +Cc: Christoph Berg <myon@debian.org>; pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Wed, Sep 8, 2021 at 11:33 AM Christoph Berg <myon@debian.org> wrote:
>> How about "compressed-in-line Datum" like on the comment 5 lines above?
> That seems reasonable to me, but I think Tom Lane is responsible for
> the current form of that comment, so it'd be nice to hear what he
> thinks.
Hmm ... looks like I copied-and-pasted that comment to the wrong place
while rearranging stuff in aeb1631ed. The comment just below is
off-point too. Will fix.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2021-09-08 18:01 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07 15:55 VARDATA_COMPRESSED_GET_COMPRESS_METHOD comment? Christoph Berg <myon@debian.org>
2021-09-07 18:13 ` Robert Haas <robertmhaas@gmail.com>
2021-09-08 15:33 ` Christoph Berg <myon@debian.org>
2021-09-08 16:27 ` Robert Haas <robertmhaas@gmail.com>
2021-09-08 18:01 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox