ddn.df.optimizer
The bounded query optimizer of ddn.df (ADR-2026-10-24-16, amended 2026-10-29): proved-safe rewrites over the plan tree - predicate pushdown, the two fusion rules (adjacent filters compose under the totality rule; a withColumn inlines into the one projection expression referencing it) and projection pruning - applied before the executor walks the tree, plus the shared-subplan prediction of the executor's per-collection memo (structurally identical deterministic subtrees evaluate once per collection). Every rewrite preserves the oracle contract bitwise: the optimized collect equals both the unoptimized collect and the eager chain in values, schema, row order, validity and error behaviour.
The eligibility contract (binding):
- Barriers - a predicate never crosses a limit, an aggregation, a join, a window expression or an unclassified node.
- Totality - a predicate crosses a computed projection or a
withColumnvalue only when the crossed expressions are provably total (direct column references and literals), because a projection evaluated on fewer rows could lose the error a dropped row would have raised. Identity column references and literals are safe: they produce the same values (or the same absence) on any row subset. The same rule admits filter fusion: a total outer predicate may evaluate on all rows, not just the survivors, because it raises no error either way. - Shadowing - a predicate that references a projected or replaced output name moves only when that output is the identity reference of the same column (the values below are identical).
- Sort commutation - a predicate crosses a sort freely: the stable sort of an order-preserved subset equals filtering after the sort.
- Fusion composes adjacent filters only when the outer predicate is total and both predicates resolve BOOLEAN where they evaluate, and inlines a withColumn only into the single projection expression referencing it (never through over keys, aggregate or window holders); the substitution is structural, never a reassociation, and alias-wrapping preserves the output names.
- Pruning removes only what no downstream node references - dead projection entries, dead
withColumnnodes and unreferenced source columns - and only across provably total expressions, so no evaluation and no error disappears. - Float reductions and expression evaluation order never change; aggregation and join inputs prune to exactly their referenced columns; nothing below a join is pruned this tier.
- Shared-subplan reuse is the executor's per-collection memo over structural subtree identity; the optimizer only predicts its count (the counters'
sharedSubplans).Copyright
Copyright (c) 2026, DDN (D Developer Network) MembersBSD-3-Clause
Types 2
The rewrite counters one optimization pass reports (also the explain annotations). sharedSubplans is not a rewrite but the executor's predicted work reduction: the number of subtree results the per-collection memo will serve instead of re-evaluating.
size_t pushedFilterssize_t prunedProjectionssize_t droppedColumnssize_t droppedNodessize_t fusedFilterssize_t fusedProjectionssize_t sharedSubplanssize_t scanProjectionsThe result of one optimization pass: the rewritten plan root and the rule counters.
Functions 9
OptResult optimizePlan(PlanNode root) @safeOptimizes a plan: predicate pushdown, then the two proved-safe fusion rules, then projection pruning, and finally the shared-subplan prediction of the executor's per-collection memo. Every rule pre...