class Axiom::Optimizer::Algebra::Restriction::CombinationOperand

Optimize when the operand is a combine operation

Public Instance Methods

optimizable?() click to toggle source

Test if the restriction is commutative

@return [Boolean]

@api private

# File lib/axiom/optimizer/algebra/restriction.rb, line 149
def optimizable?
  restriction_commutative?
end
optimize() click to toggle source

Distribute the restriction across the operation and apply to the operands

@return [Restriction]

@api private

# File lib/axiom/optimizer/algebra/restriction.rb, line 158
def optimize
  left_restriction.send(relation_method, right_restriction).restrict(partition.remainder)
end

Private Instance Methods

left_restriction() click to toggle source

Restrict the left operand with the left predicate partition

@return [Restriction]

@api private

# File lib/axiom/optimizer/algebra/restriction.rb, line 217
def left_restriction
  operand.left.restrict(partition.left)
end
partition() click to toggle source

Return a predicate partition for the restriction and operand headers

@return [PredicatePartition]

@api private

# File lib/axiom/optimizer/algebra/restriction.rb, line 169
def partition
  PredicatePartition.new(predicate, operand.left.header, operand.right.header)
end
partition_left_tautology?() click to toggle source

Test if the predicate for the left operand would match everything

@return [Boolean]

@api private

# File lib/axiom/optimizer/algebra/restriction.rb, line 191
def partition_left_tautology?
  partition.left.equal?(Axiom::Function::Proposition::Tautology.instance)
end
partition_right_tautology?() click to toggle source

Test if the predicate for the right operand would match everything

@return [Boolean]

@api private

# File lib/axiom/optimizer/algebra/restriction.rb, line 200
def partition_right_tautology?
  partition.right.equal?(Axiom::Function::Proposition::Tautology.instance)
end
restriction_commutative?() click to toggle source

Test if the restriction can be distributed over the operation

If the predicates for the left and right operands would match everything, there is no point in distributing the restriction across the operation, since it will not affect the result.

@return [Boolean]

@api private

# File lib/axiom/optimizer/algebra/restriction.rb, line 182
def restriction_commutative?
  ! (partition_left_tautology? && partition_right_tautology?)
end
right_restriction() click to toggle source

Restrict the right operand with the right predicate partition

@return [Restriction]

@api private

# File lib/axiom/optimizer/algebra/restriction.rb, line 226
def right_restriction
  operand.right.restrict(partition.right)
end