org.eigenbase.relopt
Class AbstractRelOptPlanner

java.lang.Object
  extended by org.eigenbase.relopt.AbstractRelOptPlanner
All Implemented Interfaces:
RelOptPlanner
Direct Known Subclasses:
HepPlanner, MockRelOptPlanner, VolcanoPlanner

public abstract class AbstractRelOptPlanner
extends Object
implements RelOptPlanner

AbstractRelOptPlanner is an abstract base for implementations of the RelOptPlanner interface.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/relopt/AbstractRelOptPlanner.java#13 $
Author:
John V. Sichi

Field Summary
private  CancelFlag cancelFlag
           
private static Pattern IntegerPattern
          Regular expression for integer.
private  MulticastRelOptListener listener
           
private  Map<String,RelOptRule> mapDescToRule
          Maps rule description to rule, just to ensure that rules' descriptions are unique.
private  Pattern ruleDescExclusionFilter
           
 
Fields inherited from interface org.eigenbase.relopt.RelOptPlanner
tracer
 
Constructor Summary
protected AbstractRelOptPlanner()
          Creates an AbstractRelOptPlanner.
 
Method Summary
 void addListener(RelOptListener newListener)
          Adds a listener to this planner.
 boolean addRelTraitDef(RelTraitDef relTraitDef)
          Registers a rel trait definition.
 void checkCancel()
          Checks to see whether cancellation has been requested, and if so, throws an exception.
 RelOptPlanner chooseDelegate()
          Negotiates an appropriate planner to deal with distributed queries.
protected  void fireRule(RelOptRuleCall ruleCall)
          Fires a rule, taking care of tracing and listener notification.
 RelOptCost getCost(RelNode rel)
          Computes the cost of a RelNode.
 JavaRelImplementor getJavaRelImplementor(RelNode rel)
          Retrieves an implementor appropriate for the context in which this planner was created.
protected  MulticastRelOptListener getListener()
           
 long getRelMetadataTimestamp(RelNode rel)
          Gets a timestamp for a given rel's metadata.
protected  RelOptRule getRuleByDescription(String description)
          Returns the rule with a given description
 boolean isRuleExcluded(RelOptRule rule)
          Determines whether a given rule is excluded by ruleDescExclusionFilter.
 RelOptCost makeCost(double dRows, double dCpu, double dIo)
          Creates a cost object.
 RelOptCost makeHugeCost()
          Creates a cost object representing an enormous non-infinite cost.
 RelOptCost makeInfiniteCost()
          Creates a cost object representing infinite cost.
 RelOptCost makeTinyCost()
          Creates a cost object representing a small positive cost.
 RelOptCost makeZeroCost()
          Creates a cost object representing zero cost.
protected  void mapRuleDescription(RelOptRule rule)
          Registers a rule's description.
protected  void notifyChosen(RelNode rel)
          Takes care of tracing and listener notification when a rel is chosen as part of the final plan.
protected  void notifyDiscard(RelNode rel)
          Takes care of tracing and listener notification when a rel is discarded
protected  void notifyEquivalence(RelNode rel, Object equivalenceClass, boolean physical)
          Takes care of tracing and listener notification when a rel equivalence is detected.
protected  void notifyTransformation(RelOptRuleCall ruleCall, RelNode newRel, boolean before)
          Takes care of tracing and listener notification when a rule's transformation is applied.
 void registerMetadataProviders(ChainedRelMetadataProvider chain)
          Gives this planner a chance to register one or more RelMetadataProviders in the chain which will be used to answer metadata queries.
 void registerSchema(RelOptSchema schema)
          Tells this planner that a schema exists.
 void setCancelFlag(CancelFlag cancelFlag)
          Installs the cancellation-checking flag for this planner.
 void setImportance(RelNode rel, double importance)
          Sets the importance of a relational expression.
 void setRuleDescExclusionFilter(Pattern exclusionFilter)
          Sets the exclusion filter to use for this planner.
protected  void unmapRuleDescription(RelOptRule rule)
          Removes the mapping between a rule and its description.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eigenbase.relopt.RelOptPlanner
addRule, changeTraits, ensureRegistered, findBestExp, getRoot, isRegistered, register, removeRule, setRoot
 

Field Detail

IntegerPattern

private static final Pattern IntegerPattern
Regular expression for integer.


mapDescToRule

private final Map<String,RelOptRule> mapDescToRule
Maps rule description to rule, just to ensure that rules' descriptions are unique.


listener

private MulticastRelOptListener listener

ruleDescExclusionFilter

private Pattern ruleDescExclusionFilter

cancelFlag

private CancelFlag cancelFlag
Constructor Detail

AbstractRelOptPlanner

protected AbstractRelOptPlanner()
Creates an AbstractRelOptPlanner.

Method Detail

setCancelFlag

public void setCancelFlag(CancelFlag cancelFlag)
Description copied from interface: RelOptPlanner
Installs the cancellation-checking flag for this planner. The planner should periodically check this flag and terminate the planning process if it sees a cancellation request.

Specified by:
setCancelFlag in interface RelOptPlanner
Parameters:
cancelFlag - flag which the planner should periodically check

checkCancel

public void checkCancel()
Checks to see whether cancellation has been requested, and if so, throws an exception.


mapRuleDescription

protected void mapRuleDescription(RelOptRule rule)
Registers a rule's description.

Parameters:
rule - Rule

unmapRuleDescription

protected void unmapRuleDescription(RelOptRule rule)
Removes the mapping between a rule and its description.

Parameters:
rule - Rule

getRuleByDescription

protected RelOptRule getRuleByDescription(String description)
Returns the rule with a given description

Parameters:
description - Description
Returns:
Rule with given description, or null if not found

setRuleDescExclusionFilter

public void setRuleDescExclusionFilter(Pattern exclusionFilter)
Description copied from interface: RelOptPlanner
Sets the exclusion filter to use for this planner. Rules which match the given pattern will not be fired regardless of whether or when they are added to the planner.

Specified by:
setRuleDescExclusionFilter in interface RelOptPlanner
Parameters:
exclusionFilter - pattern to match for exclusion; null to disable filtering

isRuleExcluded

public boolean isRuleExcluded(RelOptRule rule)
Determines whether a given rule is excluded by ruleDescExclusionFilter.

Parameters:
rule - rule to test
Returns:
true iff rule should be excluded

chooseDelegate

public RelOptPlanner chooseDelegate()
Description copied from interface: RelOptPlanner
Negotiates an appropriate planner to deal with distributed queries. The idea is that the schemas decide among themselves which has the most knowledge. Right now, the local planner retains control.

Specified by:
chooseDelegate in interface RelOptPlanner

registerSchema

public void registerSchema(RelOptSchema schema)
Description copied from interface: RelOptPlanner
Tells this planner that a schema exists. This is the schema's chance to tell the planner about all of the special transformation rules.

Specified by:
registerSchema in interface RelOptPlanner

getRelMetadataTimestamp

public long getRelMetadataTimestamp(RelNode rel)
Description copied from interface: RelOptPlanner
Gets a timestamp for a given rel's metadata. This timestamp is used by CachingRelMetadataProvider to decide whether cached metadata has gone stale.

Specified by:
getRelMetadataTimestamp in interface RelOptPlanner
Parameters:
rel - rel of interest
Returns:
timestamp of last change which might affect metadata derivation

setImportance

public void setImportance(RelNode rel,
                          double importance)
Description copied from interface: RelOptPlanner
Sets the importance of a relational expression.

An important use of this method is when a RelOptRule has created a relational expression which is indisputably better than the original relational expression. The rule set the original relational expression's importance to zero, to reduce the search space. Pending rule calls are cancelled, and future rules will not fire.

Specified by:
setImportance in interface RelOptPlanner
Parameters:
rel - Relational expression
importance - Importance

makeCost

public RelOptCost makeCost(double dRows,
                           double dCpu,
                           double dIo)
Description copied from interface: RelOptPlanner
Creates a cost object.

Specified by:
makeCost in interface RelOptPlanner

makeHugeCost

public RelOptCost makeHugeCost()
Description copied from interface: RelOptPlanner
Creates a cost object representing an enormous non-infinite cost.

Specified by:
makeHugeCost in interface RelOptPlanner

makeInfiniteCost

public RelOptCost makeInfiniteCost()
Description copied from interface: RelOptPlanner
Creates a cost object representing infinite cost.

Specified by:
makeInfiniteCost in interface RelOptPlanner

makeTinyCost

public RelOptCost makeTinyCost()
Description copied from interface: RelOptPlanner
Creates a cost object representing a small positive cost.

Specified by:
makeTinyCost in interface RelOptPlanner

makeZeroCost

public RelOptCost makeZeroCost()
Description copied from interface: RelOptPlanner
Creates a cost object representing zero cost.

Specified by:
makeZeroCost in interface RelOptPlanner

getCost

public RelOptCost getCost(RelNode rel)
Description copied from interface: RelOptPlanner
Computes the cost of a RelNode. In most cases, this just dispatches to RelMetadataQuery.getCumulativeCost(org.eigenbase.rel.RelNode).

Specified by:
getCost in interface RelOptPlanner
Parameters:
rel - expression of interest
Returns:
estimated cost

addListener

public void addListener(RelOptListener newListener)
Description copied from interface: RelOptPlanner
Adds a listener to this planner.

Specified by:
addListener in interface RelOptPlanner
Parameters:
newListener - new listener to be notified of events

getJavaRelImplementor

public JavaRelImplementor getJavaRelImplementor(RelNode rel)
Description copied from interface: RelOptPlanner
Retrieves an implementor appropriate for the context in which this planner was created.

Specified by:
getJavaRelImplementor in interface RelOptPlanner

registerMetadataProviders

public void registerMetadataProviders(ChainedRelMetadataProvider chain)
Description copied from interface: RelOptPlanner
Gives this planner a chance to register one or more RelMetadataProviders in the chain which will be used to answer metadata queries. Planners which use their own relational expressions internally to represent concepts such as equivalence classes will generally need to supply corresponding metadata providers.

Specified by:
registerMetadataProviders in interface RelOptPlanner
Parameters:
chain - receives planner's custom providers, if any

addRelTraitDef

public boolean addRelTraitDef(RelTraitDef relTraitDef)
Description copied from interface: RelOptPlanner
Registers a rel trait definition. If the RelTraitDef has already been registered, does nothing.

Specified by:
addRelTraitDef in interface RelOptPlanner
Returns:
whether the RelTraitDef was added, as per Collection.add(E)

fireRule

protected void fireRule(RelOptRuleCall ruleCall)
Fires a rule, taking care of tracing and listener notification.

Parameters:
ruleCall - description of rule call
"Precondition:"
ruleCall.getRule().matches(ruleCall)

notifyTransformation

protected void notifyTransformation(RelOptRuleCall ruleCall,
                                    RelNode newRel,
                                    boolean before)
Takes care of tracing and listener notification when a rule's transformation is applied.

Parameters:
ruleCall - description of rule call
newRel - result of transformation
before - true before registration of new rel; false after

notifyChosen

protected void notifyChosen(RelNode rel)
Takes care of tracing and listener notification when a rel is chosen as part of the final plan.

Parameters:
rel - chosen rel

notifyEquivalence

protected void notifyEquivalence(RelNode rel,
                                 Object equivalenceClass,
                                 boolean physical)
Takes care of tracing and listener notification when a rel equivalence is detected.

Parameters:
rel - chosen rel

notifyDiscard

protected void notifyDiscard(RelNode rel)
Takes care of tracing and listener notification when a rel is discarded

Parameters:
rel - discarded rel

getListener

protected MulticastRelOptListener getListener()