saffron.opt
Class Rule

java.lang.Object
  |
  +--saffron.opt.Rule
Direct Known Subclasses:
AbstractConverter.ExpandConversionRule, AddFilterToQueryRule, AddProjectToQueryRule, ConverterRule, DistinctToExistsRule, RemoveDistinctRule, RemoveTrivialProjectRule, SwapJoinRule, TableAccessToQueryRule, UnionToDistinctRule

public abstract class Rule
extends Object

A Rule transforms an expression into another. It has a list of Operands, 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(saffron.opt.RuleCall) on each of them.


Field Summary
protected  String description
          Description of rule, must be unique within planner.
(package private)  Operand operand
          Root of operand tree.
(package private)  Operand[] operands
          Flattened list of operands.
protected  VolcanoPlanner planner
          Current planner; set by VolcanoPlanner.addRule(saffron.opt.Rule).
 
Constructor Summary
Rule(Operand operand)
           
 
Method Summary
protected static Rel convert(Planner planner, Rel 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(RuleCall 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

planner

protected VolcanoPlanner planner
Current planner; set by VolcanoPlanner.addRule(saffron.opt.Rule).


operand

final Operand operand
Root of operand tree.


operands

Operand[] operands
Flattened list of operands.


description

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.

Constructor Detail

Rule

public Rule(Operand operand)
Method Detail

guessDescription

private static String guessDescription(String className)

getPlanner

VolcanoPlanner getPlanner()
Returns the current VolcanoPlanner.


onMatch

public abstract void onMatch(RuleCall 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 RuleCall.transformTo(saffron.rel.Rel) to register the expression.


toString

public String toString()
Overrides:
toString in class Object

getOutConvention

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


convert

protected static Rel convert(Planner planner,
                             Rel 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.

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

SourceForge.net_Logo