Repository navigation
Conversation
A one-hop OPTIONAL MATCH runs as one outer CsrExpandExec, but any WHERE of its own sent it back to planning the input a second time and joining it back. In the shape suite the filtered form was 3.4x (memory) and 25x (lazy) the time of the unfiltered one. The optional clause's own WHERE has exactly the semantics of a filter inside an outer hop: a neighbour that fails it is skipped, and a row left with none keeps one row of nulls. When every conjunct reads only the optional node or relationship, it now moves into the hop (the same PushCsrTargetFilters step the degree count uses). Outer rows are marked matched only after the hop's filters, so a row whose neighbours all fail keeps its null row. A WHERE that reads earlier variables keeps the left join.
Deploying lance-csr with
|
| Latest commit: |
2a3a159
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://523c068e.lance-csr.pages.dev |
| Branch Preview URL: | https://perf-optional-hop-filter.lance-csr.pages.dev |
5 of 16 tasks
This branch has not been deployed
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
OPTIONAL MATCH (x)-[:T]->(b)runs as one CSR expansion: each row walks its neighbours, and a row with no neighbours is kept once, with nulls forb. Adding aWHEREto the optional clause, as inOPTIONAL MATCH (x)-[:T]->(b) WHERE b.flag = 1, switched the planner to a much slower plan. It planned and ran everything before the clause a second time to find the rows to expand, expanded those, and joined the result back to the original rows with a left join.On
main, the shape suite measures the difference. The filtered query took 3.4 times as long as the unfiltered one in memory mode, and 25 times as long in lazy mode, even though it returns fewer rows.What changed
WHEREmoves into the outer hop. Inside an outer hop, a filter has exactly the semanticsOPTIONAL MATCH ... WHEREneeds: a neighbour that fails it is skipped, and a row left with no neighbour keeps its row of nulls. When every condition reads only the optional node or relationship, the planner now moves it into the hop, using the samePushCsrTargetFiltersstep the two-hop degree count already uses.WHEREthat also reads an earlier variable (WHERE b.age > a.age), or a filter written after the optional clause, can't move into the hop and plans as before.Validation
cargo test --workspace,cargo clippy --workspace --all-targets -- -D warnings,make test(1,822 passed), the strict docs build andtypospass locally. New cases in theOPTIONAL MATCHtests cover a relationship filter, a target and relationship filter together, anOR, and aWHEREthat reads an earlier variable, with and without the CSR. The plan test now checks that the first three are a single outer hop and that the last keeps the left join. The same cases also match over Lance datasets. CI has not run yet.CONTRIBUTING.md: release wheels frommain(5676cda) and this branch (2a3a159), alternatingmainand branch twice each,memoryandlazy. Every answer check and every shape-suite phrasing and plan check passed. I reran graph-benchmark-ldbc on its own because my builds for the next change overlapped its first round; the numbers below are from the clean rerun.Shape suite headlines (
smallgraph):optional/optional_wheremoved by −69% (memory) and −94% (lazy). Two memory-mode hub queries moved in one branch run and matchedmainin the other:cycle_100000(1.12 and 1.58 ms against 1.12 and 1.13) andcycle_join_100000, which runs withuse_csr=False(3.19 and 4.37 ms against 3.21 and 3.20).SF1 suites:
mainmainrun 2 / run 1No SF1 query moved by 10% or more.
Machine: Apple M5 MacBook Pro, 24 GB, macOS 26.6.2. Load average 4 to 9, with the high end right after the release build.
Every SF1 query
graph-benchmark, memory
Geomean branch/main: 1.004; main run 2 / run 1: 1.001 (largest single-query main gap 2%)
graph-benchmark-ldbc, memory
Geomean branch/main: 0.989; main run 2 / run 1: 0.981 (largest single-query main gap 13%)
graph-benchmark-ldbc, lazy
Geomean branch/main: 1.000; main run 2 / run 1: 0.994 (largest single-query main gap 3%)
graph-benchmark-ldbc-complex, memory
Geomean branch/main: 0.996; main run 2 / run 1: 0.989 (largest single-query main gap 4%)
graph-benchmark-ldbc-complex, lazy
Geomean branch/main: 0.998; main run 2 / run 1: 1.001 (largest single-query main gap 3%)
Every shape-suite query
memory: small graph (20,000 accounts, 229,517 T edges, hub degrees [10, 1000, 10000, 100000])
Runs: main x2, branch x2.
main run-to-run geomean: 1.000; largest single-query gap 5%.
lazy: small graph (20,000 accounts, 229,517 T edges, hub degrees [10, 1000, 10000, 100000])
Runs: main x2, branch x2.
main run-to-run geomean: 1.003; largest single-query gap 8%.
🤖 Generated with Claude Code