aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2022-07-06 09:55:30 +0900
committerMichael Paquier <michael@paquier.xyz>2022-07-06 09:55:30 +0900
commitd4bfe41281705c1bcb7093b3d07ce5ff1114341b (patch)
tree40e6a7b49f20aff8a8fef57191f70df8b2d5c4f7 /src
parent08385ed261965c4e1604e357330ac5bf9755b01a (diff)
downloadpostgresql-d4bfe41281705c1bcb7093b3d07ce5ff1114341b.tar.gz
postgresql-d4bfe41281705c1bcb7093b3d07ce5ff1114341b.zip
autho_explain: Add GUC to log query parameters
auto_explain.log_parameter_max_length is a new GUC part of the extension, similar to the corresponding core setting, that controls the inclusion of query parameters in the logged explain output. More tests are added to check the behavior of this new parameter: when parameters logged in full (the default of -1), when disabled (value of 0) and when partially truncated (value different than the two others). Author: Dagfinn Ilmari Mannsåker Discussion: https://postgr.es/m/87ee09mohb.fsf@wibble.ilmari.org
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/explain.c22
-rw-r--r--src/include/commands/explain.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 5d1f7089daf..e29c2ae206f 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -973,6 +973,28 @@ ExplainQueryText(ExplainState *es, QueryDesc *queryDesc)
}
/*
+ * ExplainQueryParameters -
+ * add a "Query Parameters" node that describes the parameters of the query
+ *
+ * The caller should have set up the options fields of *es, as well as
+ * initializing the output buffer es->str.
+ *
+ */
+void
+ExplainQueryParameters(ExplainState *es, ParamListInfo params, int maxlen)
+{
+ char *str;
+
+ /* This check is consistent with errdetail_params() */
+ if (params == NULL || params->numParams <= 0 || maxlen == 0)
+ return;
+
+ str = BuildParamLogString(params, NULL, maxlen);
+ if (str && str[0] != '\0')
+ ExplainPropertyText("Query Parameters", str, es);
+}
+
+/*
* report_triggers -
* report execution stats for a single relation's triggers
*/
diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h
index 666977fb1f8..9ebde089aed 100644
--- a/src/include/commands/explain.h
+++ b/src/include/commands/explain.h
@@ -99,6 +99,7 @@ extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
extern void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc);
extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
+extern void ExplainQueryParameters(ExplainState *es, ParamListInfo params, int maxlen);
extern void ExplainBeginOutput(ExplainState *es);
extern void ExplainEndOutput(ExplainState *es);