public class RelMdUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static SqlFunction |
ARTIFICIAL_SELECTIVITY_FUNC |
| Modifier and Type | Method and Description |
|---|---|
static double |
addEpsilon(double d)
Add an epsilon to the value passed in.
|
static boolean |
areColumnsDefinitelyUnique(RelMetadataQuery mq,
RelNode rel,
ImmutableBitSet colMask)
Returns true if the columns represented in a bit mask are definitely
known to form a unique column set.
|
static boolean |
areColumnsDefinitelyUnique(RelMetadataQuery mq,
RelNode rel,
List<RexInputRef> columnRefs) |
static boolean |
areColumnsDefinitelyUniqueWhenNullsFiltered(RelMetadataQuery mq,
RelNode rel,
ImmutableBitSet colMask)
Returns true if the columns represented in a bit mask are definitely
known to form a unique column set, when nulls have been filtered from
the columns.
|
static boolean |
areColumnsDefinitelyUniqueWhenNullsFiltered(RelMetadataQuery mq,
RelNode rel,
List<RexInputRef> columnRefs) |
static Boolean |
areColumnsUnique(RelMetadataQuery mq,
RelNode rel,
List<RexInputRef> columnRefs) |
static Boolean |
areColumnsUniqueWhenNullsFiltered(RelMetadataQuery mq,
RelNode rel,
List<RexInputRef> columnRefs) |
static double |
capInfinity(Double d)
Caps a double value at Double.MAX_VALUE if it's currently infinity
|
static Double |
cardOfProjExpr(RelMetadataQuery mq,
Project rel,
RexNode expr)
Computes the cardinality of a particular expression from the projection
list.
|
static boolean |
checkInputForCollationAndLimit(RelMetadataQuery mq,
RelNode input,
RelCollation collation,
RexNode offset,
RexNode fetch)
Returns whether a relational expression is already sorted and has fewer
rows than the sum of offset and limit.
|
static boolean |
clearCache(RelNode rel)
Removes cached metadata values for specified RelNode.
|
static double |
computeSemiJoinSelectivity(RelMetadataQuery mq,
RelNode factRel,
RelNode dimRel,
Join rel)
Computes the selectivity of a semijoin filter if it is applied on a fact
table.
|
static double |
computeSemiJoinSelectivity(RelMetadataQuery mq,
RelNode factRel,
RelNode dimRel,
List<Integer> factKeyList,
List<Integer> dimKeyList)
Computes the selectivity of a semijoin filter if it is applied on a fact
table.
|
static double |
estimateFilteredRows(RelNode child,
RexNode condition,
RelMetadataQuery mq) |
static double |
estimateFilteredRows(RelNode child,
RexProgram program,
RelMetadataQuery mq) |
static Double |
getJoinDistinctRowCount(RelMetadataQuery mq,
RelNode joinRel,
JoinRelType joinType,
ImmutableBitSet groupKey,
RexNode predicate,
boolean useMaxNdv)
Computes the number of distinct rows for a set of keys returned from a
join.
|
static Double |
getJoinPopulationSize(RelMetadataQuery mq,
RelNode join_,
ImmutableBitSet groupKey)
Computes the population size for a set of keys returned from a join.
|
static Double |
getJoinRowCount(RelMetadataQuery mq,
Join join,
RexNode condition)
Returns an estimate of the number of rows returned by a
Join. |
static double |
getMinusRowCount(RelMetadataQuery mq,
Minus minus)
Returns an estimate of the number of rows returned by a
Minus. |
static double |
getSelectivityValue(RexNode artificialSelectivityFuncNode)
Returns the selectivity value stored in a call.
|
static Double |
getSemiJoinDistinctRowCount(Join semiJoinRel,
RelMetadataQuery mq,
ImmutableBitSet groupKey,
RexNode predicate)
Computes the number of distinct rows for a set of keys returned from a
semi-join.
|
static double |
getUnionAllRowCount(RelMetadataQuery mq,
Union rel)
Returns an estimate of the number of rows returned by a
Union
(before duplicates are eliminated). |
static double |
guessSelectivity(RexNode predicate)
Returns default estimates for selectivities, in the absence of stats.
|
static double |
guessSelectivity(RexNode predicate,
boolean artificialOnly)
Returns default estimates for selectivities, in the absence of stats.
|
static double |
linear(int x,
int minX,
int maxX,
double minY,
double maxY)
Returns a point on a line.
|
static RexNode |
makeSemiJoinSelectivityRexNode(RelMetadataQuery mq,
Join rel)
Creates a RexNode that stores a selectivity value corresponding to the
selectivity of a semijoin.
|
static RexNode |
minusPreds(RexBuilder rexBuilder,
RexNode pred1,
RexNode pred2)
Takes the difference between two predicates, removing from the first any
predicates also in the second.
|
static Double |
numDistinctVals(Double domainSize,
Double numSelected)
Returns the number of distinct values provided numSelected are selected
where there are domainSize distinct values.
|
static void |
setAggChildKeys(ImmutableBitSet groupKey,
Aggregate aggRel,
ImmutableBitSet.Builder childKey)
Takes a bitmap representing a set of input references and extracts the
ones that reference the group by columns in an aggregate.
|
static void |
setLeftRightBitmaps(ImmutableBitSet groupKey,
ImmutableBitSet.Builder leftMask,
ImmutableBitSet.Builder rightMask,
int nFieldsOnLeft)
Separates a bit-mask representing a join into masks representing the left
and right inputs into the join.
|
static void |
splitCols(List<RexNode> projExprs,
ImmutableBitSet groupKey,
ImmutableBitSet.Builder baseCols,
ImmutableBitSet.Builder projCols)
Forms two bitmaps by splitting the columns in a bitmap according to
whether or not the column references the child input or is an expression.
|
static RexNode |
unionPreds(RexBuilder rexBuilder,
RexNode pred1,
RexNode pred2)
AND's two predicates together, either of which may be null, removing
redundant filters.
|
static Double |
validatePercentage(Double result)
Validate the
result represents a percentage number,
e.g. the value interval is [0.0, 1.0]. |
static Double |
validateResult(Double result)
Validates the
result is valid. |
public static final SqlFunction ARTIFICIAL_SELECTIVITY_FUNC
public static RexNode makeSemiJoinSelectivityRexNode(RelMetadataQuery mq, Join rel)
rel - the semijoin of interestpublic static double getSelectivityValue(RexNode artificialSelectivityFuncNode)
artificialSelectivityFuncNode - Call containing the selectivity valuepublic static double computeSemiJoinSelectivity(RelMetadataQuery mq, RelNode factRel, RelNode dimRel, Join rel)
factRel - fact table participating in the semijoindimRel - dimension table participating in the semijoinrel - semijoin relpublic static double computeSemiJoinSelectivity(RelMetadataQuery mq, RelNode factRel, RelNode dimRel, List<Integer> factKeyList, List<Integer> dimKeyList)
factRel - fact table participating in the semijoindimRel - dimension table participating in the semijoinfactKeyList - LHS keys used in the filterdimKeyList - RHS keys used in the filterpublic static boolean areColumnsDefinitelyUnique(RelMetadataQuery mq, RelNode rel, ImmutableBitSet colMask)
rel - the relational expression that the column mask corresponds
tocolMask - bit mask containing columns that will be tested for
uniquenesspublic static Boolean areColumnsUnique(RelMetadataQuery mq, RelNode rel, List<RexInputRef> columnRefs)
public static boolean areColumnsDefinitelyUnique(RelMetadataQuery mq, RelNode rel, List<RexInputRef> columnRefs)
public static boolean areColumnsDefinitelyUniqueWhenNullsFiltered(RelMetadataQuery mq, RelNode rel, ImmutableBitSet colMask)
rel - the relational expression that the column mask corresponds
tocolMask - bit mask containing columns that will be tested for
uniquenesspublic static Boolean areColumnsUniqueWhenNullsFiltered(RelMetadataQuery mq, RelNode rel, List<RexInputRef> columnRefs)
public static boolean areColumnsDefinitelyUniqueWhenNullsFiltered(RelMetadataQuery mq, RelNode rel, List<RexInputRef> columnRefs)
public static void setLeftRightBitmaps(ImmutableBitSet groupKey, ImmutableBitSet.Builder leftMask, ImmutableBitSet.Builder rightMask, int nFieldsOnLeft)
groupKey - original bit-maskleftMask - left bit-mask to be setrightMask - right bit-mask to be setnFieldsOnLeft - number of fields in the left inputpublic static Double numDistinctVals(Double domainSize, Double numSelected)
Note that in the case where domainSize == numSelected, it's not true that the return value should be domainSize. If you pick 100 random values between 1 and 100, you'll most likely end up with fewer than 100 distinct values, because you'll pick some values more than once. The implementation is an unbiased estimation of the number of distinct values by performing a number of selections (with replacement) from a universe set.
domainSize - size of the universe set.numSelected - the number of selections.public static double capInfinity(Double d)
d - the Double objectpublic static double guessSelectivity(RexNode predicate)
predicate - predicate for which selectivity will be computed; null
means true, so gives selectity of 1.0public static double guessSelectivity(RexNode predicate, boolean artificialOnly)
predicate - predicate for which selectivity will be computed;
null means true, so gives selectity of 1.0artificialOnly - return only the selectivity contribution from
artificial nodespublic static RexNode unionPreds(RexBuilder rexBuilder, RexNode pred1, RexNode pred2)
rexBuilder - rexBuilder used to construct AND'd RexNodepred1 - first predicatepred2 - second predicatepublic static RexNode minusPreds(RexBuilder rexBuilder, RexNode pred1, RexNode pred2)
rexBuilder - rexBuilder used to construct AND'd RexNodepred1 - first predicatepred2 - second predicatepublic static void setAggChildKeys(ImmutableBitSet groupKey, Aggregate aggRel, ImmutableBitSet.Builder childKey)
groupKey - the original bitmapaggRel - the aggregatechildKey - sets bits from groupKey corresponding to group by columnspublic static void splitCols(List<RexNode> projExprs, ImmutableBitSet groupKey, ImmutableBitSet.Builder baseCols, ImmutableBitSet.Builder projCols)
projExprs - Project expressionsgroupKey - Bitmap whose columns will be splitbaseCols - Bitmap representing columns from the child inputprojCols - Bitmap representing non-child columnspublic static Double cardOfProjExpr(RelMetadataQuery mq, Project rel, RexNode expr)
rel - RelNode corresponding to the projectexpr - projection expressionpublic static Double getJoinPopulationSize(RelMetadataQuery mq, RelNode join_, ImmutableBitSet groupKey)
join_ - Join relational operatorgroupKey - Keys to compute the population forpublic static double addEpsilon(double d)
public static Double getSemiJoinDistinctRowCount(Join semiJoinRel, RelMetadataQuery mq, ImmutableBitSet groupKey, RexNode predicate)
semiJoinRel - RelNode representing the semi-joinmq - metadata querygroupKey - keys that the distinct row count will be computed forpredicate - join predicatepublic static Double getJoinDistinctRowCount(RelMetadataQuery mq, RelNode joinRel, JoinRelType joinType, ImmutableBitSet groupKey, RexNode predicate, boolean useMaxNdv)
joinRel - RelNode representing the joinjoinType - type of joingroupKey - keys that the distinct row count will be computed forpredicate - join predicateuseMaxNdv - If true use formula max(left NDV, right NDV),
otherwise use left NDV * right NDV.public static double getUnionAllRowCount(RelMetadataQuery mq, Union rel)
Union
(before duplicates are eliminated).public static double getMinusRowCount(RelMetadataQuery mq, Minus minus)
Minus.public static Double getJoinRowCount(RelMetadataQuery mq, Join join, RexNode condition)
Join.public static double estimateFilteredRows(RelNode child, RexProgram program, RelMetadataQuery mq)
public static double estimateFilteredRows(RelNode child, RexNode condition, RelMetadataQuery mq)
public static double linear(int x,
int minX,
int maxX,
double minY,
double maxY)
The result is always a value between minY and maxY,
even if x is not between minX and maxX.
Examples:
linear(0, 0, 10, 100, 200} returns 100 because 0 is minX
linear(5, 0, 10, 100, 200} returns 150 because 5 is
mid-way between minX and maxX
linear(5, 0, 10, 100, 200} returns 160
linear(10, 0, 10, 100, 200} returns 200 because 10 is maxX
linear(-2, 0, 10, 100, 200} returns 100 because -2 is
less than minX and is therefore treated as minX
linear(12, 0, 10, 100, 200} returns 100 because 12 is
greater than maxX and is therefore treated as maxX
public static boolean checkInputForCollationAndLimit(RelMetadataQuery mq, RelNode input, RelCollation collation, RexNode offset, RexNode fetch)
If this is the case, it is safe to push down a
Sort with limit and optional offset.
public static Double validatePercentage(Double result)
result represents a percentage number,
e.g. the value interval is [0.0, 1.0].result is a percentage numberAssertionError - if the validation failspublic static Double validateResult(Double result)
result is valid.
Never let the result go below 1, as it will result in incorrect calculations if the row-count is used as the denominator in a division expression. Also, cap the value at the max double value to avoid calculations using infinity.
resultAssertionError - if the result is negativepublic static boolean clearCache(RelNode rel)
rel - RelNode whose cached metadata should be removedCopyright © 2012-2020 Apache Software Foundation. All Rights Reserved.