/** * Since the grouping aggregate will be expanded by {@link org.apache.kylin.query.optrule.AggregateMultipleExpandRule}, * made the cost of grouping aggregate more expensive to use the expanded aggregates */ @Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { RelOptCost cost; if (getGroupType() == Group.SIMPLE) { cost = super.computeSelfCost(planner, mq).multiplyBy(.05); } else { cost = super.computeSelfCost(planner, mq).multiplyBy(.05).plus(planner.getCost(getInput(), mq)) .multiplyBy(groupSets.size() * 1.5); } return cost; }
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { double rowCount = mq.getRowCount(this); final double rightRowCount = right.estimateRowCount(mq); final double leftRowCount = left.estimateRowCount(mq); if (Double.isInfinite(leftRowCount) || Double.isInfinite(rightRowCount)) { return planner.getCostFactory().makeInfiniteCost(); } Double restartCount = mq.getRowCount(getLeft()); // RelMetadataQuery.getCumulativeCost(getRight()); does not work for // RelSubset, so we ask planner to cost-estimate right relation RelOptCost rightCost = planner.getCost(getRight(), mq); RelOptCost rescanCost = rightCost.multiplyBy(Math.max(1.0, restartCount - 1)); return planner.getCostFactory().makeCost( rowCount /* generate results */ + leftRowCount /* scan left results */, 0, 0).plus(rescanCost); } }
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { double rowCount = mq.getRowCount(this); final double rightRowCount = right.estimateRowCount(mq); final double leftRowCount = left.estimateRowCount(mq); if (Double.isInfinite(leftRowCount) || Double.isInfinite(rightRowCount)) { return planner.getCostFactory().makeInfiniteCost(); } Double restartCount = mq.getRowCount(getLeft()); // RelMetadataQuery.getCumulativeCost(getRight()); does not work for // RelSubset, so we ask planner to cost-estimate right relation RelOptCost rightCost = planner.getCost(getRight(), mq); RelOptCost rescanCost = rightCost.multiplyBy(Math.max(1.0, restartCount - 1)); return planner.getCostFactory().makeCost( rowCount /* generate results */ + leftRowCount /* scan left results */, 0, 0).plus(rescanCost); } }
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { return planner.getCost(jdbcSubTree, mq); }
/** * Computes the best {@link RelNode} in this subset. * * <p>Only necessary when a subset is created in a set that has subsets that * subsume it. Rationale:</p> * * <ol> * <li>If the are no subsuming subsets, the subset is initially empty.</li> * <li>After creation, {@code best} and {@code bestCost} are maintained * incrementally by {@link #propagateCostImprovements0} and * {@link RelSet#mergeWith(VolcanoPlanner, RelSet)}.</li> * </ol> */ private void computeBestCost(RelOptPlanner planner) { bestCost = planner.getCostFactory().makeInfiniteCost(); final RelMetadataQuery mq = getCluster().getMetadataQuery(); for (RelNode rel : getRels()) { final RelOptCost cost = planner.getCost(rel, mq); if (cost.isLt(bestCost)) { bestCost = cost; best = rel; } } }
Convention previous = null; for (Convention arc : conversionPath) { if (planner.getCost(converted, mq).isInfinite() && !allowInfiniteCostConverters) { continue loop;
/** * Computes the best {@link RelNode} in this subset. * * <p>Only necessary when a subset is created in a set that has subsets that * subsume it. Rationale:</p> * * <ol> * <li>If the are no subsuming subsets, the subset is initially empty.</li> * <li>After creation, {@code best} and {@code bestCost} are maintained * incrementally by {@link #propagateCostImprovements0} and * {@link RelSet#mergeWith(VolcanoPlanner, RelSet)}.</li> * </ol> */ private void computeBestCost(RelOptPlanner planner) { bestCost = planner.getCostFactory().makeInfiniteCost(); final RelMetadataQuery mq = getCluster().getMetadataQuery(); for (RelNode rel : getRels()) { final RelOptCost cost = planner.getCost(rel, mq); if (cost.isLt(bestCost)) { bestCost = cost; best = rel; } } }
Convention previous = null; for (Convention arc : conversionPath) { if (planner.getCost(converted, mq).isInfinite() && !allowInfiniteCostConverters) { continue loop;
/** * Since the grouping aggregate will be expanded by {@link org.apache.kylin.query.optrule.AggregateMultipleExpandRule}, * made the cost of grouping aggregate more expensive to use the expanded aggregates */ @Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { RelOptCost cost; if (getGroupType() == Group.SIMPLE) { cost = super.computeSelfCost(planner, mq).multiplyBy(.05); } else { cost = super.computeSelfCost(planner, mq).multiplyBy(.05).plus(planner.getCost(getInput(), mq)) .multiplyBy(groupSets.size() * 1.5); } return cost; }
public RelNode convert( RelOptPlanner planner, RelNode rel, AltTrait toTrait, boolean allowInfiniteCostConverters) { RelTrait fromTrait = rel.getTraitSet().getTrait(this); if (conversionMap.containsKey(fromTrait)) { final RelMetadataQuery mq = RelMetadataQuery.instance(); for (Pair<RelTrait, ConverterRule> traitAndRule : conversionMap.get(fromTrait)) { RelTrait trait = traitAndRule.left; ConverterRule rule = traitAndRule.right; if (trait == toTrait) { RelNode converted = rule.convert(rel); if ((converted != null) && (!planner.getCost(converted, mq).isInfinite() || allowInfiniteCostConverters)) { return converted; } } } } return null; }
public RelNode convert( RelOptPlanner planner, RelNode rel, AltTrait toTrait, boolean allowInfiniteCostConverters) { RelTrait fromTrait = rel.getTraitSet().getTrait(this); if (conversionMap.containsKey(fromTrait)) { final RelMetadataQuery mq = RelMetadataQuery.instance(); for (Pair<RelTrait, ConverterRule> traitAndRule : conversionMap.get(fromTrait)) { RelTrait trait = traitAndRule.left; ConverterRule rule = traitAndRule.right; if (trait == toTrait) { RelNode converted = rule.convert(rel); if ((converted != null) && (!planner.getCost(converted, mq).isInfinite() || allowInfiniteCostConverters)) { return converted; } } } } return null; }