diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-01-26 16:31:48 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-01-26 16:32:19 -0500 |
commit | 3ec20c7091e97a554e7447ac2b7f4ed795631395 (patch) | |
tree | d5d4ad63f0df5f51f4e39511a2971ebe34b3df12 /src/backend/commands/explain.c | |
parent | f37ff03478aefb5e01d748b85ad86e6213624992 (diff) | |
download | postgresql-3ec20c7091e97a554e7447ac2b7f4ed795631395.tar.gz postgresql-3ec20c7091e97a554e7447ac2b7f4ed795631395.zip |
Fix EXPLAIN (SETTINGS) to follow policy about when to print empty fields.
In non-TEXT output formats, the "Settings" field should appear when
requested, even if it would be empty.
Also, get rid of the premature optimization of counting all the
GUC_EXPLAIN variables at startup. Since there was no provision for
adjusting that count later, all it'd take would be some extension marking
a parameter as GUC_EXPLAIN to risk an assertion failure or memory stomp.
We could make get_explain_guc_options() count those variables on-the-fly,
or dynamically resize its array ... but TBH I do not think that making a
transient array of pointers a bit smaller is worth any extra complication,
especially when you consider all the other transient space EXPLAIN eats.
So just allocate that array at the max possible size.
In HEAD, also add some regression test coverage for this feature.
Because of the memory-stomp hazard, back-patch to v12 where this
feature was added.
Discussion: https://postgr.es/m/19416.1580069629@sss.pgh.pa.us
Diffstat (limited to 'src/backend/commands/explain.c')
-rw-r--r-- | src/backend/commands/explain.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index f523adbc726..c367c750b19 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -626,17 +626,11 @@ ExplainPrintSettings(ExplainState *es) /* request an array of relevant settings */ gucs = get_explain_guc_options(&num); - /* also bail out of there are no options */ - if (!num) - return; - if (es->format != EXPLAIN_FORMAT_TEXT) { - int i; - ExplainOpenGroup("Settings", "Settings", true, es); - for (i = 0; i < num; i++) + for (int i = 0; i < num; i++) { char *setting; struct config_generic *conf = gucs[i]; @@ -650,12 +644,15 @@ ExplainPrintSettings(ExplainState *es) } else { - int i; StringInfoData str; + /* In TEXT mode, print nothing if there are no options */ + if (num <= 0) + return; + initStringInfo(&str); - for (i = 0; i < num; i++) + for (int i = 0; i < num; i++) { char *setting; struct config_generic *conf = gucs[i]; @@ -671,8 +668,7 @@ ExplainPrintSettings(ExplainState *es) appendStringInfo(&str, "%s = NULL", conf->name); } - if (num > 0) - ExplainPropertyText("Settings", str.data, es); + ExplainPropertyText("Settings", str.data, es); } } |