Skip to content

perf(cypher): prune named paths by any all() or none() condition - #215

Merged
prrao87 merged 1 commit into
mainfrom
perf/named-path-relationship-predicates
Nov 26, 2026
Merged

prrao87 merged 1 commit into
mainfrom
perf/named-path-relationship-predicates

Conversation

@prrao87

@prrao87 prrao87 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Why

#205 let WHERE all(r IN relationships(p) WHERE ...) on a named variable-length path drop a failing relationship during the walk, but only for equalities on r. Any other condition on a single relationship was checked once each path was complete, so its cost followed the unfiltered fan-out, as in #179:

MATCH p = (c:Computer {host_id: 17693})-[:AUTH*1..3]->(d:Computer)
WHERE all(r IN relationships(p) WHERE r.day >= 5 AND r.day <= 7)
RETURN count(*)

This change prunes the walk for any per-relationship condition in all() and none().

What changed

  • The planner turns the all(r IN relationships(p) WHERE x) and none(r IN relationships(p) WHERE x) conjuncts of the WHERE into one condition every relationship must meet, with r.key read as the column key and none read as NOT x. Comparisons, <>, IN, OR, IS NULL, bare booleans and parameters all qualify. This replaces the equality-only lowering from perf(cypher): prune named paths by all() equalities and accept bare booleans #205.
  • A predicate qualifies only when it reads r's properties, parameters and literals. Predicates that refer to other variables, to r itself or to a nested comprehension's element stay out, as do any, single, an all() under OR or NOT, and shortest paths. The WHERE still runs in every case, so pruning only saves work.
  • The path operator ANDs the condition into each step's per-edge check on both routes: the CSR walk (through EdgeFilterState, as before) and the edge inventory. A property a relationship table lacks reads as null. On the CSR walk, a condition that reads no column of a table is evaluated once for all of that table's edges.
  • Only the condition's parameters are exposed to DataFusion as logical expressions, so cached plans still bind them per execution (fix(cypher): bind cached path filters per execution #197). Exposing the whole condition would fail type coercion, since the relationship columns are not in the node's inputs.
  • EXPLAIN output is unchanged. The Cypher, CSR and internals docs describe the wider set of conditions.

Validation

  • cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace pass.
  • make test (1833 passed, 2 skipped) and make lint pass in python/.
  • zensical build --strict and typos@1.52.0 pass.
  • New tests cover which predicates are lowered, results for each predicate kind on both routes, CSR walk vs. edge inventory agreement with a property one table lacks, and each condition against the same all()/none() under OR (which is not pruned), binding a parameter twice to reuse the cached plan.

Benchmark suites

Release wheels from main (bbec0b7) and this branch (245fc16), run with the CONTRIBUTING.md harness: both modes, main and branch alternated twice each. Every query's result check passed on both wheels. The custom graph-benchmark suite (100K persons, 2.4M FOLLOWS edges) runs in memory mode only. Apple M5, 24 GiB, macOS 26.6.2, load average 2.7 to 5.0. Suite commits: graph-benchmark-ldbc 1998520, graph-benchmark-ldbc-complex 220e956, graph-benchmark 66a2f51.

suite mode geomean branch/main main run 2 / run 1
graph-benchmark-ldbc memory 1.0064 1.0444
graph-benchmark-ldbc lazy 1.0004 0.9990
graph-benchmark-ldbc-complex memory 0.9997 1.0146
graph-benchmark-ldbc-complex lazy 0.9981 1.0065
graph-benchmark memory 1.0038 1.0048

No suite query uses all() or none() over a named path, and no physical plan changed. The captured EXPLAIN text differs only for IC14, whose graph plan now prints relationship_condition: None, and for IC3, whose map entries print in a different order between runs. Every per-query change is within the 15 to 20% run-to-run noise that CONTRIBUTING.md describes. The largest moves are IC12 lazy (0.88) and IC2 lazy (1.05).

Every query (mean ms, average of 2 runs per wheel)

graph-benchmark-ldbc / memory

query main branch branch/main main run gap plan
query1 0.63 0.63 1.006 +4.5% same
query2 0.55 0.55 1.010 +7.4% same
query3 0.66 0.67 1.006 +4.2% same
query4 0.52 0.52 1.007 +6.8% same
query5 0.80 0.81 1.008 +2.6% same
query6 0.44 0.44 1.001 +6.3% same
query7 1.05 1.06 1.005 +5.3% same
query8 0.64 0.65 1.008 +2.6% same
query9 0.83 0.84 1.019 +4.3% same
query10 0.73 0.74 1.016 +4.4% same
query11 1.52 1.54 1.017 +5.1% same
query12 0.76 0.76 1.004 +6.2% same
query13 0.80 0.81 1.016 +5.4% same
query14 0.54 0.54 1.009 +4.7% same
query15 0.57 0.57 1.010 +5.2% same
query16 0.68 0.68 1.007 +5.6% same
query17 0.90 0.92 1.012 +4.3% same
query18 0.70 0.71 1.008 +5.8% same
query19 0.94 0.95 1.011 +3.2% same
query20 2.05 2.05 1.001 +2.5% same
query21 0.78 0.79 1.007 +3.4% same
query22 0.73 0.72 0.990 +5.0% same
query23 0.75 0.75 0.999 +5.4% same
query24 0.71 0.70 0.997 +5.5% same
query25 0.81 0.81 1.002 +3.6% same
query26 0.75 0.76 1.008 +3.6% same
query27 0.87 0.87 1.003 +2.1% same
query28 1.40 1.40 0.997 +4.6% same
query29 0.70 0.71 1.008 +4.1% same
query30 19.14 19.11 0.998 -0.1% same

geomean branch/main 1.0064; main run 2/run 1 1.0444; plans changed: none

graph-benchmark-ldbc / lazy

query main branch branch/main main run gap plan
query1 1.13 1.14 1.004 -0.0% same
query2 1.39 1.40 1.008 +0.3% same
query3 0.80 0.81 1.006 +0.0% same
query4 0.79 0.80 1.007 +0.4% same
query5 2.14 2.18 1.015 +1.2% same
query6 0.74 0.74 0.994 +0.7% same
query7 1.10 1.10 1.004 +0.2% same
query8 1.72 1.73 1.007 -1.7% same
query9 1.34 1.33 0.997 +0.5% same
query10 0.94 0.94 1.002 +0.4% same
query11 1.96 1.96 1.003 +0.1% same
query12 6.47 6.61 1.022 -3.4% same
query13 1.06 1.06 0.996 -0.4% same
query14 0.69 0.70 1.002 -0.7% same
query15 0.76 0.77 1.005 -0.7% same
query16 1.10 1.10 0.995 -0.5% same
query17 1.40 1.39 0.990 +0.0% same
query18 1.14 1.14 0.997 -0.5% same
query19 1.35 1.36 1.006 -0.3% same
query20 16.50 16.66 1.010 +0.5% same
query21 0.83 0.83 0.991 -0.6% same
query22 0.94 0.94 0.997 +0.2% same
query23 1.24 1.23 0.993 +0.2% same
query24 1.07 1.06 0.998 +0.1% same
query25 1.20 1.19 0.996 +0.2% same
query26 1.07 1.07 0.995 -0.1% same
query27 1.30 1.30 0.995 -0.2% same
query28 2.02 2.01 0.996 +0.3% same
query29 1.03 1.02 0.991 +0.4% same
query30 19.71 19.59 0.994 +0.5% same

geomean branch/main 1.0004; main run 2/run 1 0.9990; plans changed: none

graph-benchmark-ldbc-complex / memory

query main branch branch/main main run gap plan
query1 23.26 23.13 0.994 +0.5% same
query2 2.46 2.42 0.986 -0.5% same
query3 25.21 25.65 1.018 -0.1% changed
query4 5.73 5.73 1.001 +0.2% same
query5 72.68 73.21 1.007 +2.4% same
query6 21.00 20.82 0.992 +1.9% same
query7 9.64 9.69 1.006 -0.3% same
query8 2.28 2.28 1.000 -0.6% same
query9 36.42 36.11 0.991 +0.4% same
query10 20.14 20.02 0.994 -0.3% same
query11 2.99 2.97 0.995 +0.0% same
query12 16.94 17.32 1.022 +16.9% same
query13 1.11 1.11 0.999 +0.1% same
query14 244.42 242.11 0.991 +1.1% changed

geomean branch/main 0.9997; main run 2/run 1 1.0146; plans changed: ['test_benchmark_query14', 'test_benchmark_query3']

graph-benchmark-ldbc-complex / lazy

query main branch branch/main main run gap plan
query1 32.92 34.05 1.034 +0.8% same
query2 24.39 25.61 1.050 +3.7% same
query3 162.87 162.95 1.001 +0.4% same
query4 12.69 12.77 1.006 +0.4% same
query5 94.64 93.50 0.988 -1.3% same
query6 22.03 21.90 0.994 +1.5% same
query7 13.26 13.48 1.017 +0.3% same
query8 3.27 3.30 1.009 +1.4% same
query9 221.72 222.58 1.004 -0.1% same
query10 28.50 28.55 1.002 -0.1% same
query11 5.37 5.37 0.999 +0.6% same
query12 21.10 18.63 0.883 +0.0% same
query13 1.40 1.41 1.005 +0.5% same
query14 252.37 250.17 0.991 +1.2% changed

geomean branch/main 0.9981; main run 2/run 1 1.0065; plans changed: ['test_benchmark_query14']

graph-benchmark / memory

query main branch branch/main main run gap plan
query1 7.37 7.43 1.008 -1.0% same
query2 12.14 12.18 1.004 +2.2% same
query3 2.67 2.67 1.000 +0.8% same
query4 1.58 1.58 0.995 -1.5% same
query5 1.60 1.60 1.001 +1.6% same
query6 1.84 1.85 1.009 +0.8% same
query7 3.61 3.66 1.015 +1.2% same
query8 13.04 13.08 1.003 -1.7% same
query9 12.32 12.31 0.999 +2.0% same

geomean branch/main 1.0038; main run 2/run 1 1.0048; plans changed: none

Rerouted shapes

The suites don't exercise this route, so the shapes it changes were timed directly on SF1 (knows from person 1131, creationDate against a datetime parameter) and on a random graph (20K nodes, 600K R edges with day in 0..57, 60K S edges with no day), on both the CSR walk and the edge inventory. Times are the best of 3 runs, minimum over 2 alternated passes per wheel, in ms. Queries were capped at 10 s. Both wheels returned the same result for every shape that finished.

shape memory main memory branch ratio lazy main lazy branch ratio
sf1 *1..2 all() range 5.4 2.2 0.42 7.3 7.0 0.97
sf1 *1..2 none() range 5.3 2.2 0.42 7.4 6.9 0.93
sf1 *1..2 all() range path values 5.6 2.3 0.41 7.4 6.9 0.93
sf1 *1..2 all() under OR (not pruned) 5.2 5.3 1.02 7.2 7.3 1.02
sf1 *1..2 unfiltered count 2.7 2.7 0.99 3.6 3.5 0.99
rand all() equality (#205) [csr] 1.1 1.1 1.00 1.7 1.7 1.04
rand all() equality param [csr] 1.1 1.1 1.02 1.7 1.6 0.97
rand inline {day: 5} path values [csr] 0.9 1.0 1.04 1.4 1.4 1.00
rand all() range [csr] 15.0 1.2 0.08 23.7 3.7 0.16
rand all() IN [csr] 15.1 1.2 0.08 24.0 3.2 0.13
rand all() OR [csr] 15.0 1.2 0.08 23.7 2.3 0.10
rand none() range [csr] 15.2 1.2 0.08 23.7 4.0 0.17
rand all() range undirected [csr] 117.6 1.3 0.01 173.2 14.4 0.08
rand R|S *1..2 S lacks day [csr] 1.7 1.3 0.74 2.9 5.2 1.78
rand 2 starts all() range [csr] > 10 s 83.1 < 0.01 > 10 s 83.7 < 0.01
rand *1..2 unfiltered count [csr] 1.4 1.3 0.92 1.6 1.4 0.86
rand all() equality (#205) [inventory] 30.1 30.9 1.03 32.2 32.4 1.01
rand all() equality param [inventory] 30.0 30.5 1.02 31.6 31.5 0.99
rand inline {day: 5} path values [inventory] 29.7 30.0 1.01 31.2 31.4 1.01
rand all() range [inventory] 47.4 30.6 0.65 48.5 32.1 0.66
rand all() IN [inventory] 47.3 31.8 0.67 47.9 33.2 0.69
rand all() OR [inventory] 47.4 30.7 0.65 48.9 32.1 0.66
rand none() range [inventory] 47.5 30.7 0.65 48.7 32.0 0.66
rand all() range undirected [inventory] 150.1 31.1 0.21 151.9 32.2 0.21
rand R|S *1..2 S lacks day [inventory] 36.0 34.7 0.97 38.1 35.5 0.93
rand 2 starts all() range [inventory] > 10 s 91.2 < 0.01 > 10 s 91.0 < 0.01
rand *1..2 unfiltered count [inventory] 31.1 31.2 1.00 32.1 32.2 1.00

Closes #207

🤖 Generated with Claude Code

`WHERE all(r IN relationships(p) WHERE ...)` dropped a failing edge
during the walk only for equalities on `r`; ranges, IN lists, OR and
none() were checked once each path was complete, so their cost followed
the unfiltered fan-out.

The planner now turns the all() and none() conjuncts over a named
path's relationships into one condition on the relationship columns,
when it reads only r's properties, parameters and literals. PathMatch
ANDs it into each step's per-edge check on both the CSR walk and the
edge inventory. Only the condition's parameters are logical
expressions of the node, so cached plans bind them per execution
without DataFusion typing columns the inputs lack. A property a table
lacks reads as null, and a condition that reads no column of a table is
evaluated once for all its edges. The WHERE still runs, and shortest
paths are left alone.

Closes #207
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Deploying lance-csr with  Cloudflare Pages  Cloudflare Pages

Latest commit: 245fc16
Status: ✅  Deploy successful!
Preview URL: https://b0cc9cef.lance-csr.pages.dev
Branch Preview URL: https://perf-named-path-relationship.lance-csr.pages.dev

View logs

@prrao87
prrao87 marked this pull request as ready for review November 26, 2026 00:04
@prrao87
prrao87 merged commit 8b0bf0d into main Nov 26, 2026
10 checks passed
@prrao87
prrao87 deleted the perf/named-path-relationship-predicates branch November 26, 2026 01:57
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).
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.

Prune named paths by any per-relationship condition in all() and none()

1 participant