Repository navigation
feat(cypher): expose labels and type for fixed-length relationships - #235
MuddyBootsCode wants to merge 3 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: 162e9d480d
ℹ️ 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".
| expression: super::super::expression::bind_value(&p.expression, &schema, types), | ||
| alias: p.alias.clone(), |
There was a problem hiding this comment.
Preserve unaliased relationship functions in aggregate output
For a flat typed match such as MATCH (a:Person)-[r:KNOWS]->(b:Person) RETURN type(r), count(*) AS n, this binding replaces type(r) with @type__r while leaving its alias unset. The final aggregate projection then derives the output name from that bound expression, so drop_relationship_types removes the explicitly requested type result and returns only n. Preserve the original expression's display name before binding; unaliased labels(r) also needs its original name retained rather than becoming expr.
Useful? React with 👍 / 👎.
Summary
Closes #217. For a fixed-length relationship,
labels(r)returns a one-item list containing its configured type, andtype(r)returns that same name as a string. A single query can now return the holder, interest type and fraction for every matching edge, even when a holder has two different interests in the same tract.Problem and why it matters
On the original baseline,
type(i)raised an unimplemented-function error, andlabels(i)rejected a relationship. The workaround repeated the query once per configured type withUNION ALL. A type-list pattern also lost the name of the table that supplied each row. The endpoints alone cannot distinguish two relationships connecting the same pair of nodes.Change
Both functions read the same configured label. Relationship records already carry it in their Arrow identity. For flat typed expansions, the planner carries it through the union only when the query requests it. The type follows a
WITHrename, and both functions return null for an unmatchedOPTIONAL MATCH. The integration with #230 keeps a property-filtered optional hop eligible for a single outer CSR expansion, including when the projection returns the type.Validation
Local checks ran on the published head
162e9d4.Rust formatting, Clippy with warnings denied, Ruff, Python formatting and Pyright passed. All nine upstream CI checks passed on this head. GitHub checks
The issue fixture returns both the 2% overriding royalty and 50% mineral interest for holder 1, and the full working interest for holder 2. Regression coverage includes single-type, type-list and untyped patterns, CSR on and off, Arrow and Lance, properties named
typeorlabel, user aliases, filters, ordering, and optional null rows. The integration test also checks matching and rejected predicates inside the optional clause.Benchmarks
Compared release wheels from main
7d92e10and this branch at162e9d4. The two SF1 runners and the large shape suite ran twice per wheel in each storage mode on the same Apple M5 Max, 128 GiB, macOS 27.0.1, Rust 1.96.0. The runners loaded the verified native library from each wheel. The large graph used seed 0, 200,000 accounts and 2,338,886 T edges. All 352 SF1 answer checks and 400 shape cases passed, including required operators.Percentages are geometric means of per-query latency ratios. Positive is slower. The last column measures variation between two runs of the same main build.
The slower query and its rerun
In the original comparison (
1d01a8d→6afaaf1), the in-memorycross_filter_idsshape was the only case more than 20% slower. We reran it in four fresh processes with the same data and runner settings.The repeat was still 9.6% slower on average. Its second branch measurement was slightly faster than both main measurements. The full execution plans matched, and the original 29.7% gap did not repeat.
After integrating the upstream planner changes, we ran the same query against main
7d92e10and the published head162e9d4. The four fresh-process measurements are in milliseconds.No SF1 query exceeded the 20% slowdown threshold in the updated comparison.
On the published head,
cross_filter_idswas 5.3% faster in the full suite and 10.7% faster in the fresh-process rerun. The original slowdown did not reproduce. These measurements fall inside the project's stated run-to-run variation. No query in any of the three updated suites crossed the 20% slowdown threshold.We also compared the full EXPLAIN output for all 188 query/mode combinations. The first captures matched byte for byte for 187. The exception was complex SF1 query 3 in lazy mode, where two country filters printed in a different order. Each build reproduced the other build's exact plan in a fresh process. All 16 control query/mode combinations on the fixed-length fixture had identical plans across four captures.
Cost of asking for relationship types
On 30,000 relationships with in-memory CSR, the three-way manual
UNION ALLtook 1.18 ms, a single type-list query returning bothtype(r)andlabels(r)took 1.52 ms, and the untyped form took 10.50 ms. All produced the same rows. The untyped plan already usedPathMatchExecand took 9.63 ms to read just the share on the branch. These are warmed measurements.graph-benchmark-ldbc · all queries in both modes
memory
Geometric mean of per-query branch/main ratios: 0.9823.
lazy
Geometric mean of per-query branch/main ratios: 0.9986.
graph-benchmark-ldbc-complex · all queries in both modes
memory
Geometric mean of per-query branch/main ratios: 1.0113.
lazy
Geometric mean of per-query branch/main ratios: 0.9991.
Large shape suite · headlines, all 50 cases in both modes, peak memory and indexes
memory: large graph (200,000 accounts, 2,338,886 T edges, hub degrees [10, 1000, 10000, 100000])
Runs: main x2, branch x2.
main run-to-run geomean: 1.002; largest single-query gap 24%.
lazy: large graph (200,000 accounts, 2,338,886 T edges, hub degrees [10, 1000, 10000, 100000])
Runs: main x2, branch x2.
main run-to-run geomean: 1.002; largest single-query gap 21%.
Fixed-length interest queries · execution and planning times with CSR on and off
The graph has 10,000 nodes and 30,000 relationships. Three types connect each pair of adjacent nodes. Each sample follows a warmup. Each cell is the mean of two runs' nine-sample medians, in milliseconds.
The SF1 runners used standard cbd6d62 and complex dfec30d.
User impact
Queries can read a fixed-length relationship’s configured type directly in Cypher. The Cypher guide includes an executable example, and the optimizer guide describes when the planner carries the type. The existing node
labels()behavior and 64-combination limit are preserved. Variable-length relationship lists are outside this feature’s scope.