Repository navigation
perf(planner): start named and variable-length paths at their anchor - #225
Merged
Merged
Conversation
The same anchored path ran 33x to 480x slower depending on phrasing: whether the anchor was written inline or in WHERE, at the start or the end, and whether the path was named. - A single named or variable-length path is walked from its written end when that end is bound or its conditions score higher. PathMatch carries a `reversed` flag and reverses each path's nodes and relationships before building `p`, so path values keep written order. - PathMatch blocks DataFusion's pushdown of start-node columns, so the planner filters the start scan with the WHERE conjuncts that read only the start node. Variables that label branches give different labels are skipped, since a property may be missing from some of them. - MATCH clauses after WITH get their stage's WHERE for these choices, as the first stage does.
5 of 16 tasks
Deploying lance-csr with
|
| Latest commit: |
8345967
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://027a0f43.lance-csr.pages.dev |
| Branch Preview URL: | https://perf-path-phrasing-equivalen.lance-csr.pages.dev |
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.
Part of #223.
Why
The same anchored path query ran 20 to over 400 times slower than its fastest phrasing, depending on how it was written (release build, table below). The planner only chose a start for fixed-length, unnamed patterns, so:
p = ...) with its anchor inWHEREkept the filter abovePathMatch, because DataFusion cannot push start-node columns through that node, so the walk started from every node;MATCHafterWITHwas planned without its stage'sWHERE, so it could not use the anchor at all.The goal is that equivalent phrasings get the same plan, starting at the anchor.
What changed
WHERE) score higher than the start's. This reuses the existing scoring and the end check already used for trails across segments.reversedonPathMatch, which reverses each path's nodes and relationships before buildingp.nodes(p)andrelationships(p)are unchanged.WHEREfilters the start scan. The planner filters a path's start scan with theWHEREconjuncts that read only the start node; the fullWHEREstill runs above. Conjuncts with pattern predicates or comprehensions are left out, and so are variables that label inference plans with different labels per branch, because a property can be missing from some of those labels.MATCHafterWITHuses its stage'sWHEREfor these choices, as the first stage does. AWHEREafterOPTIONAL MATCHstill belongs to that clause.A variable-length segment with a relationship variable (
[r:T*1..3]) is still walked as written, becauseris a list in that order. Choosing the start from table statistics, rather than the kind of condition, is a later item on #223.Validation
cargo test --workspace,cargo clippy --workspace --all-targets -- -D warnings,make test(1,883 passed), ruff, the strict docs build andtyposall pass locally. CI has not run yet.MATCHafterWITHpicks its start from the stage'sWHERE. A new Python test checks that a named path walked from its end returns the same rows, nodes and relationships, in written order, as the unanchored query filtered afterwards, for both the CSR walk and the edge inventory.The rerouted shapes. 2,000 nodes and 40,000 edges,
MATCH ... (c)-[:AUTH*1..2]->(d) ... RETURN count(*), release wheels, in memory, best of five. Answers match on both wheels.mainWHEREWHEREWHEREWHEREWHERE,count(nodes(p))WITH, unnamed, anchor at end inWHEREWITH, named, anchor at end inWHEREBenchmark suites. Every query in all three suites gets the same DataFusion logical and physical plan on both wheels; the only difference in the printed plans is the new
reversed: falsefield in IC14's graph plan. Timings follow theCONTRIBUTING.mdharness, alternatingmainand branch twice each, with no runner changes. Every answer check passed, and no query moved by more than 15%.mainmainrun 2 / run 1The first graph-benchmark-ldbc memory run on
mainstarted at a load average of 6, which explains its 0.945 gap. The other runs ran at loads of 3 to 5.Setup: lance-csr
mainat 42bdb59, branch at 8345967; graph-benchmark-ldbc cbd6d62, graph-benchmark-ldbc-complex a3eb756, graph-benchmark 45e4dd1. Apple M5 MacBook Pro, 24 GB, macOS 26.6.2.Every query, mean of two runs each
graph-benchmark, memory
Geomean branch/main: 1.003; main run 2 / run 1: 0.990 (largest single-query main gap 4%)
graph-benchmark-ldbc, memory
Geomean branch/main: 0.980; main run 2 / run 1: 0.945 (largest single-query main gap 38%)
graph-benchmark-ldbc, lazy
Geomean branch/main: 0.996; main run 2 / run 1: 1.002 (largest single-query main gap 3%)
graph-benchmark-ldbc-complex, memory
Geomean branch/main: 1.005; main run 2 / run 1: 1.003 (largest single-query main gap 1%)
graph-benchmark-ldbc-complex, lazy
Geomean branch/main: 0.997; main run 2 / run 1: 0.990 (largest single-query main gap 7%)
🤖 Generated with Claude Code