subplanarguments.patch
text/plain
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: unified
| File | + | − |
|---|---|---|
| src/backend/utils/adt/ruleutils.c | 47 | 19 |
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index d16f1c4..68302e4 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -206,6 +206,7 @@ static void get_const_expr(Const *constval, deparse_context *context,
int showtype);
static void simple_quote_literal(StringInfo buf, const char *val);
static void get_sublink_expr(SubLink *sublink, deparse_context *context);
+static void get_subplan_reference(SubPlan *subplan, deparse_context *context);
static void get_from_clause(Query *query, const char *prefix,
deparse_context *context);
static void get_from_clause_item(Node *jtnode, Query *query,
@@ -4647,20 +4648,13 @@ get_rule_expr(Node *node, deparse_context *context,
break;
case T_SubPlan:
- {
- SubPlan *subplan = (SubPlan *) node;
-
- /*
- * We cannot see an already-planned subplan in rule deparsing,
- * only while EXPLAINing a query plan. We don't try to
- * reconstruct the original SQL, just reference the subplan
- * that appears elsewhere in EXPLAIN's result.
- */
- if (subplan->useHashTable)
- appendStringInfo(buf, "(hashed %s)", subplan->plan_name);
- else
- appendStringInfo(buf, "(%s)", subplan->plan_name);
- }
+ /*
+ * We cannot see an already-planned subplan in rule deparsing, only
+ * while EXPLAINing a query plan. We don't try to reconstruct the
+ * original SQL, just reference the subplan that appears elsewhere
+ * in EXPLAIN's result.
+ */
+ get_subplan_reference((SubPlan *) node, context);
break;
case T_AlternativeSubPlan:
@@ -4673,12 +4667,9 @@ get_rule_expr(Node *node, deparse_context *context,
foreach(lc, asplan->subplans)
{
SubPlan *splan = (SubPlan *) lfirst(lc);
-
Assert(IsA(splan, SubPlan));
- if (splan->useHashTable)
- appendStringInfo(buf, "hashed %s", splan->plan_name);
- else
- appendStringInfo(buf, "%s", splan->plan_name);
+ get_subplan_reference(splan, context);
+
if (lnext(lc))
appendStringInfo(buf, " or ");
}
@@ -5934,6 +5925,43 @@ get_sublink_expr(SubLink *sublink, deparse_context *context)
/* ----------
+ * get_subplan_reference - Parse back a subplan reference
+ *
+ * ----------
+ */
+static void
+get_subplan_reference(SubPlan *subplan, deparse_context *context)
+{
+ StringInfo buf = context->buf;
+
+ if (subplan->useHashTable)
+ appendStringInfo(buf, "hashed ");
+
+ appendStringInfo(buf, "%s", subplan->plan_name);
+
+ /* Add the subplan arguments */
+ if (list_length(subplan->args) > 0)
+ {
+ ListCell *l;
+ int i = 0;
+
+ foreach(l, subplan->args)
+ {
+ Node *n = lfirst(l);
+ appendStringInfo(buf, "%s$%d := ",
+ (i == 0) ? " (" : ", ",
+ i);
+
+ get_rule_expr(n, context, true);
+ i++;
+ }
+
+ appendStringInfoChar(buf, ')');
+ }
+}
+
+
+/* ----------
* get_from_clause - Parse back a FROM clause
*
* "prefix" is the keyword that denotes the start of the list of FROM