On 11/18/24 22:15, Tomas Vondra wrote:
> ...
>
> So I think the correct solution is to not pass any expressions with
> RestrictInfo to deparse_expression(). Either by stripping the nodes, or
> by not adding them at all.
> 
> The patch tries to do the stripping by maybe_extract_actual_clauses(),
> but that only looks at the top node, and that is not sufficient here.
> Maybe it would be possible to walk the whole tree, and remove all the
> RestrictInfos nodes - including intermediate ones, not just the top. But
> I'm not quite sure it wouldn't cause issues elsewhere (assuming it
> modifies the existing nodes). It still feels a bit like fixing a problem
> we shouldn't really have ...
> 

To make this idea a bit more concrete, here's a patch removing all
RestrictInfo nodes in show_stat_qual(). But still, it feels wrong.


regards

-- 
Tomas Vondra
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 40c8462d680..bf2faa6d9f2 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -2738,6 +2738,25 @@ deparse_stat_expression(Node *node,
 	return deparse_expression(node, context, false, false);
 }
 
+static Node *
+strip_restrict_info_nodes(Node *node, void *context)
+{
+	if (node == NULL)
+		return NULL;
+
+	switch (nodeTag(node))
+	{
+		case T_RestrictInfo:
+			return (Node *) ((RestrictInfo *) node)->clause;
+
+		default:
+			break;
+	}
+
+	return expression_tree_mutator(node, strip_restrict_info_nodes,
+								   (void *) context);
+}
+
 /*
  * Show a qualifier expression (which is a List with implicit AND semantics)
  */
@@ -2752,6 +2771,10 @@ show_stat_qual(List *qual, int is_or,
 	if (qual == NIL)
 		return NULL;
 
+	/* remove all RestrictInfo nodes, which are not expected by deparsing */
+	qual = (List *) expression_tree_mutator((Node *) qual,
+											strip_restrict_info_nodes, NULL);
+
 	/* Convert AND list to explicit AND */
 	switch (is_or)
 	{

Reply via email to