com.lucidera.lcs
Class LcsIndexSemiJoinRule

java.lang.Object
  extended by org.eigenbase.relopt.RelOptRule
      extended by com.lucidera.lcs.LcsIndexSemiJoinRule

public class LcsIndexSemiJoinRule
extends RelOptRule

LcsIndexSemiJoinRule implements the rule for converting a semijoin expression into the actual operations used to execute the semijoin. Specfically,

 SemiJoinRel(LcsRowScanRel, D) ->
     LcsRowScanRel(
         LcsIndexMergeRel(
             LcsIndexSearchRel(
                 LcsFennelSortRel(
                     AggregateRel(
                         ProjectRel(D))))))
 

Note that this rule assumes that no projections have been pushed into the LcsRowScanRels.

Version:
$Id: //open/dev/farrago/src/com/lucidera/lcs/LcsIndexSemiJoinRule.java#26 $
Author:
Zelaine Fong

Field Summary
 
Fields inherited from class org.eigenbase.relopt.RelOptRule
ANY, description, operands
 
Constructor Summary
LcsIndexSemiJoinRule(RelOptRuleOperand operand, String id)
          Creates an LcsIndexSemiJoinRule.
 
Method Summary
private static RelNode[] addNewIndexAccessRel(RelOptRuleCall call, int rowScanRelPosInCall, FennelSortRel sort, FemLocalIndex index, Double indexSelectivity)
           
private  RexNode[] castJoinKeys(List<Integer> leftKeys, RelDataTypeField[] leftFields, int nKeys, List<Integer> keyOrder, RexBuilder rexBuilder, RexNode[] rhsExps, FarragoTypeFactory typeFactory)
          Casts the types of the join keys from the right hand side of the join to the types of the left hand side
 void onMatch(RelOptRuleCall call)
          Receives notification about a rule match.
private  void transformSemiJoin(SemiJoinRel semiJoin, LcsRowScanRel origRowScan, FemLocalIndex index, List<Integer> keyOrder, RelNode rightRel, RelOptRuleCall call)
          Converts the semijoin expression once a valid index has been found
 
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
 

Constructor Detail

LcsIndexSemiJoinRule

public LcsIndexSemiJoinRule(RelOptRuleOperand operand,
                            String id)
Creates an LcsIndexSemiJoinRule.

Parameters:
operand - Root operand, must not be null
id - Description of rule
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)

transformSemiJoin

private void transformSemiJoin(SemiJoinRel semiJoin,
                               LcsRowScanRel origRowScan,
                               FemLocalIndex index,
                               List<Integer> keyOrder,
                               RelNode rightRel,
                               RelOptRuleCall call)
Converts the semijoin expression once a valid index has been found

Parameters:
semiJoin - the semijoin expression to be converted
origRowScan - original row scan on the left hand side of the semijoin
index - index to be used to scan the left hand side of the semijoin
keyOrder - positions of the keys that match the index, in the order of match
rightRel - right hand side of the semijoin
call - rule call

castJoinKeys

private RexNode[] castJoinKeys(List<Integer> leftKeys,
                               RelDataTypeField[] leftFields,
                               int nKeys,
                               List<Integer> keyOrder,
                               RexBuilder rexBuilder,
                               RexNode[] rhsExps,
                               FarragoTypeFactory typeFactory)
Casts the types of the join keys from the right hand side of the join to the types of the left hand side

Parameters:
leftKeys - left hand side join keys
leftFields - fields corresponding to the left hand side of the join
nKeys - number of keys to be cast
keyOrder - positions of the keys that match the index, in the order of match
rexBuilder - rex builder from right hand side of join
rhsExps - right hand side expressions that need to be cast
typeFactory - type factory
Returns:
cast expression

addNewIndexAccessRel

private static RelNode[] addNewIndexAccessRel(RelOptRuleCall call,
                                              int rowScanRelPosInCall,
                                              FennelSortRel sort,
                                              FemLocalIndex index,
                                              Double indexSelectivity)
Parameters:
call - call this rule is matched against
rowScanRelPosInCall - the position(start from 0) of the LcsRowScanRel in the sequence of rels matched by this rule
sort - input to the index search rel to be created
index - the index to use in the index search rel
indexSelectivity - selectivity of the index being added
Returns:
the new input rels, after adding the new index search rel, to the row scan rel.