Copilot commented on code in PR #2460:
URL: https://github.com/apache/age/pull/2460#discussion_r3520823282
##########
src/backend/parser/cypher_clause.c:
##########
@@ -973,6 +992,17 @@ transform_cypher_union_tree(cypher_parsestate *cpstate,
cypher_clause *clause,
}
}
+ /*
+ * Returnless UNION branches use a parser-injected RETURN * only as a
+ * syntactic carrier. The branch output is unobservable, so expose one
+ * stable column to PostgreSQL's set-op planner instead of leaking the
+ * branch's current variable list into set-op metadata.
+ */
+ if (returnless_union)
+ {
+ project_returnless_union_leaf(returnQuery);
+ }
Review Comment:
`returnless_union` is set by the grammar for any subquery without an
explicit `RETURN` (see `subquery_stmt_no_return`), not just `EXISTS { ... }`.
Replacing each UNION leaf’s targetlist with a single constant column changes
the *semantic* row identity for `UNION` (distinct): all rows in a branch become
identical, so `UNION` will collapse them down to at most 1 row per branch. This
is fine for `EXISTS` (only non-emptiness matters), but it will change results
for `COUNT { ... }` subqueries (which count the UNION’s output rows) when the
user writes a returnless UNION inside `COUNT { ... }`. Consider gating this
projection to `EXISTS` subqueries only (e.g., plumb the `cypher_sub_query.kind`
into UNION transformation), or otherwise preserve per-row distinctness for
COUNT contexts.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]