summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/array_userfuncs.c
diff options
context:
space:
mode:
authorDavid Rowley2023-10-10 01:16:54 +0000
committerDavid Rowley2023-10-10 01:16:54 +0000
commit4f3b56eea23554e1756a26080db273156f23f4f2 (patch)
tree7e8427ae6228d2fa2eb2821d03bbe8afbcbb45ac /src/backend/utils/adt/array_userfuncs.c
parentf483b209056b4181eb33b97cd6a30910a73c0f87 (diff)
Revert "Optimize various aggregate deserialization functions"
This reverts commit 608fd198def5390c3490bfe903730207dfd8eeb4. On 2nd thoughts, the StringInfo API requires that strings are NUL terminated and pointing directly to the data in a bytea Datum isn't NUL terminated. Discussion: https://postgr.es/m/CAApHDvorfO3iBZ=xpiZvp3uHtJVLyFaPBSvcAhAq2HPLnaNSwQ@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/array_userfuncs.c')
-rw-r--r--src/backend/utils/adt/array_userfuncs.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/backend/utils/adt/array_userfuncs.c b/src/backend/utils/adt/array_userfuncs.c
index 7f87df45df6..5c4fdcfba46 100644
--- a/src/backend/utils/adt/array_userfuncs.c
+++ b/src/backend/utils/adt/array_userfuncs.c
@@ -723,13 +723,12 @@ array_agg_deserialize(PG_FUNCTION_ARGS)
sstate = PG_GETARG_BYTEA_PP(0);
/*
- * Fake up a StringInfo pointing to the bytea's value so we can "receive"
- * the serialized aggregate state value.
+ * Copy the bytea into a StringInfo so that we can "receive" it using the
+ * standard recv-function infrastructure.
*/
- buf.data = VARDATA_ANY(sstate);
- buf.len = VARSIZE_ANY_EXHDR(sstate);
- buf.maxlen = 0;
- buf.cursor = 0;
+ initStringInfo(&buf);
+ appendBinaryStringInfo(&buf,
+ VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate));
/* element_type */
element_type = pq_getmsgint(&buf, 4);
@@ -826,6 +825,7 @@ array_agg_deserialize(PG_FUNCTION_ARGS)
}
pq_getmsgend(&buf);
+ pfree(buf.data);
PG_RETURN_POINTER(result);
}
@@ -1134,13 +1134,12 @@ array_agg_array_deserialize(PG_FUNCTION_ARGS)
sstate = PG_GETARG_BYTEA_PP(0);
/*
- * Fake up a StringInfo pointing to the bytea's value so we can "receive"
- * the serialized aggregate state value.
+ * Copy the bytea into a StringInfo so that we can "receive" it using the
+ * standard recv-function infrastructure.
*/
- buf.data = VARDATA_ANY(sstate);
- buf.len = VARSIZE_ANY_EXHDR(sstate);
- buf.maxlen = 0;
- buf.cursor = 0;
+ initStringInfo(&buf);
+ appendBinaryStringInfo(&buf,
+ VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate));
/* element_type */
element_type = pq_getmsgint(&buf, 4);
@@ -1198,6 +1197,7 @@ array_agg_array_deserialize(PG_FUNCTION_ARGS)
memcpy(result->lbs, temp, sizeof(result->lbs));
pq_getmsgend(&buf);
+ pfree(buf.data);
PG_RETURN_POINTER(result);
}