|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.relopt.RelOptUtil
public abstract class RelOptUtil
RelOptUtil
defines static utility methods for use in optimizing
RelNode
s.
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 field th field of an
expression. |
static FieldAccess |
makeFieldAccess(int ordinal,
int field)
Constructs a reference to the field th field of
the ordinal th input. |
static String |
makeName(int ordinal)
Constructs the name for the ordinal th 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 |
---|
private static final Variable var0
private static final Variable var1
public static final String NL
public static final double EPSILON
Constructor Detail |
---|
public RelOptUtil()
Method Detail |
---|
public static int getInputOrdinal(String name)
name
, or -1 if it does not represent an input.
public static Set<String> getVariablesSet(RelNode rel)
public static String[] getVariablesSetAndUsed(RelNode rel0, RelNode rel1)
rel0
and used by
rel1
.
public static Set<String> getVariablesUsed(RelNode rel)
RexVariable.getName()
public static RelNode[] clone(RelNode[] rels)
public static RelTraitSet clone(RelTraitSet traits)
public static RelTraitSet mergeTraits(RelTraitSet baseTraits, RelTraitSet additionalTraits)
public static void go(RelVisitor visitor, RelNode p)
RelVisitor
going on a given relational expression, and
returns the result.
public static FieldAccess makeFieldAccess(int ordinal, int field)
field
th field of
the ordinal
th input.
public static FieldAccess makeFieldAccess(Expression expr, int field)
field
th field of an
expression.
public static String makeName(int ordinal)
ordinal
th input. For example,
makeName(0)
returns "$input0".
public static Variable makeReference(int ordinal)
public static String toString(RelNode[] a)
public static List<String> getFieldNameList(RelDataType type)
type
- Struct type
getFieldTypeList(RelDataType)
,
getFieldNames(RelDataType)
public static String[] getFieldNames(RelDataType type)
type
- Struct type
getFieldNameList(RelDataType)
public static List<RelDataType> getFieldTypeList(RelDataType type)
type
- Struct type
getFieldNameList(RelDataType)
,
getFieldTypes(RelDataType)
public static RelDataType[] getFieldTypes(RelDataType type)
type
- Struct type
getFieldTypeList(RelDataType)
public static void collectFields(RelDataType type, List<String> fieldNameList, List<RelDataType> typeList)
public static RelDataType createTypeFromProjection(RelDataType type, RelDataTypeFactory typeFactory, List<String> columnNameList)
public static boolean areRowTypesEqual(RelDataType rowType1, RelDataType rowType2, boolean compareNames)
public static void verifyTypeEquivalence(RelNode originalRel, RelNode newRel, Object equivalenceClass)
originalRel
- canonical rel for equivalence classnewRel
- rel being added to equivalence classequivalenceClass
- object representing equivalence classpublic static RelNode createExistsPlan(RelOptCluster cluster, RelNode seekRel, RexNode[] conditions, RexLiteral extraExpr, String extraName)
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.
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 nullextraExpr
- Column expression to add. "TRUE" for EXISTS and INextraName
- Name of expression to add.
public static RelNode createExistsPlan(RelOptCluster cluster, RelNode seekRel, boolean isIn, boolean isExists, boolean needsOuterJoin)
public static RelNode createRenameRel(RelDataType outputType, RelNode rel)
outputType
- a row type descriptor whose field names the generated
ProjectRel must matchrel
- the rel whose output is to be renamed; rel.getRowType() must
be the same as outputType except for field names
public static RelNode createNullFilter(RelNode rel, Integer[] fieldOrdinals)
rel
- the rel to be filteredfieldOrdinals
- array of 0-based field ordinals to filter, or null
for all fields
public static RelNode createCastRel(RelNode rel, RelDataType castRowType, boolean rename)
rel
- producer of rows to be convertedcastRowType
- row type after castrename
- if true, use field names from castRowType; if false,
preserve field names from rel
public static RelNode createSingleValueAggRel(RelOptCluster cluster, RelNode rel)
rel
- underlying rel
public static RelNode createDistinctRel(RelNode rel)
rel
- underlying rel
public static boolean analyzeSimpleEquiJoin(JoinRel joinRel, int[] joinFieldOrdinals)
public static RexNode splitJoinCondition(RelNode left, RelNode right, RexNode condition, List<Integer> leftKeys, List<Integer> rightKeys)
L.A = R.X AND L.B = L.C AND (L.D = 5 OR L.E =
R.Y)
returns
left
- left input to joinright
- right input to joincondition
- join conditionleftKeys
- The ordinals of the fields from the left input which are
equi-join keysrightKeys
- The ordinals of the fields from the right input which
are equi-join keys
RexLiteral
true, but never nullpublic static RexNode splitJoinCondition(List<RelDataTypeField> sysFieldList, RelNode leftRel, RelNode rightRel, RexNode condition, List<RexNode> leftJoinKeys, List<RexNode> rightJoinKeys, List<Integer> filterNulls, List<SqlOperator> rangeOp)
sysFieldList
- list of system fieldsleftRel
- left join inputrightRel
- right join inputcondition
- join conditionleftJoinKeys
- The join keys from the left input which are equi-join
keysrightJoinKeys
- The join keys from the right input which are
equi-join keysfilterNulls
- 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
public static RexNode splitCorrelatedFilterCondition(FilterRel filterRel, List<RexInputRef> joinKeys, List<RexNode> correlatedJoinKeys)
public static RexNode splitCorrelatedFilterCondition(FilterRel filterRel, List<RexNode> joinKeys, List<RexNode> correlatedJoinKeys, boolean extractCorrelatedFieldAccess)
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)
private static void addJoinKey(List<RexNode> joinKeyList, RexNode key, boolean preserveLastElementInList)
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)
private static void splitJoinCondition(int leftFieldCount, RexNode condition, List<Integer> leftKeys, List<Integer> rightKeys, List<RexNode> nonEquiList)
public static void projectJoinInputs(RelNode[] inputRels, List<RexNode> leftJoinKeys, List<RexNode> rightJoinKeys, int systemColCount, List<Integer> leftKeys, List<Integer> rightKeys, List<Integer> outputProj)
inputRels
- inputs to a joinleftJoinKeys
- expressions for LHS of join keyrightJoinKeys
- expressions for RHS of join keysystemColCount
- 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.public static RelNode createProjectJoinRel(List<Integer> outputProj, RelNode joinRel)
outputProj
- desired projection; if null, return original join nodejoinRel
- the join node
public static void registerAbstractRels(RelOptPlanner planner)
public static String dumpPlan(String header, RelNode rel, boolean asXml, SqlExplainLevel detailLevel)
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.
public static RelDataType createDmlRowType(RelDataTypeFactory typeFactory)
typeFactory
- factory to use for creating type descriptor
public static RexNode createInputRef(RelNode rel, int i)
rel
- Relational expressioni
- Field ordinal; if negative, counts from end, so -1 means the
last fieldpublic static boolean eq(String desc1, RelDataType type1, String desc2, RelDataType type2, boolean fail)
desc1
- type1
- First typedesc2
- type2
- Second typefail
- Whether to assert if they are not equal
public static boolean equal(String desc1, RelDataType type1, String desc2, RelDataType type2, boolean fail)
areRowTypesEqual(RelDataType, RelDataType, boolean)
. Both types must
not be null.
desc1
- Description of role of first typetype1
- First typedesc2
- Description of role of second typetype2
- Second typefail
- Whether to assert if they are not equal
public static RexNode isDistinctFrom(RexBuilder rexBuilder, RexNode x, RexNode y, boolean neg)
IS DISTINCT FROM
(or IS
NOT DISTINCT FROM
) sql operator.
neg
- if false, returns a translation of IS NOT DISTINCT FROMprivate static RexNode isDistinctFromInternal(RexBuilder rexBuilder, RexNode x, RexNode y, boolean neg)
public static String toString(RelNode rel)
public static RelNode renameIfNecessary(RelNode rel, RelDataType desiredRowType)
rel
- Relational expressiondesiredRowType
- Desired row type (including desired field names)
public static String dumpType(RelDataType type)
public static void decomposeConjunction(RexNode rexPredicate, List<RexNode> rexList)
rexPredicate
- predicate to be analyzedrexList
- list of decomposed RexNodespublic static RexNode andJoinFilters(RexBuilder rexBuilder, RexNode left, RexNode right)
rexBuilder
- rexBuilder to create AND expressionleft
- filter on the left that the right will be AND'd toright
- filter on the right
public static List<Integer> adjustKeys(List<Integer> keys, int adjustment)
keys
- list of key valuesadjustment
- the amount to adjust the key values by
public static void setRexInputBitmap(BitSet bitmap, int start, int end)
bitmap
- bitmap to be setstart
- starting bit to set, corresponding to first field in the
RelNodeend
- the bit one beyond the last to be setpublic static boolean contains(BitSet x, BitSet y)
x
- containing bitmapy
- bitmap to be checked
public static boolean classifyFilters(RelNode joinRel, List<RexNode> filters, boolean pushJoin, boolean pushLeft, boolean pushRight, List<RexNode> joinFilters, List<RexNode> leftFilters, List<RexNode> rightFilters)
joinRel
- join nodefilters
- filters to be classifiedpushJoin
- true if filters originated from above the join node and
the join is an inner joinpushLeft
- true if filters can be pushed to the leftpushRight
- true if filters can be pushed to the rightjoinFilters
- list of filters to push to the joinleftFilters
- list of filters to push to the left childrightFilters
- list of filters to push to the right child
public static void splitFilters(int nChildFields, RexNode predicate, List<RexNode> pushable, List<RexNode> notPushable)
nChildFields
- number of fields in the childpredicate
- filters that will be splitpushable
- returns the list of filters that can be pushed to the
child inputnotPushable
- returns the list of filters that cannot be pushed to
the child inputpublic static RexNode[] splitJoinCondition(RelNode left, RelNode right, RexNode condition)
left
- Left input to the joinright
- Right input to the joincondition
- Join condition
public static boolean checkProjAndChildInputs(ProjectRel project, boolean checkNames)
project
- projection being examinedcheckNames
- if true, also compare that the names of the project
fields and its child fields
public static RexNode[] createSwappedJoinExprs(RelNode newJoin, JoinRel origJoin, boolean origOrder)
newJoin
- the RelNode corresponding to the join with its inputs
swappedorigJoin
- original JoinRelorigOrder
- 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
public static SetOpRel createNewSetOpRel(SetOpRel setOpRel, RelNode[] newSetOpInputs)
setOpRel
- the original SetOpRelnewSetOpInputs
- the input children
public static RexNode pushFilterPastProject(RexNode filter, ProjectRelBase projRel)
filter
- the filter to be convertedprojRel
- project rel underneath the filter
public static MultiJoinRel projectMultiJoin(MultiJoinRel multiJoin, ProjectRel project)
MultiJoinRel
to reflect projection references from
a ProjectRel
that is on top of the MultiJoinRel
.
multiJoin
- the original MultiJoinRelproject
- the ProjectRel on top of the MultiJoinRel
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |