pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Optimize various aggregate deserialization functions 2+ messages / 1 participants [nested] [flat]
* pgsql: Optimize various aggregate deserialization functions @ 2023-10-09 04:25 David Rowley <drowley@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: David Rowley @ 2023-10-09 04:25 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/608fd198def5390c3490bfe903730207dfd8eeb4 Modified Files -------------- src/backend/utils/adt/array_userfuncs.c | 24 ++++++++--------- src/backend/utils/adt/numeric.c | 48 ++++++++++++++++----------------- src/backend/utils/adt/varlena.c | 12 ++++----- 3 files changed, 42 insertions(+), 42 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Optimize various aggregate deserialization functions, take 2 @ 2023-10-26 21:42 David Rowley <drowley@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: David Rowley @ 2023-10-26 21:42 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Optimize various aggregate deserialization functions, take 2 f0efa5aec added initReadOnlyStringInfo to allow a StringInfo to be initialized from an existing buffer and also relaxed the requirement that a StringInfo's buffer must be NUL terminated at data[len]. Now that we have that, there's no need for these aggregate deserial functions to use appendBinaryStringInfo() as that rather wastefully palloc'd a new buffer and memcpy'd in the bytea's buffer. Instead, we can just use the bytea's buffer and point the StringInfo directly to that using the new initializer function. In Amdahl's law, this speeds up the serial portion of parallel aggregates and makes sum(numeric), avg(numeric), var_pop(numeric), var_samp(numeric), variance(numeric), stddev_pop(numeric), stddev_samp(numeric), stddev(numeric), array_agg(anyarray), string_agg(text) and string_agg(bytea) scale better in parallel queries. Author: David Rowley Discussion: https://postgr.es/m/CAApHDvr%3De-YOigriSHHm324a40HPqcUhSp6pWWgjz5WwegR%3DcQ%40mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/0c882a298881056176a27ccc44c5c3bb7c8f308c Modified Files -------------- src/backend/utils/adt/array_userfuncs.c | 20 +++++++---------- src/backend/utils/adt/numeric.c | 40 +++++++++++++-------------------- src/backend/utils/adt/varlena.c | 10 ++++----- 3 files changed, 28 insertions(+), 42 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2023-10-26 21:42 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2023-10-09 04:25 pgsql: Optimize various aggregate deserialization functions David Rowley <drowley@postgresql.org> 2023-10-26 21:42 pgsql: Optimize various aggregate deserialization functions, take 2 David Rowley <drowley@postgresql.org>
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