summaryrefslogtreecommitdiff
path: root/src/include/pgstat.h
diff options
context:
space:
mode:
authorAndres Freund2017-09-19 18:46:07 +0000
committerAndres Freund2017-09-19 19:51:14 +0000
commit54b6cd589ac2f5635a42511236a5eb7299e2dcaf (patch)
treed3ee7ba947177ad35c4ed42bf221bd850b7ea0aa /src/include/pgstat.h
parentd1687c6926819f023c78b353458950a303796aba (diff)
Speedup pgstat_report_activity by moving mb-aware truncation to read side.
Previously multi-byte aware truncation was done on every pgstat_report_activity() call - proving to be a bottleneck for workloads with long query strings that execute quickly. Instead move the truncation to the read side, which commonly is executed far less frequently. That's possible because all server encodings allow to determine the length of a multi-byte string from the first byte. Rename PgBackendStatus.st_activity to st_activity_raw so existing extension users of the field break - their code has to be adjusted to use pgstat_clip_activity(). Author: Andres Freund Tested-By: Khuntal Ghosh Reviewed-By: Robert Haas, Tom Lane Discussion: https://postgr.es/m/20170912071948.pa7igbpkkkviecpz@alap3.anarazel.de
Diffstat (limited to 'src/include/pgstat.h')
-rw-r--r--src/include/pgstat.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 57ac5d41e46..52af0aa5415 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -1003,8 +1003,14 @@ typedef struct PgBackendStatus
/* application name; MUST be null-terminated */
char *st_appname;
- /* current command string; MUST be null-terminated */
- char *st_activity;
+ /*
+ * Current command string; MUST be null-terminated. Note that this string
+ * possibly is truncated in the middle of a multi-byte character. As
+ * activity strings are stored more frequently than read, that allows to
+ * move the cost of correct truncation to the display side. Use
+ * pgstat_clip_activity() to truncate correctly.
+ */
+ char *st_activity_raw;
/*
* Command progress reporting. Any command which wishes can advertise
@@ -1193,6 +1199,8 @@ extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
extern void pgstat_initstats(Relation rel);
+extern char *pgstat_clip_activity(const char *activity);
+
/* ----------
* pgstat_report_wait_start() -
*