diff options
| author | David Rowley <drowley@postgresql.org> | 2022-12-16 10:31:25 +1300 |
|---|---|---|
| committer | David Rowley <drowley@postgresql.org> | 2022-12-16 10:31:25 +1300 |
| commit | ac998020802b742303979a13692afa7b2084d0e9 (patch) | |
| tree | c731037569f34cc2f52c1d94c13c1130c2e41959 /src/include/tcop | |
| parent | d35a1af468162f510b6139bf81a7a41fd8ba8500 (diff) | |
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
Diffstat (limited to 'src/include/tcop')
| -rw-r--r-- | src/include/tcop/cmdtag.h | 5 | ||||
| -rw-r--r-- | src/include/tcop/dest.h | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/include/tcop/cmdtag.h b/src/include/tcop/cmdtag.h index 60e3179c74e..9bde568bb0e 100644 --- a/src/include/tcop/cmdtag.h +++ b/src/include/tcop/cmdtag.h @@ -13,6 +13,8 @@ #ifndef CMDTAG_H #define CMDTAG_H +/* buffer size required for command completion tags */ +#define COMPLETION_TAG_BUFSIZE 64 #define PG_CMDTAG(tag, name, evtrgok, rwrok, rowcnt) \ tag, @@ -50,9 +52,12 @@ CopyQueryCompletion(QueryCompletion *dst, const QueryCompletion *src) extern void InitializeQueryCompletion(QueryCompletion *qc); extern const char *GetCommandTagName(CommandTag commandTag); +extern const char *GetCommandTagNameAndLen(CommandTag commandTag, Size *len); extern bool command_tag_display_rowcount(CommandTag commandTag); extern bool command_tag_event_trigger_ok(CommandTag commandTag); extern bool command_tag_table_rewrite_ok(CommandTag commandTag); extern CommandTag GetCommandTagEnum(const char *commandname); +extern Size BuildQueryCompletionString(char *buff, const QueryCompletion *qc, + bool nameonly); #endif /* CMDTAG_H */ diff --git a/src/include/tcop/dest.h b/src/include/tcop/dest.h index 3c3eabae674..83d1af88b41 100644 --- a/src/include/tcop/dest.h +++ b/src/include/tcop/dest.h @@ -71,8 +71,6 @@ #include "tcop/cmdtag.h" -/* buffer size to use for command completion tags */ -#define COMPLETION_TAG_BUFSIZE 64 /* ---------------- |
