Skip to content

Named paths filtered by all() are still 5x slower than explicit hops #208

Done

Description

@prrao87

What happened?

With #205, a named variable-length path whose relationships share an equality filter drops failing edges during the walk. On #179's repro that takes the query from 21.4 s to 2.6 s. It is still about 5x slower than the same query written as explicit hops, which finds the same 10 paths:

Query (debug build, best of 3) Paths Time
Three explicit hops, rN.day = 5 on each hop 10 0.49 s
*1..3 with all(r IN relationships(p) WHERE r.day = 5) 10 2.60 s
The same with $day instead of 5 10 2.59 s

I haven't profiled this with Claude Opus 5.5 yet (on my TDL). Best guess on the cause for now: the named-path operator builds its edge inventory from every edge of the relationship table, 3M here, and evaluates the filter on all of them before the walk starts. The explicit hops read only the edges next to the start node and its neighbours. If that's right, the gap grows with the size of the relationship table, not with the number of matching paths.

Minimal reproducer

The script from #179, run on the branch from #205:

import time
import numpy as np
import pyarrow as pa
from lance_csr import CypherEngine, GraphConfig

rng = np.random.default_rng(0)
n, m = 20_000, 3_000_000
cfg = GraphConfig.builder().node_table("N", "id").rel_table("R", "N", "N", "src", "dst").build()
e = CypherEngine(cfg, {
    "N": pa.table({"id": np.arange(n)}),
    "R": pa.table({"src": rng.integers(0, n, m), "dst": rng.integers(0, n, m), "day": rng.integers(0, 58, m)}),
}, use_csr=True)

queries = {
    "explicit hops": """
MATCH (a:N {id: 0})-[r1:R]->(:N) WHERE r1.day = 5 RETURN count(*) AS n
UNION ALL MATCH (a:N {id: 0})-[r1:R]->(:N)-[r2:R]->(:N) WHERE r1.day = 5 AND r2.day = 5 RETURN count(*) AS n
UNION ALL MATCH (a:N {id: 0})-[r1:R]->(:N)-[r2:R]->(:N)-[r3:R]->(:N) WHERE r1.day = 5 AND r2.day = 5 AND r3.day = 5 RETURN count(*) AS n""",
    "all() on *1..3": "MATCH p = (a:N {id: 0})-[:R*1..3]->(:N) WHERE all(r IN relationships(p) WHERE r.day = 5) RETURN count(*) AS n",
}
for name, q in queries.items():
    t = time.perf_counter()
    rows = e.execute(q).to_pydict()["n"]
    print(f"{name}: {sum(rows)} paths in {time.perf_counter() - t:.2f}s")

Environment

Activity

  1. added
    bug
    on Nov 25, 2026
  2. added a commit that references this issue on Nov 26, 2026
    bbec0b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions