Class PropertyDeriver

java.lang.Object
com.darkcollective.relix.cost.PropertyDeriver

public final class PropertyDeriver extends Object
Derives RelationProperties for a RelNode tree bottom-up, purely structurally — from each operator's semantics and its children's properties — with no schema or symbol-table lookup.

Because the derivation reads only node structure, it is robust against the optimizer rewriting nodes (a rewritten subtree carries no schema annotation): properties are recomputed from whatever tree it is handed.

Distinctness rules

  • Establish whole-row distinctness (output is a set regardless of input): δ, ∪, ∩, −, ∆, ÷, transitive closure.
  • Establish a candidate key from structurally known unique columns: grouping aggregation (γ) and group-wise universal quantification (∀) are unique on their grouping keys (an empty grouping-key list ⇒ at most one row).
  • Preserve the input's distinctness (row-subset / reorder / relation-only rename): σ, τ, λ, sampling, TOP, OPTIMIZE, and the left input of ⋉/▷.
  • Conservatively break distinctness (may introduce or require duplicates, or change values): base relations (no key info in this phase), all joins/products/composition, ⊎, π (may drop key columns), μ (UNNEST), and SOLVE.

Every rule is conservative: it never reports isDuplicateFree() for a relation that could contain duplicates. It derives distinctness structurally only: base-relation primary keys, candidate-key survival through π and key propagation through joins are not part of the derivation.

  • Method Details

    • derive

      public static RelationProperties derive(RelNode node)
      Derives the logical properties of the relation produced by node, assuming every leaf is bounded (equivalent to derive(node, BoundednessSource.ALL_BOUNDED)).
      Parameters:
      node - the tree to analyse; must not be null
      Returns:
      the derived properties; never null (conservatively RelationProperties.none() when nothing can be proven)
    • derive

      public static RelationProperties derive(RelNode node, DistinctnessSource distinctnessSource)
      Derives properties taking leaf distinctness from distinctnessSource (and all-bounded leaves). A leaf the source reports duplicate-free yields whole-row distinctness; everything else is structural as usual.
      Parameters:
      node - the tree to analyse; must not be null
      distinctnessSource - the per-leaf duplicate-free lookup; must not be null
      Returns:
      the derived properties; never null
    • derive

      public static RelationProperties derive(RelNode node, BoundednessSource boundednessSource)
      Derives the logical properties of node, taking leaf boundedness from boundednessSource. Distinctness is derived purely structurally; the boundedness is computed bottom-up — contagious upward from leaves, with λ (LIMIT) bounding its input — and overlaid onto the result.
      Parameters:
      node - the tree to analyse; must not be null
      boundednessSource - the per-leaf boundedness lookup; must not be null
      Returns:
      the derived properties; never null
    • derive

      public static RelationProperties derive(RelNode node, BoundednessSource boundednessSource, DistinctnessSource distinctnessSource)
      Derives the logical properties of node, taking leaf boundedness from boundednessSource and leaf distinctness from distinctnessSource.
      Parameters:
      node - the tree to analyse; must not be null
      boundednessSource - the per-leaf boundedness lookup; must not be null
      distinctnessSource - the per-leaf duplicate-free lookup; must not be null
      Returns:
      the derived properties; never null
    • boundedness

      public static Boundedness boundedness(RelNode node, BoundednessSource boundednessSource)
      Derives only the boundedness of node (without computing distinctness), taking leaf boundedness from boundednessSource.
      Parameters:
      node - the tree to analyse; must not be null
      boundednessSource - the per-leaf boundedness lookup; must not be null
      Returns:
      the relation's boundedness; never null