Repository navigation
perf(cypher): walk the csr for named trail paths - #211
Merged
Merged
Conversation
Named paths (`MATCH p = ...`) built an inventory of every edge of the relationship table before walking, so a selective path over a large table paid for the whole table. When the engine has a CSR for every type and direction a trail follows, the path now walks that CSR from its start node instead, as explicit hops do. Each step checks its relationship equalities only on the edges it reaches, using the same per-edge-then-mask rule as CsrExpandExec, and relationship records are built only for returned paths, once per distinct edge in a batch. The design follows Kùzu, which evaluates relationship predicates inside recursive joins over CSR adjacency lists. Shortest paths and types without a CSR keep the edge inventory. Closes #208
prrao87
marked this pull request as ready for review
November 25, 2026 17:55
The CSR walk named an edge by its row in the engine's edge store (the row address on Lance), while the edge inventory, which shortest paths still use, named it by its position in a scan. On a Lance table with several fragments or deleted rows, a trail and a shortest path in one query then disagreed: `relationships(p)[0] = relationships(q)[0]` was false for the same edge. For a relationship type the engine has a CSR for, the inventory now reads the rows the CSR stores, with their row identity, instead of scanning the table, so both routes name each edge the same way. Both routes build the identity through one helper, and the CSR route reads its rows from the same place.
Deploying lance-csr with
|
| Latest commit: |
3872f76
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://323f4bab.lance-csr.pages.dev |
| Branch Preview URL: | https://perf-named-path-csr-walk.lance-csr.pages.dev |
This was referenced Nov 25, 2026
Both halves of an undirected named-path step read the same relationship table with the same filter, but each kept its own EdgeFilterState, so on Lance each could read the whole filter column into its own mask. Hops of one step over the same type now share one state. Closes #210
A named path whose variable nothing references still built an Arrow path value per path, and on the CSR walk read every relationship record for it. The column-pruning optimizer rule now drops the path column from PathMatch when no expression uses it, and the CSR walk skips relationship records when no output needs them.
prrao87
added a commit
to MuddyBootsCode/lance-csr
that referenced
this pull request
Nov 26, 2026
Resolve conflicts with named-path CSR walks (hyperdimensionalcomputingai#211) and all()/none() pruning (hyperdimensionalcomputingai#215): - path_ops.rs: keep both the trail builders and main's csr_route. - logical_plan.rs: pass no relationship condition at the two shared-trail calls of plan_inventory_path, since only named paths have one. - operators.md: describe main's two PathMatch routes, then trails across segments of an unnamed path in their own subsection. - test_path_csr_walk.py: an unnamed multi-type segment now takes iterative CsrExpand. Rows still match the edge inventory, and on LDBC SF1 it runs in 0.5 ms instead of 2.8 ms (knows|studyAt*1..2) and 6 ms instead of 140 ms (knows|workAt*1..3).
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.
Why
A named path (
MATCH p = ...) built an inventory of every edge of every relationship table it followed before it started walking. After #205, a path filtered byall(r IN relationships(p) WHERE r.day = 5)dropped failing edges during the walk, but it still paid for the whole table first. On the repro in #208 (20K nodes, 3M edges) that took 2.6 s in a debug build, about 5x slower than the same query written as explicit hops, and the time grew with the table's size rather than with the number of paths found. Profiling showed the walk itself took under 1 ms; building the inventory took the rest.Closes #208. Closes #212.
Two follow-ups were reviewed and merged into this branch, so they land with it: #213 skips building path values the query never reads (#212), and #214 makes the two halves of an undirected step share one filter state (#210, already closed).
What changed
When the engine has a CSR for every relationship type and direction a named trail follows, the path now walks that CSR from its start node, as explicit hops do, instead of building the edge inventory.
{day: 5}maps, or theall()equalities from perf(cypher): prune named paths by all() equalities and accept bare booleans #205) are checked only on the edges reached. The rule matchesCsrExpandExec: fetch the filter columns of just those edges and, on a Lance table, switch to one read of the whole column once 1/256 of the table has been checked. In memory it never switches.collect()andUNWIND.relationships(p)[0] = relationships(q)[0]was false for the same edge whenpwalked the CSR andqwas a shortest path. An independent review found this; the second commit fixes it, and both routes now build the identity through one helper.PathMatchExec: p csr walk.count(*),RETURN b.id), the optimizer drops the path column and the node shows asPathMatchExec: endpoints, on either route. Any reference (p,length(p),nodes(p),relationships(p),WITH p AS q) keeps it. On the CSR walk, relationship records are then read only for a path value or a relationship variable on a fixed-length step (perf(cypher): skip path values the query never reads #213).use_csr=False), keep the edge inventory. Both routes still read the participating node tables in full.The design follows Kùzu, which evaluates relationship predicates inside its recursive joins over CSR adjacency lists, so the work follows the frontier rather than the size of the relationship table. The CSR guide and the operator internals now describe the walk and credit Kùzu, and the path-value notes no longer say path values always read whole relationship tables.
The Python and TypeScript APIs don't change.
Validation
Correctness:
cargo test --workspace,cargo clippy --workspace --all-targets -- -D warningsandcargo fmt --all --checkpass.python/:make test(1807 passed, 2 skipped) andmake lintpass.use_csr=TrueandFalseand require identical results, in memory and on multi-fragment Lance tables with deletions: both directions and undirected, several types, mixed labels with colliding keys, self-loops, parallel edges, inline andall()filters, and a filter on a property one type lacks. Another test makes a walk check edges one by one and then switch to the mask on a 30,000-edge Lance table. A Rust test checks that both filter modes keep the same rows.use_csron and off, and requires the relationships and paths to compare equal.(:Person {ID: 1131})-[:knows*1..3]->()(11 output batches) matchmainrow for row, apart from the query-local relationship ids, in both modes.zensical build --strict,check_snippets.pyandtypospass.Performance, release wheels built from
mainand this branch, with the CONTRIBUTING.md harness, runs alternated, on an idle Apple silicon laptop (load average 2.5 to 5.6).Query shapes the walk takes over (best of 5, ms; SF1 is the LDBC graph, "random" is 20K nodes with 3M
Rand 300KSedges):*1..3withall(r.day = 5), random{day: 5}*1..3, returningp, randomR|S*1..2withall(), random*1..2count, randomR|S*1..2, randomknows*1..2returningp(5,430 paths)knows*1..2thenhasInterestknows*1..3count (86K paths)These timings predate #213 and #214. The last row was the one shape that got slower:
count(*)built all 86K path values, and in lazy mode the walk read those relationships from Lance by row whilemainscans the 180K-edge table once. With #213 the path values are skipped, and the shape takes 27.3 ms in memory and 28.6 ms lazy (main: 68.2 and 71.3). A query that does read every path, such assum(length(p))over the same paths, still pays the by-row reads: 71.4 ms onmain, 88.3 ms lazy here. The undirected lazy row read the filter column twice; #214 removes the second read (confirmed with a read counter in a debug build), but the row was not re-timed.Both suites: no query changed plan (IC3's filter prints its two
ANDterms in a different order per process, onmaintoo), and every result matched its expected answer. Geometric means of branch/mainper-query ratios, two runs each:The identity fix changes how shortest-path inventories read relationship tables when a CSR exists. Rerun of the IC suite against
mainwith that commit (two runs each, load 4.6 to 6.0): geometric mean 1.004 in memory and 1.005 lazy, with IC13 and IC14, the shortest-path queries, within ±3%.An earlier version shared the mask-switch code between
CsrExpandExecand the walk. A control wheel showed that it slowed IC12 by 10%, IC5 by 7% and custom query 30 by 6%, with identical plans, soCsrExpandExeckeeps its inline code and a comment records why. The table above is for the final code. graph-benchmark (custom, non-LDBC, memory) was only measured on that earlier version: geometric mean 1.008, with no plan changes and no named paths in its queries.#213 measured both suites again with its own control wheel: every geometric mean against
mainwas between 0.996 and 1.005, and no suite query uses a named path. #214 was checked with tests only, without benchmarks, since it removes a read and adds no work.Not done: release timings for the walk on graphs much larger than 3M edges, and a release re-timing of the undirected lazy shape after #214.
🤖 Generated with Claude Code