Skip to content

perf(cypher): share a filter state across an undirected step - #214

Merged
prrao87 merged 1 commit into
perf/named-path-csr-walkfrom
perf/share-undirected-filter-state
Nov 25, 2026
Merged

prrao87 merged 1 commit into
perf/named-path-csr-walkfrom
perf/share-undirected-filter-state

Conversation

@prrao87

@prrao87 prrao87 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Why

When a named path walks the CSR (#211), each step checks its relationship filter only on the edges it reaches. On a Lance table it switches to one read of the whole filter column once it has checked 1/256 of the edges. An undirected step is planned as two hops over the same table, the outgoing and the incoming CSR, and each hop kept its own filter state. So each half counted its checks separately and could read the whole column into its own mask, doing the same read twice.

Closes #210.

What changed

  • Hops of one step over the same relationship type now share one filter state. The two halves of an undirected step count their checks together, switch to the mask together, and read the column once.
  • Sharing is safe because both halves read the same table with the same compiled filter, and their row addresses index the same mask.
  • The internals page on PathMatchExec notes the shared state.

This PR is stacked on #211, whose branch it targets. It needs retargeting to main once #211 merges.

Validation

  • A debug build with a temporary counter in the mask read ran an undirected filtered *1..3 path on a 400k-edge Lance table. The filter column was read twice before this change and once after. The CSR walk and the edge inventory both returned the same 1,543 paths in each run.
  • cargo test -p lance-csr --lib: 490 passed.
  • Full Python suite: 1,805 passed, 2 skipped.
  • cargo clippy -D warnings, cargo fmt --check, the strict docs build and typos pass.
  • Benchmark suites were not run: the change only affects undirected filtered named paths on Lance, and removes a read rather than adding work.

🤖 Generated with Claude Code

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
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying lance-csr with  Cloudflare Pages  Cloudflare Pages

Latest commit: 646d9ab
Status: ✅  Deploy successful!
Preview URL: https://423766a2.lance-csr.pages.dev
Branch Preview URL: https://perf-share-undirected-filter.lance-csr.pages.dev

View logs

@prrao87
prrao87 marked this pull request as ready for review November 25, 2026 22:41
@prrao87
prrao87 merged commit 3923356 into perf/named-path-csr-walk Nov 25, 2026
10 checks passed
@prrao87
prrao87 deleted the perf/share-undirected-filter-state branch 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant