java.lang.Object
com.darkcollective.relix.cost.PropertyDeriver
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), andSOLVE.
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 Summary
Modifier and TypeMethodDescriptionstatic Boundednessboundedness(RelNode node, BoundednessSource boundednessSource) Derives only the boundedness ofnode(without computing distinctness), taking leaf boundedness fromboundednessSource.static RelationPropertiesDerives the logical properties of the relation produced bynode, assuming every leaf is bounded (equivalent toderive(node, BoundednessSource.ALL_BOUNDED)).static RelationPropertiesderive(RelNode node, BoundednessSource boundednessSource) Derives the logical properties ofnode, taking leaf boundedness fromboundednessSource.static RelationPropertiesderive(RelNode node, BoundednessSource boundednessSource, DistinctnessSource distinctnessSource) Derives the logical properties ofnode, taking leaf boundedness fromboundednessSourceand leaf distinctness fromdistinctnessSource.static RelationPropertiesderive(RelNode node, DistinctnessSource distinctnessSource) Derives properties taking leaf distinctness fromdistinctnessSource(and all-bounded leaves).
-
Method Details
-
derive
Derives the logical properties of the relation produced bynode, assuming every leaf is bounded (equivalent toderive(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
Derives properties taking leaf distinctness fromdistinctnessSource(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 nulldistinctnessSource- the per-leaf duplicate-free lookup; must not be null- Returns:
- the derived properties; never null
-
derive
Derives the logical properties ofnode, taking leaf boundedness fromboundednessSource. 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 nullboundednessSource- 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 ofnode, taking leaf boundedness fromboundednessSourceand leaf distinctness fromdistinctnessSource.- Parameters:
node- the tree to analyse; must not be nullboundednessSource- the per-leaf boundedness lookup; must not be nulldistinctnessSource- the per-leaf duplicate-free lookup; must not be null- Returns:
- the derived properties; never null
-
boundedness
Derives only the boundedness ofnode(without computing distinctness), taking leaf boundedness fromboundednessSource.- Parameters:
node- the tree to analyse; must not be nullboundednessSource- the per-leaf boundedness lookup; must not be null- Returns:
- the relation's boundedness; never null
-