Skip to main content

Module subquery

Module subquery 

Source
Expand description

Correlated-subquery evaluation split out of lib.rs (lib.rs split 5): the per-row eval_expr_with_correlated path (clones the expression, substitutes outer-row columns into each surviving subquery node, runs the inner SELECT, folds the literal result back) plus the subquery_replacement pre-walk that materialises uncorrelated subquery nodes once, and the try_batch_correlated_scalar keyed-probe optimisation (round-22 phase 3) that runs a correlated scalar subquery ONCE without the correlation and folds rows into a key→value map. impl Engine methods; the bare-SELECT / DML / join row loops drive eval_expr_with_correlated, and select.rs drives subquery_replacement / try_batch_correlated_scalar.

Structs§

ScalarPkProbeFastPath
v7.32 (R30 memory) — cheap static correlation pre-check.

Statics§

BATCHED_SCALAR_FALL_THROUGH_COUNT
BATCHED_SCALAR_KEYED_FIRE_COUNT
v7.37.4 A’ — per-keyed-probe / per-fallback counters for the batched scalar subquery resolver. Used by perf-gate instrumentation to distinguish “keyed path fires but per-probe is slow” from “keyed path never fires” — A’ targets the former.
BATCHED_SCALAR_KEYED_PROBE_COUNT
EXISTS_BATCH_FALL_THROUGH_COUNT
EXISTS_BATCH_FIRE_COUNT
EXISTS_PULLUP_FIRE_COUNT
v7.37.4 A’ — EXISTS path counters. Distinguish whether mailrs prod’s 2-column NOT EXISTS goes through the cheap try_batch_correlated_exists (one inner scan + per-row hash probe) or the slow pull_up_exists_sublinks rewrite (rejects multi-column correlation today). Ablation finding 2026-06-19: the NOT EXISTS conjunct in /api/conversations costs ~165 ms per 100k bench iteration — figure out which path is actually being taken.
EXISTS_PULLUP_MULTICOL_DISABLE
v7.37.4 A’’ — differential knob. When true, the multi-column branch of try_pull_up_exists_sublink rejects (falling back to the v7.34.2 batch resolver path); single-column EXISTS pullup still fires. Lets the differential e2e prove byte-equal results between the new pullup path and the legacy batch path. Default false — production never sets this.
PULLUP_LIMIT1_FIRE_COUNT
v7.37.4 — fire counter for the LIMIT 1 pullup pass. Tests inspect this to confirm whether the rewrite actually triggered on a given SQL shape (semantic-equivalence tests pass either way). Relaxed ordering is fine: tests synchronize on full query execution.
SCALARSQ_PK_PROBE_FIRED
SCALARSQ_PK_PROBE_PLAN_FIRED
v7.37.x — per-row hit counter for the plan-cached fast path.
SCALARSQ_PK_PROBE_PLAN_OUTER_INT

Functions§

expr_tree_has_subquery
Quick scan for any subquery-bearing node in a SELECT’s WHERE / projection / order_by — saves cloning the AST when there are none (the common case).