Repository navigation
Allow a MATCH clause to follow OPTIONAL MATCH - #2626
Open
leo7martins wants to merge 1 commit into
Open
leo7martins wants to merge 1 commit into
leo7martins wants to merge 1 commit into
Conversation
A MATCH directly after OPTIONAL MATCH was rejected as a syntax error. openCypher chains those reading clauses in one scope. The following MATCH is already transformed as an inner join against the previous clause, which is the LATERAL LEFT JOIN of an OPTIONAL MATCH that has a predecessor. Null-extended rows stay unless that MATCH filters them, so the blanket rejection was not required. Fixes apache#2622
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2622.
A MATCH clause placed directly after OPTIONAL MATCH was rejected with
"MATCH cannot follow OPTIONAL MATCH". openCypher allows those reading
clauses in one scope. AGE already ran the sibling orders (MATCH after
MATCH, OPTIONAL MATCH after OPTIONAL MATCH, and OPTIONAL MATCH, WITH,
MATCH) and returned the right counts on empty and non-empty graphs.
The rejection was a syntax check in transform_cypher_match_pattern(),
added in #740 because the clause order was treated as invalid Cypher.
It is not required for a correct plan. The following MATCH is already
transformed as an inner join against the previous clause. When that
clause is an OPTIONAL MATCH with a predecessor, the previous result is
the LATERAL LEFT JOIN built for OPTIONAL MATCH. Null-extended rows from
that left join are kept unless the MATCH itself filters them. A search
of the git history and of public issue and mailing-list discussion did
not turn up a correctness requirement for the blanket error.
The check is removed. OPTIONAL MATCH followed by another OPTIONAL MATCH
still uses the left-join path.
Regression coverage is in regress/sql/cypher_match.sql (issue 2622):
empty graph and a 2-vertex, 1-edge graph, the reported clause orders,
a missed optional pattern joined with a later MATCH (with and without
WITH), and a property constraint on a variable bound by OPTIONAL MATCH.
Tested on PostgreSQL 18.7:
(exit 0)
(exit 0)
REGRESS=cypher_match
(1 of 1 passed)
(44 of 44 passed)
This was written with help from an AI coding assistant.