POC_fix_compression_in_rowtype.patch
application/octet-stream
Filename: POC_fix_compression_in_rowtype.patch
Type: application/octet-stream
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/access/heap/heaptoast.c | 17 | 0 |
| src/backend/executor/execTuples.c | 0 | 4 |
diff --git a/src/backend/access/heap/heaptoast.c b/src/backend/access/heap/heaptoast.c
index 55bbe1d..0aeea55 100644
--- a/src/backend/access/heap/heaptoast.c
+++ b/src/backend/access/heap/heaptoast.c
@@ -587,11 +587,28 @@ toast_build_flattened_tuple(TupleDesc tupleDesc,
if (!isnull[i] && TupleDescAttr(tupleDesc, i)->attlen == -1)
{
struct varlena *new_value;
+ bool changed = false;
new_value = (struct varlena *) DatumGetPointer(new_values[i]);
+
if (VARATT_IS_EXTERNAL(new_value))
{
new_value = detoast_external_attr(new_value);
+ changed = true;
+ }
+
+ if (VARATT_IS_COMPRESSED(new_value) &&
+ VARFLAGS_4B_C(new_value) != PGLZ_COMPRESSION_ID)
+ {
+ struct varlena *tmp = new_value;
+
+ new_value = detoast_attr(tmp);
+ if (changed)
+ pfree(tmp);
+ changed = true;
+ }
+ if (changed)
+ {
new_values[i] = PointerGetDatum(new_value);
freeable_values[num_to_free++] = (Pointer) new_value;
}
diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c
index 73c35df..f115464 100644
--- a/src/backend/executor/execTuples.c
+++ b/src/backend/executor/execTuples.c
@@ -2207,10 +2207,6 @@ HeapTupleHeaderGetDatum(HeapTupleHeader tuple)
Datum result;
TupleDesc tupDesc;
- /* No work if there are no external TOAST pointers in the tuple */
- if (!HeapTupleHeaderHasExternal(tuple))
- return PointerGetDatum(tuple);
-
/* Use the type data saved by heap_form_tuple to look up the rowtype */
tupDesc = lookup_rowtype_tupdesc(HeapTupleHeaderGetTypeId(tuple),
HeapTupleHeaderGetTypMod(tuple));