v1-0001-Simplify-EXPLAIN-for-how-to-append-comma-separato.patch
application/octet-stream
Filename: v1-0001-Simplify-EXPLAIN-for-how-to-append-comma-separato.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v1-0001
Subject: Simplify EXPLAIN for how to append comma separators
| File | + | − |
|---|---|---|
| src/backend/commands/explain.c | 13 | 16 |
From b5e0947808d0c858ee324e1d1f5fa96775e0903b Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Mon, 8 Dec 2025 16:20:40 +0800
Subject: [PATCH v1] Simplify EXPLAIN for how to append comma separators
Streamline how we build comma-separated lists in EXPLAIN text
output by prefixing the separator instead of appending it after
each item. This is a cosmetic simplification; behavior is unchanged.
Author: Chao Li <lic@highgo.com>
---
src/backend/commands/explain.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 7e699f8595e..55b60afaf98 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -718,6 +718,7 @@ ExplainPrintSettings(ExplainState *es)
else
{
StringInfoData str;
+ const char *sep = "";
/* In TEXT mode, print nothing if there are no options */
if (num <= 0)
@@ -730,15 +731,13 @@ ExplainPrintSettings(ExplainState *es)
char *setting;
struct config_generic *conf = gucs[i];
- if (i > 0)
- appendStringInfoString(&str, ", ");
-
setting = GetConfigOptionByName(conf->name, NULL, true);
if (setting)
- appendStringInfo(&str, "%s = '%s'", conf->name, setting);
+ appendStringInfo(&str, "%s%s = '%s'", sep, conf->name, setting);
else
- appendStringInfo(&str, "%s = NULL", conf->name);
+ appendStringInfo(&str, "%s%s = NULL", sep, conf->name);
+ sep = ", ";
}
ExplainPropertyText("Settings", str.data, es);
@@ -2961,6 +2960,7 @@ show_window_keys(StringInfo buf, PlanState *planstate,
Plan *plan = planstate->plan;
List *context;
bool useprefix;
+ const char *sep = "";
/* Set up deparsing context */
context = set_deparse_context_plan(es->deparse_cxt,
@@ -2981,9 +2981,8 @@ show_window_keys(StringInfo buf, PlanState *planstate,
/* Deparse the expression, showing any top-level cast */
exprstr = deparse_expression((Node *) target->expr, context,
useprefix, true);
- if (keyno > 0)
- appendStringInfoString(buf, ", ");
- appendStringInfoString(buf, exprstr);
+ appendStringInfo(buf, "%s%s", sep, exprstr);
+ sep = ", ";
pfree(exprstr);
/*
@@ -3058,16 +3057,14 @@ show_tablesample(TableSampleClause *tsc, PlanState *planstate,
/* Print results */
if (es->format == EXPLAIN_FORMAT_TEXT)
{
- bool first = true;
+ const char *sep = "";
ExplainIndentText(es);
appendStringInfo(es->str, "Sampling: %s (", method_name);
foreach(lc, params)
{
- if (!first)
- appendStringInfoString(es->str, ", ");
- appendStringInfoString(es->str, (const char *) lfirst(lc));
- first = false;
+ appendStringInfo(es->str, "%s%s", sep, (const char *) lfirst(lc));
+ sep = ", ";
}
appendStringInfoChar(es->str, ')');
if (repeatable)
@@ -4769,6 +4766,7 @@ static void
show_result_replacement_info(Result *result, ExplainState *es)
{
StringInfoData buf;
+ const char *sep = "";
int nrels = 0;
int rti = -1;
bool found_non_result = false;
@@ -4828,9 +4826,8 @@ show_result_replacement_info(Result *result, ExplainState *es)
refname = (char *) list_nth(es->rtable_names, rti - 1);
if (refname == NULL)
refname = rte->eref->aliasname;
- if (buf.len > 0)
- appendStringInfoString(&buf, ", ");
- appendStringInfoString(&buf, refname);
+ appendStringInfo(&buf, "%s%s", sep, refname);
+ sep = ", ";
/* Keep track of whether we see anything other than RTE_RESULT. */
if (rte->rtekind != RTE_RESULT)
--
2.39.5 (Apple Git-154)