public Double visitLiteral(RexLiteral literal) { return numDistinctVals(1.0, mq.getRowCount(rel)); }
public Double visitLiteral(RexLiteral literal) { return numDistinctVals(1.0, mq.getRowCount(rel)); }
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); }
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); }
public Double visitInputRef(RexInputRef var) { int index = var.getIndex(); ImmutableBitSet col = ImmutableBitSet.of(index); Double distinctRowCount = mq.getDistinctRowCount(rel.getInput(), col, null); if (distinctRowCount == null) { return null; } else { return numDistinctVals(distinctRowCount, mq.getRowCount(rel)); } }
public Double visitInputRef(RexInputRef var) { int index = var.getIndex(); ImmutableBitSet col = ImmutableBitSet.of(index); Double distinctRowCount = mq.getDistinctRowCount(rel.getInput(), col, null); if (distinctRowCount == null) { return null; } else { return numDistinctVals(distinctRowCount, mq.getRowCount(rel)); } }
return numDistinctVals(distinctRowCount, rowCount);
return numDistinctVals(distinctRowCount, rowCount);
/** * Computes the population size for a set of keys returned from a join * * @param joinRel the join rel * @param groupKey keys to compute the population for * @return computed population size */ public static Double getJoinPopulationSize(RelMetadataQuery mq, RelNode joinRel, ImmutableBitSet groupKey) { ImmutableBitSet.Builder leftMask = ImmutableBitSet.builder(); ImmutableBitSet.Builder rightMask = ImmutableBitSet.builder(); RelNode left = joinRel.getInputs().get(0); RelNode right = joinRel.getInputs().get(1); // separate the mask into masks for the left and right RelMdUtil.setLeftRightBitmaps( groupKey, leftMask, rightMask, left.getRowType().getFieldCount()); Double population = NumberUtil.multiply( mq.getPopulationSize(left, leftMask.build()), mq.getPopulationSize(right, rightMask.build())); return numDistinctVals(population, mq.getRowCount(joinRel)); }
/** * Computes the population size for a set of keys returned from a join * * @param joinRel the join rel * @param groupKey keys to compute the population for * @return computed population size */ public static Double getJoinPopulationSize(RelMetadataQuery mq, RelNode joinRel, ImmutableBitSet groupKey) { ImmutableBitSet.Builder leftMask = ImmutableBitSet.builder(); ImmutableBitSet.Builder rightMask = ImmutableBitSet.builder(); RelNode left = joinRel.getInputs().get(0); RelNode right = joinRel.getInputs().get(1); // separate the mask into masks for the left and right RelMdUtil.setLeftRightBitmaps( groupKey, leftMask, rightMask, left.getRowType().getFieldCount()); Double population = NumberUtil.multiply( mq.getPopulationSize(left, leftMask.build()), mq.getPopulationSize(right, rightMask.build())); return numDistinctVals(population, mq.getRowCount(joinRel)); }
public Double getPopulationSize(Project rel, RelMetadataQuery mq, ImmutableBitSet groupKey) { ImmutableBitSet.Builder baseCols = ImmutableBitSet.builder(); ImmutableBitSet.Builder projCols = ImmutableBitSet.builder(); List<RexNode> projExprs = rel.getProjects(); RelMdUtil.splitCols(projExprs, groupKey, baseCols, projCols); Double population = mq.getPopulationSize(rel.getInput(), baseCols.build()); if (population == null) { return null; } // No further computation required if the projection expressions are // all column references if (projCols.cardinality() == 0) { return population; } for (int bit : projCols.build()) { Double subRowCount = RelMdUtil.cardOfProjExpr(mq, rel, projExprs.get(bit)); if (subRowCount == null) { return null; } population *= subRowCount; } // REVIEW zfong 6/22/06 - Broadbase did not have the call to // numDistinctVals. This is needed; otherwise, population can be // larger than the number of rows in the RelNode. return RelMdUtil.numDistinctVals(population, mq.getRowCount(rel)); }
public Double getPopulationSize(Project rel, RelMetadataQuery mq, ImmutableBitSet groupKey) { ImmutableBitSet.Builder baseCols = ImmutableBitSet.builder(); ImmutableBitSet.Builder projCols = ImmutableBitSet.builder(); List<RexNode> projExprs = rel.getProjects(); RelMdUtil.splitCols(projExprs, groupKey, baseCols, projCols); Double population = mq.getPopulationSize(rel.getInput(), baseCols.build()); if (population == null) { return null; } // No further computation required if the projection expressions are // all column references if (projCols.cardinality() == 0) { return population; } for (int bit : projCols.build()) { Double subRowCount = RelMdUtil.cardOfProjExpr(mq, rel, projExprs.get(bit)); if (subRowCount == null) { return null; } population *= subRowCount; } // REVIEW zfong 6/22/06 - Broadbase did not have the call to // numDistinctVals. This is needed; otherwise, population can be // larger than the number of rows in the RelNode. return RelMdUtil.numDistinctVals(population, mq.getRowCount(rel)); }
return RelMdUtil.numDistinctVals(distRowCount, mq.getRowCount(joinRel));
return RelMdUtil.numDistinctVals(distRowCount, mq.getRowCount(joinRel));
return RelMdUtil.numDistinctVals(distinctRowCount, mq.getRowCount(rel));
return RelMdUtil.numDistinctVals(distinctRowCount, mq.getRowCount(rel));