Repository navigation
perf(cypher): skip path values the query never reads - #213
Merged
Merged
Conversation
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.
Deploying lance-csr with
|
| Latest commit: |
5a45a30
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://31df58a0.lance-csr.pages.dev |
| Branch Preview URL: | https://perf-skip-unused-path-values.lance-csr.pages.dev |
prrao87
marked this pull request as ready for review
November 25, 2026 22:42
prrao87
added a commit
that referenced
this pull request
Nov 25, 2026
* perf(cypher): walk the CSR for named trail paths 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 * fix(cypher): give a relationship one identity on every path route 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. * perf(cypher): share a filter state across an undirected step (#214) 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 * perf(cypher): skip path values the query never reads (#213) 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.
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 built its Arrow path value for every path it found, even when the query never read the path variable. On the LDBC SF1 graph,
MATCH p = (a:Person {ID: 1131})-[:knows*1..3]->(b:Person) RETURN count(*)finds 86,096 paths, andPathMatchExecemitted about 100 MB of node and relationship records only forcount(*)to discard them. Both routes did this work. On the CSR walk from #211 it was the one shape left slower thanmainin lazy mode, because the walk read each returned relationship's columns from Lance by row.Closes #212. Stacked on #211 (base
perf/named-path-csr-walk); retarget tomainonce that merges.What changed
CsrExpandandNodeLookupcolumns now also drops the path column fromPathMatchwhen no expression in the plan references it. The node then shows asPathMatchExec: endpointsand emits only boundary columns, on either route.p,length(p),nodes(p),relationships(p),WITH p AS q. The check is by column name across the whole plan, so it errs toward keeping the value.PathMatchinternals page describe when the value is skipped.Validation
cargo test --workspace,cargo clippy --workspace --all-targets -- -D warnings(and the Node crate by manifest),make test(1807 passed),make lint,zensical build --strictandtypospass locally, after rebasing onto perf(cypher): walk the csr for named trail paths #211's de2a035.pplanPathMatchExec: endpointsand return the same counts ascount(p); queries that readpor its functions keepPathMatchExec: p.PathMatchExecoutput 100.9 MB → 12.2 MB, compute 69 ms → 15 ms, same 86,096 rows.Release wheels per CONTRIBUTING.md:
main(e3278fd), #211 (de2a035), this branch, and a control (this branch with the pruning hook disabled, to separate build layout from the change). Each wheel ran twice per mode in alternating order, with load under 6.SF1 named-path shapes from person 1131, best of 7, ms:
*1..3count(*)*1..3count(*)*1..3RETURN b.ID*1..2thenhasInterestcount(*)*1..3count(*)*1..3count(*)*1..3sum(length(p))(readsp)*1..2RETURN p(readsp)Queries that read
pare unchanged from #211 (within 3%). The lazysum(length(p))shape stays slower thanmainbecause it still needs every relationship record; that is #211's trade-off, not this change.Both suites, geomean of mean times, branch relative to each wheel:
No suite query uses a named path, and their plans match #211's (IC3 differs only in map print order). Every query is within run-to-run noise; the largest single move is IC12 lazy, whose two
mainruns themselves differ by 8%.🤖 Generated with Claude Code