8000 perf: short-circuit or/or-join branch evaluation using cost model · Issue #250 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

perf: short-circuit or/or-join branch evaluation using cost model #250

Closed

Description

@adityamukho

Summary

Once optimizer::clause_cost() is available (landed in #205), use it to short-circuit or/or-join branch evaluation in apply_or_clauses.

Motivation

Currently apply_or_clauses evaluates all branches unconditionally and unions the results. For disjunctions with one highly selective branch, this wastes work on branches that contribute little or nothing to the final result.

The fast path (no Not/NotJoin in branches) evaluates each branch from an empty seed and hash-joins the union back onto incoming bindings. If the cheapest branch already produces bindings that cover all incoming bindings, subsequent branches add nothing and can be skipped.

Prerequisite

Proposed approach

  1. Sort branches by clause_cost() ascending before evaluation (cheapest first). The branch ordering in plan_or_branches() / clause_cost() from perf(post-1.0): cost-based optimizer extensions for new clause types #205 provides this directly.
  2. In the fast-path loop, track which incoming binding keys are already covered after each branch is joined. Once coverage is complete, break early.
  3. In the seeded slow-path (branches with Not/NotJoin), sort branches cheapest-first so that branches most likely to match run first — less useful for short-circuit but reduces average work per outer binding.

Acceptance criteria

  • apply_or_clauses sorts branches by clause_cost() before evaluation
  • Fast path: early exit when all incoming bindings are covered
  • No change to query results — all existing tests pass
  • Benchmark showing improvement on queries with one selective and one expensive Or branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceBenchmark performance regressions

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0