Class SubqueryMemo

java.lang.Object
dev.frostlake.executor.expressions.SubqueryMemo

public class SubqueryMemo extends Object
Per-(outer-query) memo for subqueries that are evaluated once per outer row. A subquery is uncorrelated if its execution reads no outer (lateral) value — in which case its result is identical for every outer row, so it can be executed once and reused instead of re-executed per row.

Correlation is classified empirically: ExpressionEvaluatorVisitor counts actual lateral-value reads, and a subquery whose first execution reads zero is provably row-independent (any branch decision that depended on an outer value would itself have read one). The classification is therefore exact and conservative — anything that touches the outer context is treated as correlated and never cached.

Scope is one ExpressionEvaluator instance — i.e. one outer query's row loop, evaluated on a single thread — so plain HashMap/HashSet suffice and cached results never leak across queries.

  • Constructor Details

    • SubqueryMemo

      public SubqueryMemo()
  • Method Details

    • cachedResult

      public List<ResultSet> cachedResult(String subquery)
      The cached result of a proven-uncorrelated subquery, or null if not (yet) cached.
    • isCorrelated

      public boolean isCorrelated(String subquery)
      True if this subquery has been proven correlated and must be re-executed per outer row.
    • recordUncorrelated

      public void recordUncorrelated(String subquery, List<ResultSet> result)
    • recordCorrelated

      public void recordCorrelated(String subquery)
    • cachedInSet

      public PreparedInSet cachedInSet(String subquery)
      Prepared IN-membership index for an uncorrelated subquery, or null if not yet built.
    • recordInSet

      public void recordInSet(String subquery, PreparedInSet set)