com.lucidera.opt
Class LoptRemoveSelfJoinRule

java.lang.Object
  extended by org.eigenbase.relopt.RelOptRule
      extended by com.lucidera.opt.LoptRemoveSelfJoinRule

public class LoptRemoveSelfJoinRule
extends RelOptRule

LoptRemoveSelfJoinRule implements a rule that converts removable self-joins into a scan on the common underlying row scan table. The projection and filtering applied on each join input are combined into one.

This rule only needs to look for a very specific RelNode pattern because it assumes that LoptModifyRemovableSelfJoinRule has already been applied.

Version:
$Id: //open/dev/farrago/src/com/lucidera/opt/LoptRemoveSelfJoinRule.java#7 $
Author:
Zelaine Fong

Field Summary
static LoptRemoveSelfJoinRule instance
           
 
Fields inherited from class org.eigenbase.relopt.RelOptRule
ANY, description, operands
 
Constructor Summary
private LoptRemoveSelfJoinRule()
          Creates a LoptRemoveSelfJoinRule.
 
Method Summary
private  RelNode combineFilters(FilterRel leftFilter, FilterRel rightFilter, LcsRowScanRel newRowScan)
          Combines filters on top of row scans into a single filter.
private  ProjectRel combineProjects(ProjectRel leftProject, ProjectRel rightProject, RelNode projInput)
          Combines projections on top of filters that are top of row scans into a single projection.
private  LcsRowScanRel combineRowScans(LcsRowScanRel leftRowScan, LcsRowScanRel rightRowScan)
          Combines two row scans into one by taking the intersection of the inputs into each row scan.
private  RelNode createJoinReplacement(JoinRel joinRel, ProjectRel joinInput)
          Replaces the join with whatever additional filters need to be applied as a result of removing the join.
 void onMatch(RelOptRuleCall call)
          Receives notification about a rule match.
 
Methods inherited from class org.eigenbase.relopt.RelOptRule
convert, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, mergeTraitsAndConvert, mergeTraitsAndConvert, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

instance

public static final LoptRemoveSelfJoinRule instance
Constructor Detail

LoptRemoveSelfJoinRule

private LoptRemoveSelfJoinRule()
Creates a LoptRemoveSelfJoinRule.

Method Detail

onMatch

public void onMatch(RelOptRuleCall call)
Description copied from class: RelOptRule
Receives notification about a rule match. 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 RelOptRuleCall.transformTo(org.eigenbase.rel.RelNode) to register the expression.

Specified by:
onMatch in class RelOptRule
Parameters:
call - Rule call
See Also:
RelOptRule.matches(RelOptRuleCall)

combineRowScans

private LcsRowScanRel combineRowScans(LcsRowScanRel leftRowScan,
                                      LcsRowScanRel rightRowScan)
Combines two row scans into one by taking the intersection of the inputs into each row scan. It's assumed that each row scan has no more than one input.

Parameters:
leftRowScan - left row scan
rightRowScan - right row scan
Returns:
the combined row scan

combineFilters

private RelNode combineFilters(FilterRel leftFilter,
                               FilterRel rightFilter,
                               LcsRowScanRel newRowScan)
Combines filters on top of row scans into a single filter. If either filter is always true, then don't include it in the combined filter.

Parameters:
leftFilter - filter on top of the original left row scan
rightFilter - filter on top of the original right row scan
newRowScan - the new, combined row scan
Returns:
a FilterRel containing the combined filters on top of the new row scan; if both filters are always true, then the combined row scan is returned instead

combineProjects

private ProjectRel combineProjects(ProjectRel leftProject,
                                   ProjectRel rightProject,
                                   RelNode projInput)
Combines projections on top of filters that are top of row scans into a single projection. Since the row scans are identical and have not yet been projected, the original expressions in both projections will be the same in the combined projection.

Parameters:
leftProject - the left projection
rightProject - the right projection
projInput - the input into the combined projection
Returns:
the resulting combined projection

createJoinReplacement

private RelNode createJoinReplacement(JoinRel joinRel,
                                      ProjectRel joinInput)
Replaces the join with whatever additional filters need to be applied as a result of removing the join.

Parameters:
joinRel - the original join
joinInput - the new input into the join
Returns:
a FilterRel containing whatever additional filters need to be applied; if no additional filtering is required, then the new join input is returned