Enum Class OptimizationCode

java.lang.Object
java.lang.Enum<OptimizationCode>
com.darkcollective.relix.optimizer.OptimizationCode
All Implemented Interfaces:
Serializable, Comparable<OptimizationCode>, Constable

public enum OptimizationCode extends Enum<OptimizationCode>
Enumeration of every transformation rule the query optimizer can apply.

Each constant carries a stable code() string (e.g. "EXPR-001") used in reports and audit logs, together with a short description() of what the transformation does.

Codes are grouped by category prefix — one per rule family, in the order the constants are declared below:

  • EXPR-nnn — arithmetic / expression level
  • PRED-nnn — predicate simplification
  • SEL-nnn — selection (σ) rules
  • PROJ-nnn — projection (π) rules
  • JOIN-nnn — join / cross-product rules
  • LATERAL-nnn — lateral (correlated TVF) join decorrelation
  • EQ-nnn — equality propagation across join conditions
  • LIM-nnn — limit (λ) rules
  • AGG-nnn — aggregation (γ) rules
  • DIST-nnn — redundant-δ elimination
  • SORT-nnn — redundant-τ elimination
  • PROD-nnn — Cartesian-product identity elimination
  • SET-nnn — set-operation identities and common-operator hoisting
  • EMPTY-nnn — empty-relation introduction and propagation
  • NEST-nnn — nest/unnest (NF²) round-trip rules
  • CLOSURE-nnn — endpoint bounds folded into CLOSURE
  • TRACE-nnn — endpoint bounds folded into TRACE
  • PATH-nnn — endpoint bounds folded into PATH
  • FIX-nnn — magic sets into a FIX recursion
  • GEN-nnn — production bounds folded into a generator
  • WINDOW-nnn — partition pruning into WINDOW
  • TOPK-nnn — partition pruning into TOP
  • OPTIMIZE-nnn — group pruning into the OPTIMIZE solver
  • SESSION-nnn — partition pruning into SESSIONIZE
  • DOWNSAMPLE-nnn — group pruning into DOWNSAMPLE
  • INLINE-nnn — view-body inlining
  • RENAME-nnn — rename collapsing / elimination

OptimizationCodeTest asserts that this list and the declared constants name the same set of categories, so adding a category without documenting it fails the build.

The category() convenience method returns the prefix string (e.g. "EXPR") derived from code().

  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Collapse a redundant outer aggregation directly above another aggregation: when the outer AggregationNode has no aggregate functions and its grouping keys (as a set) are exactly the inner aggregation's output columns, the inner already emits one row per grouping-key combination, so re-grouping by all of its columns is a no-op and the outer aggregation is removed (γ cols [] (γ keys, aggs (R)) → γ keys, aggs (R)).
    Fold a constant endpoint equality above a CLOSURE/RCLOSURE into the operator as a source/target bound, turning all-pairs reachability into single-source / single-target / single-pair traversal — the canonical magic-sets / sideways-information-passing rewrite.
    Remove a δ (DISTINCT) whose input is already provably duplicate-free, so the deduplication is redundant (δ(R) → R when R is whole-row distinct or has a candidate key — e.g.
    Remove a δ (DISTINCT) below an aggregation that ignores multiplicity, so the deduplication is work its consumer does not need (γ keys, aggs (δ R) → γ keys, aggs (R) when the γ has no aggregates, or only MIN/MAX over deterministic arguments).
    Prune a DownsampleNode to the group(s) a selection fixes: an equality groupingKey = constant on a PER column above the operator is pushed below it, so only the matching group's rows are bucketed and consolidated (σ k = c (DOWNSAMPLE … PER k (R)) → DOWNSAMPLE … PER k (σ k = c (R))).
    Replace a selection whose predicate is constant-false with the empty relation carrying that selection's heading (σ false (R) → ∅).
    Replace an operator with the empty relation because an input that forces emptiness is empty (∅ ⋈ X → ∅).
    Drop an empty right branch of a bag union (X ⊎ ∅ → X).
    Propagate a literal binding across an equi-join's equality classes, so a filter written against one side also constrains the other (A.x = B.x ∧ A.x = 5 ⊨ B.x = 5).
    Evaluate a binary arithmetic expression whose both operands are numeric literals at planning time (e.g.
    Evaluate a string concatenation whose both operands are string literals at planning time (e.g.
    Remove addition or subtraction of zero (x + 0 → x, x − 0 → x, 0 + x → x).
    Remove multiplication by one or division by one (x * 1 → x, 1 * x → x, x / 1 → x).
    Replace multiplication by zero with zero (x * 0 → 0, 0 * x → 0).
    Remove double unary negation (−(−x) → x).
    Reassociate constants in a chain of the same commutative+associative operator so they can be folded together ((x + k1) + k2 → x + (k1+k2)).
    Remove a redundant outer call to an idempotent single-argument built-in function (f(f(x)) → f(x)).
    Push a selection over frozen columns into a FIX least-fixpoint — the general magic-sets / sideways-information-passing rewrite over arbitrary monotone, linear recursion — the umbrella case of which CLOSURE-001/TRACE-001 are fixed-shape instances.
    Fold a top-level upper-bound equality/inequality above a monotone unbounded generator (Naturals/Primes) into the producer as a generation stop, so the otherwise non-terminating scan is finite.
    Replace a reference to a named view (QueryRelationSymbol) with the view's own body, so that later rules (e.g.
    Convert a SelectionNode applied to a ProductNode into a ThetaJoinNode, allowing the executor to filter during the join rather than afterwards.
    Push a selection whose predicate references only one side of a join down into that join input.
    Demote an outer join to a less outer one when a predicate above it rejects NULLs on a column from the padded side, making the rows that join produced by padding unreachable (σ p (A ⟕ B) → σ p (A ⨝θ B) when p rejects NULLs on a column of B).
    Turn an uncorrelated LATERAL table-valued-function join into a plain Cartesian product against a single TVF call (L LATERAL f(args) → L × f(args)) when no argument references a column of the left input.
    Push a LimitNode below an intervening ProjectionNode, since projection is row-count neutral.
    Push a LimitNode below a RenameNode: a rename touches names, never rows, so it is row-count and order neutral (λ(off, n)(ρ … (R)) → ρ … (λ(off, n)(R))).
    Fuse a limit over a sort into a TopKNode — the classic top-N rewrite (λ(off, n)(τ k (R)) → TOP n OFFSET off ORDER BY k (R), with no grouping keys, i.e.
    Replicate a limit into both branches of a UnionAllNode, so neither branch produces more rows than the whole union can possibly use (λ n (A ⊎ B) → λ n ((λ n A) ⊎ (λ n B))).
    Collapse a nest immediately undone by an unnest — the μ ∘ COLLECT = id round-trip law (after Hölsch, Grossniklaus & Scholl, SIGMOD 2016).
    Push a selection below an μ (UNNEST) when its predicate references neither the unnested column nor the WITH ORDINALITY column, so the filter runs before the row-multiplying explode (σ p (μ c (R)) → μ c (σ p (R))).
    Push a column-pruning projection below an μ (UNNEST) so fewer columns flow through the row-multiplying explode (π cols (μ c (R)) → μ c (π cols (R))); fires only when every projected attribute is a bare column, the unnested column is projected unaliased, and there is no WITH ORDINALITY column.
    Prune an OptimizeNode to the group(s) a selection fixes: an equality groupingKey = constant on a PER key above the operator is pushed below it, so the solver runs its MIP/LP for only the matching group instead of every group (σ k = c (OPTIMIZE … PER k (R)) → OPTIMIZE … PER k (σ k = c (R))).
    Fold a constant endpoint equality above a PATH bounded-traversal operator into the operator as a source/target bound, turning an all-pairs breadth-first search into a single-source / single-target / single-pair one.
    Simplify AND or OR expressions that have a constant-true or constant-false branch.
    Remove double logical negation (¬¬p → p).
    Swap the operands of a comparison predicate so the literal is always on the right, mirroring the operator as needed (5 &gt; age → age &lt; 5).
    Collapse a conjunction whose bounds on one column cannot all hold to the constant-false predicate (x > 5 ∧ x < 3, x = 5 ∧ x = 6).
    Drop a bound another conjunct on the same column already implies (x > 5 ∧ x > 3 → x > 5).
    Remove a conjunct that repeats one already present (p ∧ p → p), compared structurally.
    Drop a Cartesian product against the one-tuple truth relation UNIT (DEE), which is the identity of × (R × UNIT → R, UNIT × R → R).
    Remove a projection that outputs exactly the same schema as its input (a no-op pass-through).
    Merge two stacked projections into one (π a (π a,b R) → π a R).
    Push a projection below an intervening selection so fewer columns are carried through the selection evaluation.
    Prune the columns a query never reads, by a top-down "required columns" walk: each node is told which of its output columns its parent needs and derives what it therefore needs from each child, so a base relation is wrapped in a narrowing π whenever the query reads strictly fewer columns than the table has (γ region, SUM(amount) (Sales) → γ region, SUM(amount) (π region, amount (Sales))), and an intermediate π is narrowed to the columns actually read above it.
    Collapse a relation-only ρ into the ρ directly beneath it (ρ V (ρ W [spec] (R)) → ρ V [spec] (R)).
    Remove a relation-only ρ whose alias nothing references (ρ V (X) → X) — the wrapper ViewInliner puts around every inlined view body, which otherwise survives into the final plan and sits between operators that later passes need to see adjacent.
    Drop a column rename that renames a column to the name it already has (ρ id→id, a→q (A) → ρ a→q (A)).
    Compose a pair-form ρ with the pair-form ρ beneath it (ρ b→c (ρ a→b (R)) → ρ a→c (R)).
    Split a conjunctive selection into two stacked selections (σ A∧B R → σ A (σ B R)), enabling independent pushdown of each part.
    Merge two adjacent selections back into one conjunctive predicate (σ A (σ B R) → σ A∧B R), reducing operator count.
    Push a selection below an intervening projection when all referenced attributes are present in the projection's input schema.
    Push a selection below a rename, rewriting attribute references to match the pre-rename column names.
    Push a selection into the appropriate input of a join when the predicate references only one side's columns.
    Replicate a selection into both branches of a UnionAllNode so each branch filters rows early.
    Demote a HAVING-position selection to a WHERE-position one: a conjunct that references only bare-column grouping keys of the AggregationNode below it is evaluated before the blocking γ rather than after (σ p (γ keys, aggs (R)) → γ keys, aggs (σ p (R)) when attrs(p) ⊆ keys).
    Push a selection below a δ (DISTINCT) or a τ (SORT).
    Distribute a selection over a set operation so each branch filters early: replicated into both branches of ∪, ∩, ∆ and −.
    Merge a set operation over two selections of the same input into one selection (σi(A) ∪ σq(A) → δ σ(i ∨ q)(A), σi(A) ∩ σq(A) → δ σ(i ∧ q)(A)), the inverse of SEL_009 and so registered in a later phase.
    Prune a SessionizeNode to the partition(s) a selection fixes: an equality partitionKey = constant on a PER column above the operator is pushed below it, so only the matching partition is buffered, sorted and walked for session boundaries (σ k = c (SESSIONIZE … PER k (R)) → SESSIONIZE … PER k (σ k = c (R))).
    Remove a set operation whose two sides are the same expression (R ∪ R → δ R, R ∩ R → δ R, R − R → ∅, R ∆ R → ∅).
    Remove a set operation between a selection and its own input (σk(R) ∪ R → δ R, σk(R) ∩ R → δ σk(R), σk(R) − R → ∅), in either operand order for the commutative arms.
    Hoist a ρ both branches of a set operation apply identically (ρ spec (R) ∪ ρ spec (Q) → ρ spec (R ∪ Q); likewise ∩, −, ∆, ⊎).
    Hoist a π both branches of a ∪ apply identically (π cols (A) ∪ π cols (B) → δ π cols (A ∪ B)).
    Hoist a × both branches of a ∪ apply to the same operand on the same side (A × B ∪ A × C → δ (A × (B ∪ C)), A × C ∪ B × C → δ ((A ∪ B) × C)).
    Remove a τ (SORT) whose input already delivers an order that satisfies it, so the sort is redundant (τ keys (R) → R when R's delivered order has keys as a prefix — e.g.
    Prune a TopKNode to the partition(s) a selection fixes: an equality partitionKey = constant on a PER grouping column above the top-k is pushed below it, so top-k is computed for only the matching group instead of every group (σ k = c (TOP n … PER k (R)) → TOP n … PER k (σ k = c (R))).
    Fold a constant endpoint equality above a TRACE optimal-path operator into the operator as a source/target bound, turning all-pairs path search into single-source / single-target / single-pair search.
    Prune a partitioned WindowNode to the partition(s) a selection fixes: an equality partitionKey = constant on a PARTITION BY column above the window is pushed below it, so the per-partition window computation runs over only the matching partition and the other partitions are never computed (σ k = c (WINDOW … PARTITION BY k …) → WINDOW … PARTITION BY k … (σ k = c (R))).
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the category prefix of this code (the part before the first '-'), e.g.
    Returns the stable string code used in reports and audit logs, e.g.
    Returns a short human-readable description of what this transformation does.
    Returns a combined "code — description" string suitable for display in reports.
    Returns the enum constant of this class with the specified name.
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • EXPR_001

      public static final OptimizationCode EXPR_001
      Evaluate a binary arithmetic expression whose both operands are numeric literals at planning time (e.g. 2 * 3 → 6).
    • EXPR_002

      public static final OptimizationCode EXPR_002
      Evaluate a string concatenation whose both operands are string literals at planning time (e.g. "a" + "b" → "ab").
    • EXPR_003

      public static final OptimizationCode EXPR_003
      Remove addition or subtraction of zero (x + 0 → x, x − 0 → x, 0 + x → x).
    • EXPR_004

      public static final OptimizationCode EXPR_004
      Remove multiplication by one or division by one (x * 1 → x, 1 * x → x, x / 1 → x).
    • EXPR_005

      public static final OptimizationCode EXPR_005
      Replace multiplication by zero with zero (x * 0 → 0, 0 * x → 0).
    • EXPR_006

      public static final OptimizationCode EXPR_006
      Remove double unary negation (−(−x) → x).
    • EXPR_007

      public static final OptimizationCode EXPR_007
      Reassociate constants in a chain of the same commutative+associative operator so they can be folded together ((x + k1) + k2 → x + (k1+k2)).
    • EXPR_008

      public static final OptimizationCode EXPR_008
      Remove a redundant outer call to an idempotent single-argument built-in function (f(f(x)) → f(x)).
    • PRED_001

      public static final OptimizationCode PRED_001
      Simplify AND or OR expressions that have a constant-true or constant-false branch.
    • PRED_002

      public static final OptimizationCode PRED_002
      Remove double logical negation (¬¬p → p).
    • PRED_003

      public static final OptimizationCode PRED_003
      Swap the operands of a comparison predicate so the literal is always on the right, mirroring the operator as needed (5 &gt; age → age &lt; 5).
    • PRED_004

      public static final OptimizationCode PRED_004
      Collapse a conjunction whose bounds on one column cannot all hold to the constant-false predicate (x > 5 ∧ x < 3, x = 5 ∧ x = 6).
    • PRED_005

      public static final OptimizationCode PRED_005
      Drop a bound another conjunct on the same column already implies (x > 5 ∧ x > 3 → x > 5).
    • PRED_006

      public static final OptimizationCode PRED_006
      Remove a conjunct that repeats one already present (p ∧ p → p), compared structurally.
    • SEL_001

      public static final OptimizationCode SEL_001
      Split a conjunctive selection into two stacked selections (σ A∧B R → σ A (σ B R)), enabling independent pushdown of each part.
    • SEL_002

      public static final OptimizationCode SEL_002
      Merge two adjacent selections back into one conjunctive predicate (σ A (σ B R) → σ A∧B R), reducing operator count.
    • SEL_003

      public static final OptimizationCode SEL_003
      Push a selection below an intervening projection when all referenced attributes are present in the projection's input schema.
    • SEL_004

      public static final OptimizationCode SEL_004
      Push a selection below a rename, rewriting attribute references to match the pre-rename column names.
    • SEL_005

      public static final OptimizationCode SEL_005
      Push a selection into the appropriate input of a join when the predicate references only one side's columns.
    • SEL_006

      public static final OptimizationCode SEL_006
      Replicate a selection into both branches of a UnionAllNode so each branch filters rows early.
    • SEL_007

      public static final OptimizationCode SEL_007
      Demote a HAVING-position selection to a WHERE-position one: a conjunct that references only bare-column grouping keys of the AggregationNode below it is evaluated before the blocking γ rather than after (σ p (γ keys, aggs (R)) → γ keys, aggs (σ p (R)) when attrs(p) ⊆ keys). A conjunct touching an aggregate output stays above as a residual σ.
    • SEL_008

      public static final OptimizationCode SEL_008
      Push a selection below a δ (DISTINCT) or a τ (SORT). Both are row-preserving and column-preserving with respect to a filter, so filtering first is free and means fewer rows reach a blocking operator (σ p (δ R) → δ (σ p R), σ p (τ k R) → τ k (σ p R)).
    • SEL_009

      public static final OptimizationCode SEL_009
      Distribute a selection over a set operation so each branch filters early: replicated into both branches of ∪, ∩, ∆ and −. The subtrahend is included because the same predicate is applied to the minuend: a row the filtered subtrahend no longer removes is a row the filtered minuend no longer offers, so σp(A − B) = σpA − σpB exactly. ⊎ is SEL_006; ⊔ (outer union) is excluded because its branches have different schemas, so a predicate valid against one may reference a column absent from the other.
    • SEL_010

      public static final OptimizationCode SEL_010
      Merge a set operation over two selections of the same input into one selection (σi(A) ∪ σq(A) → δ σ(i ∨ q)(A), σi(A) ∩ σq(A) → δ σ(i ∧ q)(A)), the inverse of SEL_009 and so registered in a later phase. It deletes a blocking operator outright and leaves one filtered read where there were two, which is also what lets the backend fold the whole thing into a single WHERE. The δ is dropped when the input is provably duplicate-free. The − arm is i ∧ (¬q ∨ q IS UNKNOWN) rather than the i ∧ ¬q it looks like: the subtrahend also fails to hold a row whose q is UNKNOWN, so the difference keeps one where a bare ¬q drops it — see SelectionComplement.
    • PROJ_001

      public static final OptimizationCode PROJ_001
      Remove a projection that outputs exactly the same schema as its input (a no-op pass-through).
    • PROJ_002

      public static final OptimizationCode PROJ_002
      Merge two stacked projections into one (π a (π a,b R) → π a R).
    • PROJ_003

      public static final OptimizationCode PROJ_003
      Push a projection below an intervening selection so fewer columns are carried through the selection evaluation.
    • PROJ_004

      public static final OptimizationCode PROJ_004
      Prune the columns a query never reads, by a top-down "required columns" walk: each node is told which of its output columns its parent needs and derives what it therefore needs from each child, so a base relation is wrapped in a narrowing π whenever the query reads strictly fewer columns than the table has (γ region, SUM(amount) (Sales) → γ region, SUM(amount) (π region, amount (Sales))), and an intermediate π is narrowed to the columns actually read above it. Width multiplies through everything downstream — the SELECT list a pushdown renderer emits, a hash join's build side, and every materializing operator (ColumnPruningPass).
    • JOIN_001

      public static final OptimizationCode JOIN_001
      Convert a SelectionNode applied to a ProductNode into a ThetaJoinNode, allowing the executor to filter during the join rather than afterwards.
    • JOIN_002

      public static final OptimizationCode JOIN_002
      Push a selection whose predicate references only one side of a join down into that join input.
    • JOIN_004

      public static final OptimizationCode JOIN_004
      Demote an outer join to a less outer one when a predicate above it rejects NULLs on a column from the padded side, making the rows that join produced by padding unreachable (σ p (A ⟕ B) → σ p (A ⨝θ B) when p rejects NULLs on a column of B). A ⟗ demotes one half at a time, to ⟕/⟖ and then to ⨝θ. The demotion is a gate in front of several optimizations an outer join cannot have: σ pushdown into both sides, sort-merge planning, JOIN … ON pushdown, and EQ-001. c IS NULL is deliberately not null-rejecting — that is the anti-join idiom (OuterJoinDemotionPass).
    • LATERAL_001

      public static final OptimizationCode LATERAL_001
      Turn an uncorrelated LATERAL table-valued-function join into a plain Cartesian product against a single TVF call (L LATERAL f(args) → L × f(args)) when no argument references a column of the left input. The lateral operator re-plans and re-executes the function body once per left row; with constant arguments every one of those invocations produces the same relation, so a single call is equivalent — the schema is left ++ body either way, and × pairs the two sides in the same order the lateral concatenates them.

      Beyond the per-row work it removes, the rewrite is what makes the operator visible: RelNode.children() reports only the left input, so the TVF body is outside structural traversal and no other rule can see through it. As a × it can become a theta join (JOIN-001), take a pushed selection, and be reordered (LateralDecorrelationPass).

    • EQ_001

      public static final OptimizationCode EQ_001
      Propagate a literal binding across an equi-join's equality classes, so a filter written against one side also constrains the other (A.x = B.x ∧ A.x = 5 ⊨ B.x = 5). The derived predicate is placed as a σ directly on the side whose schema owns the column, so with capability-based pushdown both backends filter independently instead of one shipping its whole table for the engine to discard. Inner (ThetaJoinNode) joins only — an outer join's condition does not hold of its padded rows (TransitiveEqualityPass).
    • LIM_001

      public static final OptimizationCode LIM_001
      Push a LimitNode below an intervening ProjectionNode, since projection is row-count neutral.
    • LIM_002

      public static final OptimizationCode LIM_002
      Push a LimitNode below a RenameNode: a rename touches names, never rows, so it is row-count and order neutral (λ(off, n)(ρ … (R)) → ρ … (λ(off, n)(R))).
    • LIM_003

      public static final OptimizationCode LIM_003
      Fuse a limit over a sort into a TopKNode — the classic top-N rewrite (λ(off, n)(τ k (R)) → TOP n OFFSET off ORDER BY k (R), with no grouping keys, i.e. one global group). The pair materializes and sorts the whole input to then discard all but n rows; TOP keeps a bounded heap instead. The λ's offset carries across unchanged, since TopKNode skips before it takes.
    • LIM_004

      public static final OptimizationCode LIM_004
      Replicate a limit into both branches of a UnionAllNode, so neither branch produces more rows than the whole union can possibly use (λ n (A ⊎ B) → λ n ((λ n A) ⊎ (λ n B))). The outer λ must stay: each branch may supply fewer than n rows. With an offset the branch bound is offset + count — the outer λ still has to skip.
    • AGG_001

      public static final OptimizationCode AGG_001
      Collapse a redundant outer aggregation directly above another aggregation: when the outer AggregationNode has no aggregate functions and its grouping keys (as a set) are exactly the inner aggregation's output columns, the inner already emits one row per grouping-key combination, so re-grouping by all of its columns is a no-op and the outer aggregation is removed (γ cols [] (γ keys, aggs (R)) → γ keys, aggs (R)).
    • DIST_001

      public static final OptimizationCode DIST_001
      Remove a δ (DISTINCT) whose input is already provably duplicate-free, so the deduplication is redundant (δ(R) → R when R is whole-row distinct or has a candidate key — e.g. δ over γ, a set operation, transitive closure, or another δ). Distinctness is derived bottom-up by PropertyDeriver.
    • DIST_002

      public static final OptimizationCode DIST_002
      Remove a δ (DISTINCT) below an aggregation that ignores multiplicity, so the deduplication is work its consumer does not need (γ keys, aggs (δ R) → γ keys, aggs (R) when the γ has no aggregates, or only MIN/MAX over deterministic arguments). Where DIST_001 looks down from the δ at an input that is already a set, this looks up at a consumer that would collapse the duplicates anyway. SUM/COUNT/AVG/COLLECT read multiplicity and block it, as do ARGMAX/ARGMIN. The rule looks through an intervening σ/π/ρ/τ — each emits at most one row per input row — but not a λ/sample/TOP, whose output depends on how many rows arrive.
    • SORT_001

      public static final OptimizationCode SORT_001
      Remove a τ (SORT) whose input already delivers an order that satisfies it, so the sort is redundant (τ keys (R) → R when R's delivered order has keys as a prefix — e.g. τ over a compatible τ, or over σ/λ above one). The delivered order is derived by OrderDeriver.
    • PROD_001

      public static final OptimizationCode PROD_001
      Drop a Cartesian product against the one-tuple truth relation UNIT (DEE), which is the identity of × (R × UNIT → R, UNIT × R → R). UNIT has the empty heading and exactly one row, so the product reproduces R's rows and its column order exactly — unlike swapping a product's operands, which permutes the ordered output schema. The zero-tuple EMPTY (DUM) has no matching rule: R × EMPTY is empty but keeps R's heading, so it cannot be rewritten to the zero-column EMPTY.
    • SET_001

      public static final OptimizationCode SET_001
      Remove a set operation whose two sides are the same expression (R ∪ R → δ R, R ∩ R → δ R, R − R → ∅, R ∆ R → ∅). Structural equality is AstEquivalence, so the two sides match however far apart they were written. The δ is not decoration: ∪ and ∩ declare SET, and handing back a bare R would make a distinctness claim the input need not honour. It is dropped when R is provably duplicate-free. Gated on R being reproducible — X ∆ X over an unseeded SAMPLE is a query about two draws.
    • SET_002

      public static final OptimizationCode SET_002
      Remove a set operation between a selection and its own input (σk(R) ∪ R → δ R, σk(R) ∩ R → δ σk(R), σk(R) − R → ∅), in either operand order for the commutative arms. Same δ rule and same reproducibility gate as SET_001. The other direction is the selection's complement — R − σk(R) → δ σ (¬k ∨ k IS UNKNOWN) (R), and σk(R) ∆ R is that same difference written another way — where a plain σ¬k(R) would drop every row whose k could not be decided.
    • SET_003

      public static final OptimizationCode SET_003
      Hoist a ρ both branches of a set operation apply identically (ρ spec (R) ∪ ρ spec (Q) → ρ spec (R ∪ Q); likewise ∩, −, ∆, ⊎). Unlike the two arms below this one needs no distinctness argument: a rename changes no value and drops no column, and the whole-row set operations match positionally and name-blind, so the rows being de-duplicated are the same before and after.
    • SET_004

      public static final OptimizationCode SET_004
      Hoist a π both branches of a ∪ apply identically (π cols (A) ∪ π cols (B) → δ π cols (A ∪ B)). The δ is what keeps it sound: π does not de-duplicate, so hoisting moves the ∪'s de-duplication from after the narrowing to before it. Fires only when both inputs carry an inferred heading and the two headings agree name for name in order, since the ∪ pairs their columns by position while the π names them.
    • SET_005

      public static final OptimizationCode SET_005
      Hoist a × both branches of a ∪ apply to the same operand on the same side (A × B ∪ A × C → δ (A × (B ∪ C)), A × C ∪ B × C → δ ((A ∪ B) × C)). δ for SET_004's reason. The same side condition is not a simplification: A × B ∪ C × A has the common operand at opposite ends, so factoring it would permute the ordered heading the positional consumers read — which is what JOIN-003 was removed for.
    • EMPTY_001

      public static final OptimizationCode EMPTY_001
      Replace a selection whose predicate is constant-false with the empty relation carrying that selection's heading (σ false (R) → ∅).
    • EMPTY_002

      public static final OptimizationCode EMPTY_002
      Replace an operator with the empty relation because an input that forces emptiness is empty (∅ ⋈ X → ∅).
    • EMPTY_003

      public static final OptimizationCode EMPTY_003
      Drop an empty right branch of a bag union (X ⊎ ∅ → X).
    • NEST_001

      public static final OptimizationCode NEST_001
      Collapse a nest immediately undone by an unnest — the μ ∘ COLLECT = id round-trip law (after Hölsch, Grossniklaus & Scholl, SIGMOD 2016). When a μ unnests exactly the array column produced by a single COLLECT aggregate of the AggregationNode directly beneath it, the group-then-explode reproduces the pre-nest rows, so the pair is rewritten to a plain projection (μ g (γ keys, COLLECT(x)→g (R)) → π keys, (x → g) (R)), removing a blocking γ and the μ.
    • NEST_002

      public static final OptimizationCode NEST_002
      Push a selection below an μ (UNNEST) when its predicate references neither the unnested column nor the WITH ORDINALITY column, so the filter runs before the row-multiplying explode (σ p (μ c (R)) → μ c (σ p (R))).
    • NEST_003

      public static final OptimizationCode NEST_003
      Push a column-pruning projection below an μ (UNNEST) so fewer columns flow through the row-multiplying explode (π cols (μ c (R)) → μ c (π cols (R))); fires only when every projected attribute is a bare column, the unnested column is projected unaliased, and there is no WITH ORDINALITY column.
    • CLOSURE_001

      public static final OptimizationCode CLOSURE_001
      Fold a constant endpoint equality above a CLOSURE/RCLOSURE into the operator as a source/target bound, turning all-pairs reachability into single-source / single-target / single-pair traversal — the canonical magic-sets / sideways-information-passing rewrite. Fires on a top-level conjoined equality on the from/to column against a literal in the selection chain directly above the closure; any non-pushable conjunct remains as a σ above, so the rewrite is a no-op when nothing is pushable. σ from = c (CLOSURE from, to (E)) → CLOSURE from, to ⟨from=c⟩ (E).
    • TRACE_001

      public static final OptimizationCode TRACE_001
      Fold a constant endpoint equality above a TRACE optimal-path operator into the operator as a source/target bound, turning all-pairs path search into single-source / single-target / single-pair search. Fires on a top-level conjoined equality on the from/to column against a literal in the selection chain directly above the trace; any non-pushable conjunct remains as a σ above (no-op when nothing is pushable). σ from = c (TRACE from, to VIA w … (E)) → TRACE from, to VIA w … ⟨from=c⟩ (E).
    • PATH_001

      public static final OptimizationCode PATH_001
      Fold a constant endpoint equality above a PATH bounded-traversal operator into the operator as a source/target bound, turning an all-pairs breadth-first search into a single-source / single-target / single-pair one. The depth column is unaffected: the shortest path from a seed does not depend on which other nodes were searched from, so the bounded result is a slice of the unbounded one. σ from = c (PATH from, to HOPS m TO n AS d (E)) → PATH from, to HOPS m TO n AS d ⟨from=c⟩ (E).
    • FIX_001

      public static final OptimizationCode FIX_001
      Push a selection over frozen columns into a FIX least-fixpoint — the general magic-sets / sideways-information-passing rewrite over arbitrary monotone, linear recursion — the umbrella case of which CLOSURE-001/TRACE-001 are fixed-shape instances. When every attribute a top-level conjunct references is frozen — carried unchanged by the step from the recursive reference to its output — the selection distributes over the fixpoint: σ p (FIX name (base, step)) ≡ FIX name (σ p (base), step[name ↦ σ p (name)]), so the recursion is seeded and restricted by p and the full fixpoint is avoided. Sound by the step's validator-enforced linearity + monotonicity. Non-frozen conjuncts remain as a residual σ above (no-op when nothing is pushable). σ assembly = "Bike" (FIX BOM (Contains, π assembly, … (BOM ⋈ …))) → FIX BOM (σ assembly = "Bike" (Contains), π … (σ assembly = "Bike" (BOM) ⋈ …)).
    • GEN_001

      public static final OptimizationCode GEN_001
      Fold a top-level upper-bound equality/inequality above a monotone unbounded generator (Naturals/Primes) into the producer as a generation stop, so the otherwise non-terminating scan is finite. Fires on σ n < k/n <= k/n = k directly above the generator's ascending value column; the σ is kept above as a residual filter (correctness by construction), and the leaf becomes boundedness-BOUNDED so a downstream blocking operator over it is legal. σ n < 100 (Naturals) → σ n < 100 (Naturals ⟨produce while n < 100⟩).
    • WINDOW_001

      public static final OptimizationCode WINDOW_001
      Prune a partitioned WindowNode to the partition(s) a selection fixes: an equality partitionKey = constant on a PARTITION BY column above the window is pushed below it, so the per-partition window computation runs over only the matching partition and the other partitions are never computed (σ k = c (WINDOW … PARTITION BY k …) → WINDOW … PARTITION BY k … (σ k = c (R))). Safe because the window frame never crosses a partition boundary, so the per-partition result is identical. Predicates on non-partition or computed columns stay as a residual σ above the window.
    • TOPK_001

      public static final OptimizationCode TOPK_001
      Prune a TopKNode to the partition(s) a selection fixes: an equality partitionKey = constant on a PER grouping column above the top-k is pushed below it, so top-k is computed for only the matching group instead of every group (σ k = c (TOP n … PER k (R)) → TOP n … PER k (σ k = c (R))). Safe because top-k is computed independently per group; predicates on non-partition columns stay as a residual σ above.
    • OPTIMIZE_001

      public static final OptimizationCode OPTIMIZE_001
      Prune an OptimizeNode to the group(s) a selection fixes: an equality groupingKey = constant on a PER key above the operator is pushed below it, so the solver runs its MIP/LP for only the matching group instead of every group (σ k = c (OPTIMIZE … PER k (R)) → OPTIMIZE … PER k (σ k = c (R))). Safe because OPTIMIZE solves each group's problem independently; a predicate on a non-grouping column changes the optimum under emit-the-optimum semantics and stays as a residual σ above .
    • SESSION_001

      public static final OptimizationCode SESSION_001
      Prune a SessionizeNode to the partition(s) a selection fixes: an equality partitionKey = constant on a PER column above the operator is pushed below it, so only the matching partition is buffered, sorted and walked for session boundaries (σ k = c (SESSIONIZE … PER k (R)) → SESSIONIZE … PER k (σ k = c (R))). Safe because a session boundary never spans a PER key (SelectionIntoTimeSeriesPass).
    • DOWNSAMPLE_001

      public static final OptimizationCode DOWNSAMPLE_001
      Prune a DownsampleNode to the group(s) a selection fixes: an equality groupingKey = constant on a PER column above the operator is pushed below it, so only the matching group's rows are bucketed and consolidated (σ k = c (DOWNSAMPLE … PER k (R)) → DOWNSAMPLE … PER k (σ k = c (R))). Does not fire when the operator carries FOR n ROWS: that keeps the n most recent buckets across all groups, so pushing a group filter below it changes which buckets survive (SelectionIntoTimeSeriesPass).
    • INLINE_001

      public static final OptimizationCode INLINE_001
      Replace a reference to a named view (QueryRelationSymbol) with the view's own body, so that later rules (e.g. selection/projection pushdown) can optimise across the former view boundary.
    • RENAME_001

      public static final OptimizationCode RENAME_001
      Collapse a relation-only ρ into the ρ directly beneath it (ρ V (ρ W [spec] (R)) → ρ V [spec] (R)). Unconditional: the outer rename re-anchors every column's provenance to V, so W is not a resolvable qualifier at the outer node's output either way (RenameEliminationPass).
    • RENAME_002

      public static final OptimizationCode RENAME_002
      Remove a relation-only ρ whose alias nothing references (ρ V (X) → X) — the wrapper ViewInliner puts around every inlined view body, which otherwise survives into the final plan and sits between operators that later passes need to see adjacent. Fires only when a whole-tree sweep finds neither V nor any relation name X would re-expose used as a qualifier, since a relation-qualified reference resolves by column provenance (RenameEliminationPass).
    • RENAME_003

      public static final OptimizationCode RENAME_003
      Drop a column rename that renames a column to the name it already has (ρ id→id, a→q (A) → ρ a→q (A)). Dropping the pairs is unconditional; dropping the node is not, since it may still carry a relation name something references — so the node is reduced to its relation-only form and RENAME_002 decides whether it lives (RenameEliminationPass).
    • RENAME_004

      public static final OptimizationCode RENAME_004
      Compose a pair-form ρ with the pair-form ρ beneath it (ρ b→c (ρ a→b (R)) → ρ a→c (R)). Each inner pair's target is looked up among the outer's sources and the chain is collapsed; an outer pair that renames a pass-through column is carried over unchanged. Declines when the two rename the same source column, where the outer pair names a column the inner has already consumed. A rename cycle needs no arm of its own — it composes to an identity pair, which RENAME_003 then drops.
  • Method Details

    • values

      public static OptimizationCode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static OptimizationCode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • code

      public String code()
      Returns the stable string code used in reports and audit logs, e.g. "EXPR-001".
      Returns:
      the code string; never null or blank
    • description

      public String description()
      Returns a short human-readable description of what this transformation does.
      Returns:
      the description; never null or blank
    • category

      public String category()
      Returns the category prefix of this code (the part before the first '-'), e.g. "EXPR" for EXPR_001.
      Returns:
      the category string; never null or blank
    • toString

      public String toString()
      Returns a combined "code — description" string suitable for display in reports.
      Overrides:
      toString in class Enum<OptimizationCode>
      Returns:
      formatted string; never null