Repository navigation
feat(cypher): support bounded undirected relationship alternatives - #194
MuddyBootsCode wants to merge 2 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c3e3a294d7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if match_clause.is_bounded_undirected_alternation() { | ||
| if let [GraphPattern::Path(path)] = inferred.patterns.as_slice() { | ||
| return self.plan_inventory_path(base, path); |
There was a problem hiding this comment.
Validate the label of an already-bound start node
When two labels share an ID, MATCH (s:X {id: 1}) MATCH (s:Y)-[:A|B*1..2]-(q:Y) RETURN q.id (with A and B configured between Y nodes) follows paths from Y(1), although s was bound to X(1). This new shortcut calls plan_inventory_path, which skips validate_variable_label for an already-bound start. analyze_operator then overwrites the starting variable's label with Y, and Pending::bound looks up its existing numeric ID under that label, silently matching a different node. Validate the starting label before taking this route, as plan_path does, so conflicting bindings are rejected rather than producing unrelated endpoints.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ca7214e. I reproduced the overlapping-ID example on the original PR: it returned IDs 2 and 3 by following Y’s edges from a variable bound to X. The planner now reports Variable 's' already has label 'X', cannot redefine as 'Y' before traversal. The matching-label control still returns 2 and 3.
The regression covers both named and unnamed paths. Their valid physical plans matched before and after with CSR on and off. All nine CI checks passed, and I added the refreshed SF1 results to the PR description. Tests, plans and benchmark evidence
Summary
Fixes #186. A standalone bounded undirected match can follow multiple relationship types and return endpoints without naming the path. Each hop chooses its own direction. On the issue fixture, the unnamed query now returns IDs 2, 3, 4 and 5 with CSR enabled or disabled.
Bound start label review follow-up
Commit ca7214e fixes the overlapping-ID case raised in review. On the original PR, binding
stoX(1)and then writing(s:Y)returned IDs 2 and 3 from Y’s edges. The planner now rejects that label change for both named and unnamed paths. BindingstoY(1)still returns 2 and 3.The revised commit passed 738 Rust tests (11 ignored), 1,765 Python tests (one skipped), and all nine upstream CI checks. The physical EXPLAIN for the valid review example matched the original PR with CSR enabled and disabled, for both path forms. The targeted timing difference varied between repeats. Regression logs, execution plans and timing samples
We reran both official SF1 suites on release wheels against the PR base, twice per build in each storage mode. The 30-query suite’s geometric mean latency was 1.8% higher in memory and 1.2% higher on lazy Lance. The 14-query complex suite measured 5.2% lower and 4.3% lower, respectively. Eight cases initially measured more than 20% slower. On two additional alternating runs per build, their differences ranged from 5.2% faster to 6.6% slower. The only standard-plan difference from the original PR was the order of two ANDed predicates in IC3. Full comparison, raw runs and outlier repeats
We also rotated the base, original PR, and revised wheels through three run orders for five queries. The initial IC13 slowdown reversed: the revised wheel averaged 2.9% faster than base and 1.1% slower than the original PR. Q22 was 10.9% slower than the original PR and 2.3% slower than base. Its fixed-hop CSR plan matched across revisions. The cause of that timing difference remains open. Counterbalanced runs and raw timings
The original submission’s measurements below were taken at
c3e3a29.Problem and why it matters
A chain-of-title lookup needs to walk both ways through succession, estate and distribution records. Adding an unused
p =previously made an otherwise unsupported query work. On high-fan-out SF1 data, the working named workaround also builds a full Arrow path for each trail even when only endpoint IDs are returned.Change
Reuse the existing edge inventory and trail walker. The unnamed form emits boundary columns and skips constructing the Arrow path value. It still reads the participating node and relationship tables and tracks visited edge occurrences, so repeated or parallel edges retain their Cypher semantics. A query with many eligible trails can still do substantial work before DISTINCT. Enumerating every possible combination of direction and type would grow the plan with the hop bound.
The new case requires one anonymous, explicitly bounded undirected segment with multiple listed types and resolved boundary labels. It inherits the inventory’s signed integer or uint8/16/32 key support and 20-hop maximum. Named paths still emit their path value. Queries using the new endpoint-only inventory bypass the plan-template cache and are planned with the supplied parameter values on each execution.
Execution plan and performance
For the eight-way chain-of-title tree query using the pattern from #186, the baseline unnamed form raises
NotImplementedError. The working baseline and the new form each use one traversal with the same inputs. Excerpts from the release builds:On an eight-way, four-level tree with 4,681 nodes, all 584 expected endpoints were returned through depth three. With CSR enabled, the upstream named and branch unnamed forms both took about 2.1 ms in memory. On SF1, starting at Tagclass 182 and following hasType or isSubclassOf up to three hops returned the same 9,901 distinct tags. In memory the upstream named medians were 8.06 and 8.11 ms versus 6.79 and 6.84 ms on branch unnamed. On disk the corresponding medians were 9.30 and 9.12 ms versus 7.95 and 7.74 ms. The timings are specific to these workloads.
On the same branch wheel, omitting the path name reduced median latency on the high-degree, three-hop SF1 query by about 16% in memory and 14% on disk. Both runs showed the difference. The low-degree and eight-way tree samples did not show a consistent gain beyond timing variation. The high-degree traversal produced 9,901 trails and 9,901 distinct endpoints. These timings use a bound starting node. Queries with only the far endpoint filtered may enumerate trails from many more starting nodes.
The unnamed multi-type form uses the named form’s trail semantics. It can return to a node via a different parallel relationship, and it cannot reuse the same stored relationship later in the trail. The existing anonymous single-type traversal skips immediate backtracking.
A separate case discovered in review reproduces on both upstream main and the branch. A named path inside an EXISTS predicate with a parameter in its endpoint property map can fail with an unbound placeholder. The new unnamed case is planned for each execution with the supplied parameter values. This patch leaves the existing named case for separate consideration.
main, named, physical EXPLAIN
branch, unnamed, physical EXPLAIN
A reproducible SF1 query using the complex runner’s graph:
For the main baseline, add
p =immediately afterOPTIONAL MATCH. Both builds were also checked with the named spelling. An independent trail enumeration checked the endpoint IDs on SF1.Validation
The original submission commit has the same binary diff as the tested and benchmarked working tree (SHA-256
b521f96a426de834af817367672c36047d36735f00905e9db39ad89bcc031601). The verification archive includes the test and reproduction logs, all 16 benchmark runs with per-round timings, physical plans for both builds, and focused measurements and reproduction instructions.Positive values mean higher latency. These are geometric means of per-query branch/main ratios. Physical EXPLAIN output matched in 86 of 88 comparisons after display padding was removed. In the other two, IC3 printed its two equivalent country filters in a different order. Both orders appeared in repeated EXPLAINs on unchanged main, with no change in traversal or operator structure. Given those plans and the variation between baseline repeats, the suite-level timing deltas do not establish a speedup or a regression.
Main was
c9cd09659e7deb2516b88d8c6f65ead5f2b3a9b6. Both builds used Rust 1.96.0 and the macOS 26.2 Command Line Tools SDK on an Apple M5 Max with 128 GiB, macOS 27.0.1, on AC power. Both suites used the repository runner settings. The tables give means in milliseconds, branch/main changes and the repeat spread on main.30-query SF1 suite
Runner commit
199852076ba8dceb345e18eeb2f8ac04c73f3ea1.memory
Geometric mean of per-query branch/main ratios: 1.0043.
lazy
Geometric mean of per-query branch/main ratios: 0.9803.
14-query complex SF1 suite
Runner commit
a332324f2d4660b03d1d429d8ef99767af3981e5.memory
Geometric mean of per-query branch/main ratios: 1.0021.
lazy
Geometric mean of per-query branch/main ratios: 0.9876.
User impact
Endpoint queries can use ordinary MATCH or OPTIONAL MATCH without declaring an unused path. The Cypher guide documents the supported shape, and the operator guide explains its inventory and output cost.