double residualSelectivity = RelMdUtil.guessSelectivity(constraintBasedResult.right); double rowCount; if (constraintBasedResult.left.isPKSideSimple) {
if (!RelMdUtil.areColumnsDefinitelyUniqueWhenNullsFiltered(mq, left, correlatedInputRefJoinKeys)) { if (!RelMdUtil.areColumnsDefinitelyUnique(mq, left, allCols)) {
@Override public Double getDistinctRowCount(Join rel, RelMetadataQuery mq, ImmutableBitSet groupKey, RexNode predicate) { if (rel instanceof HiveJoin) { HiveJoin hjRel = (HiveJoin) rel; //TODO: Improve this if (rel instanceof SemiJoin) { return mq.getDistinctRowCount(hjRel.getLeft(), groupKey, rel.getCluster().getRexBuilder().makeLiteral(true)); } else { return RelMdUtil.getJoinDistinctRowCount(mq, rel, rel.getJoinType(), groupKey, predicate, true); } } return mq.getDistinctRowCount(rel, groupKey, predicate); }
ImmutableBitSet.Builder projCols = ImmutableBitSet.builder(); List<RexNode> projExprs = rel.getProjects(); RelMdUtil.splitCols(projExprs, groupKey, baseCols, projCols); RexNode preds = RexUtil.composeConjunction(rexBuilder, notPushable, true); distinctRowCount *= RelMdUtil.guessSelectivity(preds); RelMdUtil.cardOfProjExpr(mq, rel, projExprs.get(bit)); if (subRowCount == null) { return null; return RelMdUtil.numDistinctVals(distinctRowCount, mq.getRowCount(rel));
@Deprecated // to be removed before 2.0 public static double estimateFilteredRows(RelNode child, RexNode condition) { final RelMetadataQuery mq = RelMetadataQuery.instance(); return RelMdUtil.estimateFilteredRows(child, condition, mq); }
if (!RelMdUtil.areColumnsDefinitelyUniqueWhenNullsFiltered(mq, right, rightJoinKeys)) {
/** Catch-all implementation for * {@link BuiltInMetadata.PopulationSize#getPopulationSize(ImmutableBitSet)}, * invoked using reflection. * * @see org.apache.calcite.rel.metadata.RelMetadataQuery#getPopulationSize(RelNode, ImmutableBitSet) */ public Double getPopulationSize(RelNode rel, RelMetadataQuery mq, ImmutableBitSet groupKey) { // if the keys are unique, return the row count; otherwise, we have // no further information on which to return any legitimate value // REVIEW zfong 4/11/06 - Broadbase code returns the product of each // unique key, which would result in the population being larger // than the total rows in the relnode boolean uniq = RelMdUtil.areColumnsDefinitelyUnique(mq, rel, groupKey); if (uniq) { return mq.getRowCount(rel); } return null; } }
public Double getDistinctRowCount(Values rel, RelMetadataQuery mq, ImmutableBitSet groupKey, RexNode predicate) { if (predicate == null || predicate.isAlwaysTrue()) { if (groupKey.isEmpty()) { return 1D; } } double selectivity = RelMdUtil.guessSelectivity(predicate); // assume half the rows are duplicates double nRows = rel.estimateRowCount(mq) / 2; return RelMdUtil.numDistinctVals(nRows, nRows * selectivity); }
RelMdUtil.setAggChildKeys(groupKey, rel, childKey); RexNode preds = RexUtil.composeConjunction(rexBuilder, notPushable, true); return distinctRowCount * RelMdUtil.guessSelectivity(preds);
/** * * @param j * @param additionalPredicate * @return if predicate is the join condition return (true, joinCond) * else return (false, minusPred) */ private Pair<Boolean,RexNode> getCombinedPredicateForJoin(Join j, RexNode additionalPredicate) { RexNode minusPred = RelMdUtil.minusPreds(j.getCluster().getRexBuilder(), additionalPredicate, j.getCondition()); if (minusPred != null) { List<RexNode> minusList = new ArrayList<RexNode>(); minusList.add(j.getCondition()); minusList.add(minusPred); return new Pair<Boolean,RexNode>(false, minusPred); } return new Pair<Boolean,RexNode>(true,j.getCondition()); }
RelMdUtil.computeSemiJoinSelectivity(mq, factRel, dimRel, semiJoin); if (selectivity > .5) { return 0; RelMdUtil.areColumnsDefinitelyUniqueWhenNullsFiltered(mq, dimRel, dimCols); if (uniq) {
private double getIntervalCostMultiplier() { int days = 0; for (Interval interval : intervals) { days += interval.toDuration().getStandardDays(); } // Cost increases with the wider interval being queries. // A plan querying 10 or more years of data will have 10x the cost of a // plan returning 1 day data. // A plan where least interval is queries will be preferred. return RelMdUtil.linear(days, 1, DAYS_IN_TEN_YEARS, 0.1d, 1d); }
@Override public double estimateRowCount(RelMetadataQuery mq) { return Util.first(RelMdUtil.getJoinRowCount(mq, this, condition), 1D); }
public static boolean areColumnsDefinitelyUnique(RelMetadataQuery mq, RelNode rel, List<RexInputRef> columnRefs) { Boolean b = areColumnsUnique(mq, rel, columnRefs); return b != null && b; }
ImmutableBitSet.Builder projCols = ImmutableBitSet.builder(); List<RexNode> projExprs = rel.getProjects(); RelMdUtil.splitCols(projExprs, groupKey, baseCols, projCols); RexNode preds = RexUtil.composeConjunction(rexBuilder, notPushable, true); distinctRowCount *= RelMdUtil.guessSelectivity(preds); RelMdUtil.cardOfProjExpr(mq, rel, projExprs.get(bit)); if (subRowCount == null) { return null; return RelMdUtil.numDistinctVals(distinctRowCount, mq.getRowCount(rel));
@Deprecated // to be removed before 2.0 public static double estimateFilteredRows(RelNode child, RexProgram program) { final RelMetadataQuery mq = RelMetadataQuery.instance(); return RelMdUtil.estimateFilteredRows(child, program, mq); }
if (!RelMdUtil.areColumnsDefinitelyUniqueWhenNullsFiltered(mq, right, rightJoinKeys)) {
/** Catch-all implementation for * {@link BuiltInMetadata.PopulationSize#getPopulationSize(ImmutableBitSet)}, * invoked using reflection. * * @see org.apache.calcite.rel.metadata.RelMetadataQuery#getPopulationSize(RelNode, ImmutableBitSet) */ public Double getPopulationSize(RelNode rel, RelMetadataQuery mq, ImmutableBitSet groupKey) { // if the keys are unique, return the row count; otherwise, we have // no further information on which to return any legitimate value // REVIEW zfong 4/11/06 - Broadbase code returns the product of each // unique key, which would result in the population being larger // than the total rows in the relnode boolean uniq = RelMdUtil.areColumnsDefinitelyUnique(mq, rel, groupKey); if (uniq) { return mq.getRowCount(rel); } return null; } }
public Double getDistinctRowCount(Values rel, RelMetadataQuery mq, ImmutableBitSet groupKey, RexNode predicate) { if (predicate == null || predicate.isAlwaysTrue()) { if (groupKey.isEmpty()) { return 1D; } } double selectivity = RelMdUtil.guessSelectivity(predicate); // assume half the rows are duplicates double nRows = rel.estimateRowCount(mq) / 2; return RelMdUtil.numDistinctVals(nRows, nRows * selectivity); }
RelMdUtil.setAggChildKeys(groupKey, rel, childKey); RexNode preds = RexUtil.composeConjunction(rexBuilder, notPushable, true); return distinctRowCount * RelMdUtil.guessSelectivity(preds);