Speed up creation of command completion tags
authorDavid Rowley <drowley@postgresql.org>
Thu, 15 Dec 2022 21:31:25 +0000 (10:31 +1300)
committerDavid Rowley <drowley@postgresql.org>
Thu, 15 Dec 2022 21:31:25 +0000 (10:31 +1300)
commitac998020802b742303979a13692afa7b2084d0e9
treec731037569f34cc2f52c1d94c13c1130c2e41959
parentd35a1af468162f510b6139bf81a7a41fd8ba8500
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
src/backend/tcop/cmdtag.c
src/backend/tcop/dest.c
src/include/tcop/cmdtag.h
src/include/tcop/dest.h