diff options
author | David Rowley <drowley@postgresql.org> | 2023-10-09 17:25:16 +1300 |
---|---|---|
committer | David Rowley <drowley@postgresql.org> | 2023-10-09 17:25:16 +1300 |
commit | 608fd198def5390c3490bfe903730207dfd8eeb4 (patch) | |
tree | b252efcaca1e13db80542ecd3913074a167a3590 /src/backend/utils/adt/array_userfuncs.c | |
parent | 7cc2f59dd57ab275497ae42a4f98e7936e1e3723 (diff) | |
download | postgresql-608fd198def5390c3490bfe903730207dfd8eeb4.tar.gz postgresql-608fd198def5390c3490bfe903730207dfd8eeb4.zip |
Optimize various aggregate deserialization functions
The serialized representation of an internal aggregate state is a bytea
value. In each deserial function, in order to "receive" the bytea value
we appended it onto a short-lived StringInfoData using
appendBinaryStringInfo. This was a little wasteful as it meant having to
palloc memory, copy a (possibly long) series of bytes then later pfree
that memory. Instead of going to this extra trouble, we can just fake up
a StringInfoData and point the data directly at the bytea's payload. This
should help increase the performance of internal aggregate
deserialization.
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/CAApHDvr=e-YOigriSHHm324a40HPqcUhSp6pWWgjz5WwegR=cQ@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/array_userfuncs.c')
-rw-r--r-- | src/backend/utils/adt/array_userfuncs.c | 24 |
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 5c4fdcfba46..7f87df45df6 100644 --- a/src/backend/utils/adt/array_userfuncs.c +++ b/src/backend/utils/adt/array_userfuncs.c @@ -723,12 +723,13 @@ array_agg_deserialize(PG_FUNCTION_ARGS) sstate = PG_GETARG_BYTEA_PP(0); /* - * Copy the bytea into a StringInfo so that we can "receive" it using the - * standard recv-function infrastructure. + * Fake up a StringInfo pointing to the bytea's value so we can "receive" + * the serialized aggregate state value. */ - initStringInfo(&buf); - appendBinaryStringInfo(&buf, - VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate)); + buf.data = VARDATA_ANY(sstate); + buf.len = VARSIZE_ANY_EXHDR(sstate); + buf.maxlen = 0; + buf.cursor = 0; /* element_type */ element_type = pq_getmsgint(&buf, 4); @@ -825,7 +826,6 @@ array_agg_deserialize(PG_FUNCTION_ARGS) } pq_getmsgend(&buf); - pfree(buf.data); PG_RETURN_POINTER(result); } @@ -1134,12 +1134,13 @@ array_agg_array_deserialize(PG_FUNCTION_ARGS) sstate = PG_GETARG_BYTEA_PP(0); /* - * Copy the bytea into a StringInfo so that we can "receive" it using the - * standard recv-function infrastructure. + * Fake up a StringInfo pointing to the bytea's value so we can "receive" + * the serialized aggregate state value. */ - initStringInfo(&buf); - appendBinaryStringInfo(&buf, - VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate)); + buf.data = VARDATA_ANY(sstate); + buf.len = VARSIZE_ANY_EXHDR(sstate); + buf.maxlen = 0; + buf.cursor = 0; /* element_type */ element_type = pq_getmsgint(&buf, 4); @@ -1197,7 +1198,6 @@ array_agg_array_deserialize(PG_FUNCTION_ARGS) memcpy(result->lbs, temp, sizeof(result->lbs)); pq_getmsgend(&buf); - pfree(buf.data); PG_RETURN_POINTER(result); } |