Skip to content

Commit bc891bf

Browse files
gregfeliceclaude
andcommitted
Fix parse-tree malformation in OPTIONAL MATCH WHERE re-attach (#2378)
transform_cypher_optional_match_clause was calling transform_cypher_expr with EXPR_KIND_JOIN_ON when re-attaching the detached WHERE as the LEFT JOIN's ON condition. All other WHERE transforms in cypher_clause.c use EXPR_KIND_WHERE, and there are three explicit p_expr_kind == EXPR_KIND_WHERE guards (cypher_clause.c:5415, 5679, 6597) that do load-bearing variable resolution for sub-pattern predicates -- walking up parent parsestates to rebind variables like `friend` inside EXISTS { (friend)-[...]->(...) }. Using EXPR_KIND_JOIN_ON bypassed those guards, so the sub-pattern fell through to the "create new variable" path and produced a structurally invalid parse tree. Under a release PG build the query happened to produce correct-looking output, but under --enable-cassert the downstream invariant checks aborted, crashing the backend and taking down the regression run (reported by @MuhammadTahaNaveed). Fix: use EXPR_KIND_WHERE, matching the pattern already established in transform_cypher_clause_with_where at line 2619. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2d75e22 commit bc891bf

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/backend/parser/cypher_clause.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@ static RangeTblEntry *transform_cypher_optional_match_clause(cypher_parsestate *
28722872
Node *where_qual;
28732873

28742874
where_qual = transform_cypher_expr(cpstate, saved_where,
2875-
EXPR_KIND_JOIN_ON);
2875+
EXPR_KIND_WHERE);
28762876
where_qual = coerce_to_boolean(pstate, where_qual, "WHERE");
28772877
j->quals = where_qual;
28782878
}

0 commit comments

Comments
 (0)