Skip to content

Optimize planner stats and functional recursive joins#574

Merged
adsharma merged 4 commits into
mainfrom
optimizer-rel-stats
Jun 8, 2026
Merged

Optimize planner stats and functional recursive joins#574
adsharma merged 4 commits into
mainfrom
optimizer-rel-stats

Conversation

@adsharma

@adsharma adsharma commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds generic planner stats support for relationship cardinality estimates, an explicit ANALYZE command to refresh planner stats, and a guarded recursive-join fast path for functional chains.

The functional-chain recursive join fast path applies to a narrow, generic case:

  • variable-length walk (*min..max)
  • forward direction only
  • one node table on both ends
  • one relationship table from that table back to itself
  • no path materialization
  • each source node has at most one valid outgoing edge

When those conditions hold, the relationship graph is a set of chains or cycles where every node has zero or one next node. Instead of running the full recursive graph-search machinery, the operator first builds a nextOffsets array:

node offset -> next node offset, or INVALID_OFFSET

If it sees two outgoing neighbors for any node, it bails out and uses the normal recursive implementation.

Once the array is built, each source node is handled by pointer chasing:

src -> next -> next -> next ...

It emits (src, dst, length) rows for lengths in the requested recursive range, respecting lowerBound, upperBound, input/output masks, visibility, and limit counters.

Why this is faster: the normal recursive machinery has to manage frontier expansion, graph scans, path semantics, intermediate state, and generalized output handling. For a functional chain, there is no branching, so the next hop is just an array lookup per step. That turns recursive expansion into tight linear pointer chasing while preserving the same result shape for the guarded case.

Validation

  • cmake --build build/release --target lbug_shell -j 8
  • RE24 script against /tmp/bb_full_hash_off_fwd_art.lbug in read-only mode
  • ANALYZE; and ANALYZE Event; against /tmp/bb_full_hash_off_fwd_art.lbug in read-only mode

@adsharma adsharma force-pushed the optimizer-rel-stats branch from 6e009e6 to df5954d Compare June 7, 2026 16:57
@adsharma adsharma merged commit 1683a1e into main Jun 8, 2026
4 checks passed
@adsharma adsharma deleted the optimizer-rel-stats branch June 8, 2026 04:40
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.

1 participant