Class VolcanoRule

Direct Known Subclasses:
AbstractConverter.ExpandConversionRule, AddFilterToQueryRule, AddProjectToQueryRule, ConverterRule, OJPlannerFactory.DistinctToExistsRule, OJPlannerFactory.ProjectedFilterToIteratorRule, RemoveDistinctRule, RemoveTrivialProjectRule, SwapJoinRule, TableAccessToQueryRule, UnionToDistinctRule, VolcanoPlannerTest.BadSingleRule, VolcanoPlannerTest.GoodSingleRule, VolcanoPlannerTest.PhysLeafRule

public abstract class VolcanoRule
extends Object

A VolcanoRule transforms an expression into another. It has a list of RuleOperands, which determine whether the rule can be applied to a particular section of the tree.

The optimizer figures out which rules are applicable, then calls onMatch(net.sf.saffron.opt.VolcanoRuleCall) on each of them.

Field Summary
protected  String description
          Description of rule, must be unique within planner.
(package private)  RuleOperand operand
          Root of operand tree.
(package private)  RuleOperand[] operands
          Flattened list of operands.
protected  VolcanoPlanner planner
          Current planner; set by VolcanoPlanner.addRule(net.sf.saffron.opt.VolcanoRule).
Constructor Summary
VolcanoRule(RuleOperand operand)
Method Summary
protected static SaffronRel convert(SaffronPlanner planner, SaffronRel rel, CallingConvention toConvention)
          Converts a relational expression to a given calling convention, if it is not already of that convention.
 CallingConvention getOutConvention()
          Returns the calling convention of the result of firing this rule, null if not known.
(package private)  VolcanoPlanner getPlanner()
          Returns the current VolcanoPlanner.
private static String guessDescription(String className)
abstract  void onMatch(VolcanoRuleCall call)
          This method is called every time the rule matches.
 String toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


protected String description
Description of rule, must be unique within planner. Default is the name of the class sans package name, but derived classes are encouraged to override.


protected VolcanoPlanner planner
Current planner; set by VolcanoPlanner.addRule(net.sf.saffron.opt.VolcanoRule).


final RuleOperand operand
Root of operand tree.


RuleOperand[] operands
Flattened list of operands.

Constructor Detail


public VolcanoRule(RuleOperand operand)
Method Detail


public abstract void onMatch(VolcanoRuleCall call)
This method is called every time the rule matches. At the time that this method is called, call.rels holds the set of relational expressions which match the operands to the rule; call.rels[0] is the root expression.

Typically a rule would check that the nodes are valid matches, creates a new expression, then calls back VolcanoRuleCall.transformTo(net.sf.saffron.rel.SaffronRel) to register the expression.


public CallingConvention getOutConvention()
Returns the calling convention of the result of firing this rule, null if not known.


public String toString()
toString in class Object


protected static SaffronRel convert(SaffronPlanner planner,
                                    SaffronRel rel,
                                    CallingConvention toConvention)
Converts a relational expression to a given calling convention, if it is not already of that convention. If the conversion is not possible, returns null.

The stubborn parameter controls how hard we try. Using true causes an expression explosion. If the expression you are converting appears as an operand of the rule, it is safe to use stubborn = false: if the operand is transformed to another type, the rule will be invoked again.

planner - Planner
rel - Relexp to convert
toConvention - Desired calling convention
a relational expression of the desired calling convention, or null if no conversion is possible
return == null || return.getConvention() == toConvention


VolcanoPlanner getPlanner()
Returns the current VolcanoPlanner.


private static String guessDescription(String className)