pgsql: Speed up creation of command completion tags

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Speed up creation of command completion tags
Date: 2022-12-15 21:32:30
Message-ID: E1p5vq9-003lnp-CR@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Speed up creation of command completion tags

The building of command completion tags could often be seen showing up in
profiles when running high tps workloads.

The query completion tags were being built with snprintf, which is slow at
the best of times when compared with more manual ways of formatting
strings. Here we introduce BuildQueryCompletionString() to do this job
for us. We also now store the completion tag's strlen in the
CommandTagBehavior struct so that we can quickly memcpy this number of
bytes into the completion tag string. Appending the rows affected is done
via pg_ulltoa_n. BuildQueryCompletionString returns the length of the
built string. This saves us having to call strlen to figure out how many
bytes to pass to pq_putmessage().

Author: David Rowley, Andres Freund
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/CAHoyFK-Xwqc-iY52shj0G+8K9FJpse+FuZ36XBKy78wDVnd=Qg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ac998020802b742303979a13692afa7b2084d0e9

Modified Files
--------------
src/backend/tcop/cmdtag.c | 72 +++++++++++++++++++++++++++++++++++++++++++++--
src/backend/tcop/dest.c | 29 +++----------------
src/include/tcop/cmdtag.h | 5 ++++
src/include/tcop/dest.h | 2 --
4 files changed, 78 insertions(+), 30 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2022-12-15 22:40:12 pgsql: Re-adjust drop-index-concurrently-1 isolation test
Previous Message Tom Lane 2022-12-15 17:18:45 pgsql: Convert range_in and multirange_in to report errors softly.