org.eigenbase.relopt
Class RelOptUtil

java.lang.Object
  extended by org.eigenbase.relopt.RelOptUtil

public abstract class RelOptUtil
extends Object

RelOptUtil defines static utility methods for use in optimizing RelNodes.

Since:
26 September, 2003
Version:
$Id: //open/dev/farrago/src/org/eigenbase/relopt/RelOptUtil.java#75 $
Author:
jhyde

Nested Class Summary
static class RelOptUtil.InputFinder
          Visitor which builds a bitmap of the inputs used by an expression.
static class RelOptUtil.InputReferencedVisitor
           
static class RelOptUtil.RexInputConverter
          Walks an expression tree, converting the index of RexInputRefs based on some adjustment factor.
static class RelOptUtil.TypeDumper
           
private static class RelOptUtil.VariableSetVisitor
           
static class RelOptUtil.VariableUsedVisitor
           
 
Field Summary
static double EPSILON
           
static String NL
           
private static Variable var0
           
private static Variable var1
           
 
Constructor Summary
RelOptUtil()
           
 
Method Summary
private static void addJoinKey(List<RexNode> joinKeyList, RexNode key, boolean preserveLastElementInList)
           
static List<Integer> adjustKeys(List<Integer> keys, int adjustment)
          Adjusts key values in a list by some fixed amount.
static boolean analyzeSimpleEquiJoin(JoinRel joinRel, int[] joinFieldOrdinals)
           
static RexNode andJoinFilters(RexBuilder rexBuilder, RexNode left, RexNode right)
          Ands two sets of join filters together, either of which can be null.
static boolean areRowTypesEqual(RelDataType rowType1, RelDataType rowType2, boolean compareNames)
           
static boolean checkProjAndChildInputs(ProjectRel project, boolean checkNames)
          Determines if a projection and its input reference identical input references.
static boolean classifyFilters(RelNode joinRel, List<RexNode> filters, boolean pushJoin, boolean pushLeft, boolean pushRight, List<RexNode> joinFilters, List<RexNode> leftFilters, List<RexNode> rightFilters)
          Classifies filters according to where they should be processed.
static RelNode[] clone(RelNode[] rels)
           
static RelTraitSet clone(RelTraitSet traits)
           
static void collectFields(RelDataType type, List<String> fieldNameList, List<RelDataType> typeList)
          Collects the names and types of the fields in a given struct type.
static boolean contains(BitSet x, BitSet y)
          Returns true if all bits set in the second parameter are also set in the first
static RelNode createCastRel(RelNode rel, RelDataType castRowType, boolean rename)
          Creates a projection which casts a rel's output to a desired row type.
static RelNode createDistinctRel(RelNode rel)
          Creates an AggregateRel which removes all duplicates from the result of an underlying rel.
static RelDataType createDmlRowType(RelDataTypeFactory typeFactory)
          Creates the row type descriptor for the result of a DML operation, which is a single column named ROWCOUNT of type BIGINT.
static RelNode createExistsPlan(RelOptCluster cluster, RelNode seekRel, boolean isIn, boolean isExists, boolean needsOuterJoin)
           
static RelNode createExistsPlan(RelOptCluster cluster, RelNode seekRel, RexNode[] conditions, RexLiteral extraExpr, String extraName)
          Creates a plan suitable for use in EXISTS or IN statements.
static RexNode createInputRef(RelNode rel, int i)
          Creates a reference to an output field of a relational expression.
static SetOpRel createNewSetOpRel(SetOpRel setOpRel, RelNode[] newSetOpInputs)
          Creates a new SetOpRel corresponding to an original SetOpRel with a new set of input children
static RelNode createNullFilter(RelNode rel, Integer[] fieldOrdinals)
          Creates a filter which will remove rows containing NULL values.
static RelNode createProjectJoinRel(List<Integer> outputProj, RelNode joinRel)
          Creates a projection on top of a join, if the desired projection is a subset of the join columns
static RelNode createRenameRel(RelDataType outputType, RelNode rel)
          Creates a ProjectRel which accomplishes a rename.
static RelNode createSingleValueAggRel(RelOptCluster cluster, RelNode rel)
          Creates an AggregateRel which removes all duplicates from the result of an underlying rel.
static RexNode[] createSwappedJoinExprs(RelNode newJoin, JoinRel origJoin, boolean origOrder)
          Creates projection expressions reflecting the swapping of a join's input.
static RelDataType createTypeFromProjection(RelDataType type, RelDataTypeFactory typeFactory, List<String> columnNameList)
           
static void decomposeConjunction(RexNode rexPredicate, List<RexNode> rexList)
          Decompose a rex predicate into list of RexNodes that are AND'ed together
static String dumpPlan(String header, RelNode rel, boolean asXml, SqlExplainLevel detailLevel)
          Dumps a plan as a string.
static String dumpType(RelDataType type)
           
static boolean eq(String desc1, RelDataType type1, String desc2, RelDataType type2, boolean fail)
          Returns whether two types are equal using '='.
static boolean equal(String desc1, RelDataType type1, String desc2, RelDataType type2, boolean fail)
          Returns whether two types are equal using areRowTypesEqual(RelDataType, RelDataType, boolean).
static List<String> getFieldNameList(RelDataType type)
          Returns a list of the names of the fields in a given struct type.
static String[] getFieldNames(RelDataType type)
          Returns an array of the names of the fields in a given struct type.
static List<RelDataType> getFieldTypeList(RelDataType type)
          Returns a list of the types of the fields in a given struct type.
static RelDataType[] getFieldTypes(RelDataType type)
          Returns an array of the types of the fields in a given struct type.
static int getInputOrdinal(String name)
          Returns the ordinal of the input represented by the variable name, or -1 if it does not represent an input.
static Set<String> getVariablesSet(RelNode rel)
          Returns a list of variables set by a relational expression or its descendants.
static String[] getVariablesSetAndUsed(RelNode rel0, RelNode rel1)
          Returns a set of distinct variables set by rel0 and used by rel1.
static Set<String> getVariablesUsed(RelNode rel)
          Returns a set of variables used by a relational expression or its descendants.
static void go(RelVisitor visitor, RelNode p)
          Sets a RelVisitor going on a given relational expression, and returns the result.
static RexNode isDistinctFrom(RexBuilder rexBuilder, RexNode x, RexNode y, boolean neg)
          Returns a translation of the IS DISTINCT FROM (or IS NOT DISTINCT FROM) sql operator.
private static RexNode isDistinctFromInternal(RexBuilder rexBuilder, RexNode x, RexNode y, boolean neg)
           
static FieldAccess makeFieldAccess(Expression expr, int field)
          Constructs a reference to the fieldth field of an expression.
static FieldAccess makeFieldAccess(int ordinal, int field)
          Constructs a reference to the fieldth field of the ordinalth input.
static String makeName(int ordinal)
          Constructs the name for the ordinalth input.
static Variable makeReference(int ordinal)
           
static RelTraitSet mergeTraits(RelTraitSet baseTraits, RelTraitSet additionalTraits)
           
static void projectJoinInputs(RelNode[] inputRels, List<RexNode> leftJoinKeys, List<RexNode> rightJoinKeys, int systemColCount, List<Integer> leftKeys, List<Integer> rightKeys, List<Integer> outputProj)
          Adding projection to the inputs of a join to produce the required join keys.
static MultiJoinRel projectMultiJoin(MultiJoinRel multiJoin, ProjectRel project)
          Creates a new MultiJoinRel to reflect projection references from a ProjectRel that is on top of the MultiJoinRel.
static RexNode pushFilterPastProject(RexNode filter, ProjectRelBase projRel)
          Converts a filter to the new filter that would result if the filter is pushed past a ProjectRel that it currently is referencing.
static void registerAbstractRels(RelOptPlanner planner)
           
static RelNode renameIfNecessary(RelNode rel, RelDataType desiredRowType)
          Renames a relational expression to make its field names the same as another row type.
static void setRexInputBitmap(BitSet bitmap, int start, int end)
          Sets a bit in a bitmap for each RexInputRef in a RelNode
static RexNode splitCorrelatedFilterCondition(FilterRel filterRel, List<RexInputRef> joinKeys, List<RexNode> correlatedJoinKeys)
           
static RexNode splitCorrelatedFilterCondition(FilterRel filterRel, List<RexNode> joinKeys, List<RexNode> correlatedJoinKeys, boolean extractCorrelatedFieldAccess)
           
private static void splitCorrelatedFilterCondition(FilterRel filterRel, RexNode condition, List<RexInputRef> joinKeys, List<RexNode> correlatedJoinKeys, List<RexNode> nonEquiList)
           
private static void splitCorrelatedFilterCondition(FilterRel filterRel, RexNode condition, List<RexNode> joinKeys, List<RexNode> correlatedJoinKeys, List<RexNode> nonEquiList, boolean extractCorrelatedFieldAccess)
           
static void splitFilters(int nChildFields, RexNode predicate, List<RexNode> pushable, List<RexNode> notPushable)
          Splits a filter into two lists, depending on whether or not the filter only references its child input
private static void splitJoinCondition(int leftFieldCount, RexNode condition, List<Integer> leftKeys, List<Integer> rightKeys, List<RexNode> nonEquiList)
           
static RexNode splitJoinCondition(List<RelDataTypeField> sysFieldList, RelNode leftRel, RelNode rightRel, RexNode condition, List<RexNode> leftJoinKeys, List<RexNode> rightJoinKeys, List<Integer> filterNulls, List<SqlOperator> rangeOp)
          Splits out the equi-join (and optionally, a single non-equi) components of a join condition, and returns what's left.
private static void splitJoinCondition(List<RelDataTypeField> sysFieldList, RelNode leftRel, RelNode rightRel, RexNode condition, List<RexNode> leftJoinKeys, List<RexNode> rightJoinKeys, List<Integer> filterNulls, List<SqlOperator> rangeOp, List<RexNode> nonEquiList)
           
static RexNode[] splitJoinCondition(RelNode left, RelNode right, RexNode condition)
          Splits a join condition.
static RexNode splitJoinCondition(RelNode left, RelNode right, RexNode condition, List<Integer> leftKeys, List<Integer> rightKeys)
          Splits out the equi-join components of a join condition, and returns what's left.
static String toString(RelNode rel)
          Converts a relational expression to a string.
static String toString(RelNode[] a)
           
static void verifyTypeEquivalence(RelNode originalRel, RelNode newRel, Object equivalenceClass)
          Verifies that a row type being added to an equivalence class matches the existing type, raising an assertion if this is not the case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

var0

private static final Variable var0

var1

private static final Variable var1

NL

public static final String NL

EPSILON

public static final double EPSILON
See Also:
Constant Field Values
Constructor Detail

RelOptUtil

public RelOptUtil()
Method Detail

getInputOrdinal

public static int getInputOrdinal(String name)
Returns the ordinal of the input represented by the variable name, or -1 if it does not represent an input.


getVariablesSet

public static Set<String> getVariablesSet(RelNode rel)
Returns a list of variables set by a relational expression or its descendants.


getVariablesSetAndUsed

public static String[] getVariablesSetAndUsed(RelNode rel0,
                                              RelNode rel1)
Returns a set of distinct variables set by rel0 and used by rel1.


getVariablesUsed

public static Set<String> getVariablesUsed(RelNode rel)
Returns a set of variables used by a relational expression or its descendants. The set may contain duplicates. The item type is the same as RexVariable.getName()


clone

public static RelNode[] clone(RelNode[] rels)

clone

public static RelTraitSet clone(RelTraitSet traits)

mergeTraits

public static RelTraitSet mergeTraits(RelTraitSet baseTraits,
                                      RelTraitSet additionalTraits)

go

public static void go(RelVisitor visitor,
                      RelNode p)
Sets a RelVisitor going on a given relational expression, and returns the result.


makeFieldAccess

public static FieldAccess makeFieldAccess(int ordinal,
                                          int field)
Constructs a reference to the fieldth field of the ordinalth input.


makeFieldAccess

public static FieldAccess makeFieldAccess(Expression expr,
                                          int field)
Constructs a reference to the fieldth field of an expression.


makeName

public static String makeName(int ordinal)
Constructs the name for the ordinalth input. For example, makeName(0) returns "$input0".


makeReference

public static Variable makeReference(int ordinal)

toString

public static String toString(RelNode[] a)

getFieldNameList

public static List<String> getFieldNameList(RelDataType type)
Returns a list of the names of the fields in a given struct type.

Parameters:
type - Struct type
Returns:
List of field names
See Also:
getFieldTypeList(RelDataType), getFieldNames(RelDataType)

getFieldNames

public static String[] getFieldNames(RelDataType type)
Returns an array of the names of the fields in a given struct type.

Parameters:
type - Struct type
Returns:
Array of field names
See Also:
getFieldNameList(RelDataType)

getFieldTypeList

public static List<RelDataType> getFieldTypeList(RelDataType type)
Returns a list of the types of the fields in a given struct type.

Parameters:
type - Struct type
Returns:
List of field types
See Also:
getFieldNameList(RelDataType), getFieldTypes(RelDataType)

getFieldTypes

public static RelDataType[] getFieldTypes(RelDataType type)
Returns an array of the types of the fields in a given struct type.

Parameters:
type - Struct type
Returns:
Array of field types
See Also:
getFieldTypeList(RelDataType)

collectFields

public static void collectFields(RelDataType type,
                                 List<String> fieldNameList,
                                 List<RelDataType> typeList)
Collects the names and types of the fields in a given struct type.


createTypeFromProjection

public static RelDataType createTypeFromProjection(RelDataType type,
                                                   RelDataTypeFactory typeFactory,
                                                   List<String> columnNameList)

areRowTypesEqual

public static boolean areRowTypesEqual(RelDataType rowType1,
                                       RelDataType rowType2,
                                       boolean compareNames)

verifyTypeEquivalence

public static void verifyTypeEquivalence(RelNode originalRel,
                                         RelNode newRel,
                                         Object equivalenceClass)
Verifies that a row type being added to an equivalence class matches the existing type, raising an assertion if this is not the case.

Parameters:
originalRel - canonical rel for equivalence class
newRel - rel being added to equivalence class
equivalenceClass - object representing equivalence class

createExistsPlan

public static RelNode createExistsPlan(RelOptCluster cluster,
                                       RelNode seekRel,
                                       RexNode[] conditions,
                                       RexLiteral extraExpr,
                                       String extraName)
Creates a plan suitable for use in EXISTS or IN statements. See SqlToRelConverter.convertExists(org.eigenbase.sql.SqlNode, boolean, boolean, boolean) Note: this implementation of createExistsPlan is only called from net.sf.farrago.fennel.rel. The last two arguments do not apply to those invocations and can be removed from the method.

Parameters:
cluster -
seekRel - A query rel, for example the resulting rel from 'select * from emp' or 'values (1,2,3)' or '('Foo', 34)'.
conditions - May be null
extraExpr - Column expression to add. "TRUE" for EXISTS and IN
extraName - Name of expression to add.
Returns:
relational expression which outer joins a boolean condition column
"Precondition:"
extraExpr == null || extraName != null

createExistsPlan

public static RelNode createExistsPlan(RelOptCluster cluster,
                                       RelNode seekRel,
                                       boolean isIn,
                                       boolean isExists,
                                       boolean needsOuterJoin)

createRenameRel

public static RelNode createRenameRel(RelDataType outputType,
                                      RelNode rel)
Creates a ProjectRel which accomplishes a rename.

Parameters:
outputType - a row type descriptor whose field names the generated ProjectRel must match
rel - the rel whose output is to be renamed; rel.getRowType() must be the same as outputType except for field names
Returns:
generated relational expression

createNullFilter

public static RelNode createNullFilter(RelNode rel,
                                       Integer[] fieldOrdinals)
Creates a filter which will remove rows containing NULL values.

Parameters:
rel - the rel to be filtered
fieldOrdinals - array of 0-based field ordinals to filter, or null for all fields
Returns:
filtered rel

createCastRel

public static RelNode createCastRel(RelNode rel,
                                    RelDataType castRowType,
                                    boolean rename)
Creates a projection which casts a rel's output to a desired row type.

Parameters:
rel - producer of rows to be converted
castRowType - row type after cast
rename - if true, use field names from castRowType; if false, preserve field names from rel
Returns:
conversion rel

createSingleValueAggRel

public static RelNode createSingleValueAggRel(RelOptCluster cluster,
                                              RelNode rel)
Creates an AggregateRel which removes all duplicates from the result of an underlying rel.

Parameters:
rel - underlying rel
Returns:
rel implementing SingleValueAgg

createDistinctRel

public static RelNode createDistinctRel(RelNode rel)
Creates an AggregateRel which removes all duplicates from the result of an underlying rel.

Parameters:
rel - underlying rel
Returns:
rel implementing DISTINCT

analyzeSimpleEquiJoin

public static boolean analyzeSimpleEquiJoin(JoinRel joinRel,
                                            int[] joinFieldOrdinals)

splitJoinCondition

public static RexNode splitJoinCondition(RelNode left,
                                         RelNode right,
                                         RexNode condition,
                                         List<Integer> leftKeys,
                                         List<Integer> rightKeys)
Splits out the equi-join components of a join condition, and returns what's left. For example, given the condition
L.A = R.X AND L.B = L.C AND (L.D = 5 OR L.E = R.Y)
returns

Parameters:
left - left input to join
right - right input to join
condition - join condition
leftKeys - The ordinals of the fields from the left input which are equi-join keys
rightKeys - The ordinals of the fields from the right input which are equi-join keys
Returns:
remaining join filters that are not equijoins; may return a RexLiteral true, but never null

splitJoinCondition

public static RexNode splitJoinCondition(List<RelDataTypeField> sysFieldList,
                                         RelNode leftRel,
                                         RelNode rightRel,
                                         RexNode condition,
                                         List<RexNode> leftJoinKeys,
                                         List<RexNode> rightJoinKeys,
                                         List<Integer> filterNulls,
                                         List<SqlOperator> rangeOp)
Splits out the equi-join (and optionally, a single non-equi) components of a join condition, and returns what's left. Projection might be required by the caller to provide join keys that are not direct field references.

Parameters:
sysFieldList - list of system fields
leftRel - left join input
rightRel - right join input
condition - join condition
leftJoinKeys - The join keys from the left input which are equi-join keys
rightJoinKeys - The join keys from the right input which are equi-join keys
filterNulls - The join key positions for which null values will not match. null values only match for the "is not distinct from" condition.
rangeOp - if null, only locate equi-joins; otherwise, locate a single non-equi join predicate and return its operator in this list; join keys associated with the non-equi join predicate are at the end of the key lists returned
Returns:
What's left

splitCorrelatedFilterCondition

public static RexNode splitCorrelatedFilterCondition(FilterRel filterRel,
                                                     List<RexInputRef> joinKeys,
                                                     List<RexNode> correlatedJoinKeys)

splitCorrelatedFilterCondition

public static RexNode splitCorrelatedFilterCondition(FilterRel filterRel,
                                                     List<RexNode> joinKeys,
                                                     List<RexNode> correlatedJoinKeys,
                                                     boolean extractCorrelatedFieldAccess)

splitJoinCondition

private static void splitJoinCondition(List<RelDataTypeField> sysFieldList,
                                       RelNode leftRel,
                                       RelNode rightRel,
                                       RexNode condition,
                                       List<RexNode> leftJoinKeys,
                                       List<RexNode> rightJoinKeys,
                                       List<Integer> filterNulls,
                                       List<SqlOperator> rangeOp,
                                       List<RexNode> nonEquiList)

addJoinKey

private static void addJoinKey(List<RexNode> joinKeyList,
                               RexNode key,
                               boolean preserveLastElementInList)

splitCorrelatedFilterCondition

private static void splitCorrelatedFilterCondition(FilterRel filterRel,
                                                   RexNode condition,
                                                   List<RexInputRef> joinKeys,
                                                   List<RexNode> correlatedJoinKeys,
                                                   List<RexNode> nonEquiList)

splitCorrelatedFilterCondition

private static void splitCorrelatedFilterCondition(FilterRel filterRel,
                                                   RexNode condition,
                                                   List<RexNode> joinKeys,
                                                   List<RexNode> correlatedJoinKeys,
                                                   List<RexNode> nonEquiList,
                                                   boolean extractCorrelatedFieldAccess)

splitJoinCondition

private static void splitJoinCondition(int leftFieldCount,
                                       RexNode condition,
                                       List<Integer> leftKeys,
                                       List<Integer> rightKeys,
                                       List<RexNode> nonEquiList)

projectJoinInputs

public static void projectJoinInputs(RelNode[] inputRels,
                                     List<RexNode> leftJoinKeys,
                                     List<RexNode> rightJoinKeys,
                                     int systemColCount,
                                     List<Integer> leftKeys,
                                     List<Integer> rightKeys,
                                     List<Integer> outputProj)
Adding projection to the inputs of a join to produce the required join keys.

Parameters:
inputRels - inputs to a join
leftJoinKeys - expressions for LHS of join key
rightJoinKeys - expressions for RHS of join key
systemColCount - number of system columns, usually zero. These columns are projected at the leading edge of the output row.
leftKeys - on return this contains the join key positions from the new project rel on the LHS.
rightKeys - on return this contains the join key positions from the new project rel on the RHS.
outputProj - on return this contains the positions of the original join output in the (to be formed by caller) LhxJoinRel. Caller needs to be responsible for adding projection on the new join output.

createProjectJoinRel

public static RelNode createProjectJoinRel(List<Integer> outputProj,
                                           RelNode joinRel)
Creates a projection on top of a join, if the desired projection is a subset of the join columns

Parameters:
outputProj - desired projection; if null, return original join node
joinRel - the join node
Returns:
projected join node or the original join if projection is unnecessary

registerAbstractRels

public static void registerAbstractRels(RelOptPlanner planner)

dumpPlan

public static String dumpPlan(String header,
                              RelNode rel,
                              boolean asXml,
                              SqlExplainLevel detailLevel)
Dumps a plan as a string.

Parameters:
header - Header to print before the plan. Ignored if the format is XML.
rel - Relational expression to explain.
asXml - Whether to format as XML.
detailLevel - Detail level.
Returns:
Plan

createDmlRowType

public static RelDataType createDmlRowType(RelDataTypeFactory typeFactory)
Creates the row type descriptor for the result of a DML operation, which is a single column named ROWCOUNT of type BIGINT.

Parameters:
typeFactory - factory to use for creating type descriptor
Returns:
created type

createInputRef

public static RexNode createInputRef(RelNode rel,
                                     int i)
Creates a reference to an output field of a relational expression.

Parameters:
rel - Relational expression
i - Field ordinal; if negative, counts from end, so -1 means the last field

eq

public static boolean eq(String desc1,
                         RelDataType type1,
                         String desc2,
                         RelDataType type2,
                         boolean fail)
Returns whether two types are equal using '='.

Parameters:
desc1 -
type1 - First type
desc2 -
type2 - Second type
fail - Whether to assert if they are not equal
Returns:
Whether the types are equal

equal

public static boolean equal(String desc1,
                            RelDataType type1,
                            String desc2,
                            RelDataType type2,
                            boolean fail)
Returns whether two types are equal using areRowTypesEqual(RelDataType, RelDataType, boolean). Both types must not be null.

Parameters:
desc1 - Description of role of first type
type1 - First type
desc2 - Description of role of second type
type2 - Second type
fail - Whether to assert if they are not equal
Returns:
Whether the types are equal

isDistinctFrom

public static RexNode isDistinctFrom(RexBuilder rexBuilder,
                                     RexNode x,
                                     RexNode y,
                                     boolean neg)
Returns a translation of the IS DISTINCT FROM (or IS NOT DISTINCT FROM) sql operator.

Parameters:
neg - if false, returns a translation of IS NOT DISTINCT FROM

isDistinctFromInternal

private static RexNode isDistinctFromInternal(RexBuilder rexBuilder,
                                              RexNode x,
                                              RexNode y,
                                              boolean neg)

toString

public static String toString(RelNode rel)
Converts a relational expression to a string.


renameIfNecessary

public static RelNode renameIfNecessary(RelNode rel,
                                        RelDataType desiredRowType)
Renames a relational expression to make its field names the same as another row type. If the row type is already identical, or if the row type is too different (the fields are different in number or type) does nothing.

Parameters:
rel - Relational expression
desiredRowType - Desired row type (including desired field names)
Returns:
Renamed relational expression, or the original expression if there is nothing to do or nothing we can do.

dumpType

public static String dumpType(RelDataType type)

decomposeConjunction

public static void decomposeConjunction(RexNode rexPredicate,
                                        List<RexNode> rexList)
Decompose a rex predicate into list of RexNodes that are AND'ed together

Parameters:
rexPredicate - predicate to be analyzed
rexList - list of decomposed RexNodes

andJoinFilters

public static RexNode andJoinFilters(RexBuilder rexBuilder,
                                     RexNode left,
                                     RexNode right)
Ands two sets of join filters together, either of which can be null.

Parameters:
rexBuilder - rexBuilder to create AND expression
left - filter on the left that the right will be AND'd to
right - filter on the right
Returns:
AND'd filter

adjustKeys

public static List<Integer> adjustKeys(List<Integer> keys,
                                       int adjustment)
Adjusts key values in a list by some fixed amount.

Parameters:
keys - list of key values
adjustment - the amount to adjust the key values by
Returns:
modified list

setRexInputBitmap

public static void setRexInputBitmap(BitSet bitmap,
                                     int start,
                                     int end)
Sets a bit in a bitmap for each RexInputRef in a RelNode

Parameters:
bitmap - bitmap to be set
start - starting bit to set, corresponding to first field in the RelNode
end - the bit one beyond the last to be set

contains

public static boolean contains(BitSet x,
                               BitSet y)
Returns true if all bits set in the second parameter are also set in the first

Parameters:
x - containing bitmap
y - bitmap to be checked
Returns:
true if all bits in the second parameter are set in the first

classifyFilters

public static boolean classifyFilters(RelNode joinRel,
                                      List<RexNode> filters,
                                      boolean pushJoin,
                                      boolean pushLeft,
                                      boolean pushRight,
                                      List<RexNode> joinFilters,
                                      List<RexNode> leftFilters,
                                      List<RexNode> rightFilters)
Classifies filters according to where they should be processed. They either stay where they are, are pushed to the join (if they originated from above the join), or are pushed to one of the children. Filters that are pushed are added to list passed in as input parameters.

Parameters:
joinRel - join node
filters - filters to be classified
pushJoin - true if filters originated from above the join node and the join is an inner join
pushLeft - true if filters can be pushed to the left
pushRight - true if filters can be pushed to the right
joinFilters - list of filters to push to the join
leftFilters - list of filters to push to the left child
rightFilters - list of filters to push to the right child
Returns:
true if at least one filter was pushed

splitFilters

public static void splitFilters(int nChildFields,
                                RexNode predicate,
                                List<RexNode> pushable,
                                List<RexNode> notPushable)
Splits a filter into two lists, depending on whether or not the filter only references its child input

Parameters:
nChildFields - number of fields in the child
predicate - filters that will be split
pushable - returns the list of filters that can be pushed to the child input
notPushable - returns the list of filters that cannot be pushed to the child input

splitJoinCondition

public static RexNode[] splitJoinCondition(RelNode left,
                                           RelNode right,
                                           RexNode condition)
Splits a join condition.

Parameters:
left - Left input to the join
right - Right input to the join
condition - Join condition
Returns:
Array holding the output; neither element is null. Element 0 is the equi-join condition (or TRUE if empty); Element 1 is rest of the condition (or TRUE if empty).

checkProjAndChildInputs

public static boolean checkProjAndChildInputs(ProjectRel project,
                                              boolean checkNames)
Determines if a projection and its input reference identical input references.

Parameters:
project - projection being examined
checkNames - if true, also compare that the names of the project fields and its child fields
Returns:
if checkNames is false, true is returned if the project and its child reference the same input references, regardless of the names of the project and child fields; if checkNames is true, then true is returned if the input references are the same but the field names are different

createSwappedJoinExprs

public static RexNode[] createSwappedJoinExprs(RelNode newJoin,
                                               JoinRel origJoin,
                                               boolean origOrder)
Creates projection expressions reflecting the swapping of a join's input.

Parameters:
newJoin - the RelNode corresponding to the join with its inputs swapped
origJoin - original JoinRel
origOrder - if true, create the projection expressions to reflect the original (pre-swapped) join projection; otherwise, create the projection to reflect the order of the swapped projection
Returns:
array of expression representing the swapped join inputs

createNewSetOpRel

public static SetOpRel createNewSetOpRel(SetOpRel setOpRel,
                                         RelNode[] newSetOpInputs)
Creates a new SetOpRel corresponding to an original SetOpRel with a new set of input children

Parameters:
setOpRel - the original SetOpRel
newSetOpInputs - the input children
Returns:
new SetOpRel

pushFilterPastProject

public static RexNode pushFilterPastProject(RexNode filter,
                                            ProjectRelBase projRel)
Converts a filter to the new filter that would result if the filter is pushed past a ProjectRel that it currently is referencing.

Parameters:
filter - the filter to be converted
projRel - project rel underneath the filter
Returns:
converted filter

projectMultiJoin

public static MultiJoinRel projectMultiJoin(MultiJoinRel multiJoin,
                                            ProjectRel project)
Creates a new MultiJoinRel to reflect projection references from a ProjectRel that is on top of the MultiJoinRel.

Parameters:
multiJoin - the original MultiJoinRel
project - the ProjectRel on top of the MultiJoinRel
Returns:
the new MultiJoinRel