Skip to content

Named paths build path values that the query never reads #212

Done

Description

@prrao87

What happens

A named path builds its Arrow path value for every path it finds, even when the query never reads the path variable:

MATCH p = (a:Person {ID: 1131})-[:knows*1..3]->(b:Person)
RETURN count(*)

On the LDBC SF1 graph this finds 86,096 paths, and PathMatchExec emits about 100 MB of path values (node records, relationship records and their endpoints) only for count(*) to discard them. Both routes pay for it: the edge inventory takes the records from its prebuilt arrays, and the CSR walk from #211 reads each returned relationship's columns from its table.

This is the one shape #211 left slower than main. In lazy mode the CSR walk reads those relationships from Lance by row, while the inventory scans the 180K-edge knows table once (release builds, best of 5):

Mode main (inventory) #211 (CSR walk)
memory 71 ms 73 ms
lazy 74 ms 86 ms

Suggested fix

When the query never references the path variable (p, nodes(p), relationships(p), length(p) and so on), plan the named path without a path value, the way the planner already does for an unnamed, bounded undirected segment with several types. PathMatchExec then emits only the boundary columns, and neither route builds node or relationship records it doesn't return.

The planner side is in build_path_match (crates/lance-csr/src/datafusion_planner/builder/path_ops.rs), which sets PathSpec::variable. PathMatchNode::try_new adds the path column when that is set, and the operator then calls paths_array and, on the CSR route, builds relationship records.

How to check

  • The count query above, and queries such as RETURN b.ID over a named path that never read p, no longer build path values on either route. EXPLAIN ANALYZE's output_bytes for PathMatchExec should drop from about 100 MB.
  • Queries that do read p or its functions return the same results as before.
  • Time the count query on SF1 in both memory and lazy modes, and run both benchmark suites as CONTRIBUTING.md describes.

Activity

  1. added
    enhancement
    on Nov 25, 2026
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions