Use the correct PG_DETOAST_DATUM macro in BRIN
authorTomas Vondra <[email protected]>
Sun, 14 Apr 2024 16:19:52 +0000 (18:19 +0200)
committerTomas Vondra <[email protected]>
Sun, 14 Apr 2024 16:19:58 +0000 (18:19 +0200)
Commit 6bcda4a721 replaced PG_DETOAST_DATUM with PG_DETOAST_DATUM_PACKED
in two BRIN output functions, for minmax-multi and bloom opclasses. But
this is incorrect - the code is accessing the data through structs that
already include a 4B header, so the detoast needs to match that. But the
PACKED macro may keep the 1B header, which means the struct fields will
point to incorrect data.

Backpatch-through: 16
Discussion: https://postgr.es/m/1df00a66-db5a-4e66-809a-99b386a06d86%40enterprisedb.com

src/backend/access/brin/brin_bloom.c
src/backend/access/brin/brin_minmax_multi.c

index 71749e6143032e34b39aa90fc2b49d5c045102b0..f94e2b0bfbd95fae6a90542f4e647414854b7c07 100644 (file)
@@ -800,7 +800,7 @@ brin_bloom_summary_out(PG_FUNCTION_ARGS)
    StringInfoData str;
 
    /* detoast the data to get value with a full 4B header */
-   filter = (BloomFilter *) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(0));
+   filter = (BloomFilter *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 
    initStringInfo(&str);
    appendStringInfoChar(&str, '{');
index c5962c00d6483243086a6614a1fe82b3b9e6e203..e5d95de5d84a7434ee7556e30c951d04b65d6001 100644 (file)
@@ -3023,7 +3023,7 @@ brin_minmax_multi_summary_out(PG_FUNCTION_ARGS)
     * Detoast to get value with full 4B header (can't be stored in a toast
     * table, but can use 1B header).
     */
-   ranges = (SerializedRanges *) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(0));
+   ranges = (SerializedRanges *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 
    /* lookup output func for the type */
    getTypeOutputInfo(ranges->typid, &outfunc, &isvarlena);