public RelOptCost getJoinCost(HiveJoin join) { // Select algorithm with min cost JoinAlgorithm joinAlgorithm = null; RelOptCost minJoinCost = null; if (LOG.isTraceEnabled()) { LOG.trace("Join algorithm selection for:\n" + RelOptUtil.toString(join)); } for (JoinAlgorithm possibleAlgorithm : this.joinAlgorithms) { if (!possibleAlgorithm.isExecutable(join)) { continue; } RelOptCost joinCost = possibleAlgorithm.getCost(join); if (LOG.isTraceEnabled()) { LOG.trace(possibleAlgorithm + " cost: " + joinCost); } if (minJoinCost == null || joinCost.isLt(minJoinCost) ) { joinAlgorithm = possibleAlgorithm; minJoinCost = joinCost; } } if (LOG.isTraceEnabled()) { LOG.trace(joinAlgorithm + " selected"); } join.setJoinAlgorithm(joinAlgorithm); join.setJoinCost(minJoinCost); return minJoinCost; }
public RelOptCost getJoinCost(HiveJoin join) { // Select algorithm with min cost JoinAlgorithm joinAlgorithm = null; RelOptCost minJoinCost = null; if (LOG.isTraceEnabled()) { LOG.trace("Join algorithm selection for:\n" + RelOptUtil.toString(join)); } for (JoinAlgorithm possibleAlgorithm : this.joinAlgorithms) { if (!possibleAlgorithm.isExecutable(join)) { continue; } RelOptCost joinCost = possibleAlgorithm.getCost(join); if (LOG.isTraceEnabled()) { LOG.trace(possibleAlgorithm + " cost: " + joinCost); } if (minJoinCost == null || joinCost.isLt(minJoinCost) ) { joinAlgorithm = possibleAlgorithm; minJoinCost = joinCost; } } if (LOG.isTraceEnabled()) { LOG.trace(joinAlgorithm + " selected"); } join.setJoinAlgorithm(joinAlgorithm); join.setJoinCost(minJoinCost); return minJoinCost; }
public RelOptCost getCumulativeCost(HiveJoin rel, RelMetadataQuery mq) { RelOptCost cost = mq.getNonCumulativeCost(rel); List<RelNode> inputs = rel.getInputs(); RelOptCost maxICost = HiveCost.ZERO; for (RelNode input : inputs) { RelOptCost iCost = mq.getCumulativeCost(input); if (maxICost.isLt(iCost)) { maxICost = iCost; } } return cost.plus(maxICost); } }
public RelOptCost getCumulativeCost(HiveJoin rel, RelMetadataQuery mq) { RelOptCost cost = mq.getNonCumulativeCost(rel); List<RelNode> inputs = rel.getInputs(); RelOptCost maxICost = HiveCost.ZERO; for (RelNode input : inputs) { RelOptCost iCost = mq.getCumulativeCost(input); if (maxICost.isLt(iCost)) { maxICost = iCost; } } return cost.plus(maxICost); } }
RelOptCost afterCost = mq.getCumulativeCost(r); RelOptCost beforeCost = mq.getCumulativeCost(aggregate); if (afterCost.isLt(beforeCost)) { call.transformTo(r);
if (afterCost.isLt(beforeCost)) { call.transformTo(r);
@Override public RelNode apply(Ord<Result> r) { RelCostPair pair = r.e.bestWithReflectionMap.get(reflection); if (r.i == alternateIndex || (pair != null && pair.cost.isLt(r.e.bestCost))) { return pair.rel; } else { return r.e.best; } } }));
public int compare(Integer rel1Idx, Integer rel2Idx) { RelOptCost c1 = mq.getCumulativeCost(chosenSemiJoins[rel1Idx]); RelOptCost c2 = mq.getCumulativeCost(chosenSemiJoins[rel2Idx]); // nulls are arbitrarily sorted if ((c1 == null) || (c2 == null)) { return -1; } return (c1.isLt(c2)) ? -1 : ((c1.equals(c2)) ? 0 : 1); } }
public int compare(Integer rel1Idx, Integer rel2Idx) { RelOptCost c1 = mq.getCumulativeCost(chosenSemiJoins[rel1Idx]); RelOptCost c2 = mq.getCumulativeCost(chosenSemiJoins[rel2Idx]); // nulls are arbitrarily sorted if ((c1 == null) || (c2 == null)) { return -1; } return (c1.isLt(c2)) ? -1 : ((c1.equals(c2)) ? 0 : 1); } }
void propagateCostImprovements0(VolcanoPlanner planner, RelMetadataQuery mq, RelNode rel, Set<RelSubset> activeSet) { ++timestamp; if (!activeSet.add(this)) { // This subset is already in the chain being propagated to. This // means that the graph is cyclic, and therefore the cost of this // relational expression - not this subset - must be infinite. LOGGER.trace("cyclic: {}", this); return; } try { final RelOptCost cost = planner.getCost(rel, mq); if (cost.isLt(bestCost)) { LOGGER.trace("Subset cost improved: subset [{}] cost was {} now {}", this, bestCost, cost); bestCost = cost; best = rel; // Lower cost means lower importance. Other nodes will change // too, but we'll get to them later. planner.ruleQueue.recompute(this); for (RelNode parent : getParents()) { final RelSubset parentSubset = planner.getSubset(parent); parentSubset.propagateCostImprovements(planner, mq, parent, activeSet); } planner.checkForSatisfiedConverters(set, rel); } } finally { activeSet.remove(this); } }
void propagateCostImprovements0(VolcanoPlanner planner, RelMetadataQuery mq, RelNode rel, Set<RelSubset> activeSet) { ++timestamp; if (!activeSet.add(this)) { // This subset is already in the chain being propagated to. This // means that the graph is cyclic, and therefore the cost of this // relational expression - not this subset - must be infinite. LOGGER.trace("cyclic: {}", this); return; } try { final RelOptCost cost = planner.getCost(rel, mq); if (cost.isLt(bestCost)) { LOGGER.trace("Subset cost improved: subset [{}] cost was {} now {}", this, bestCost, cost); bestCost = cost; best = rel; // Lower cost means lower importance. Other nodes will change // too, but we'll get to them later. planner.ruleQueue.recompute(this); for (RelNode parent : getParents()) { final RelSubset parentSubset = planner.getSubset(parent); parentSubset.propagateCostImprovements(planner, mq, parent, activeSet); } planner.checkForSatisfiedConverters(set, rel); } } finally { activeSet.remove(this); } }
public RelOptCost getCumulativeCost(HiveJoin rel) { RelOptCost cost = RelMetadataQuery.getNonCumulativeCost(rel); List<RelNode> inputs = rel.getInputs(); RelOptCost maxICost = HiveCost.ZERO; for (RelNode input : inputs) { RelOptCost iCost = RelMetadataQuery.getCumulativeCost(input); if (maxICost.isLt(iCost)) { maxICost = iCost; } } return cost.plus(maxICost); } }
/** * 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; } } }
/** * 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; } } }
public RelOptCost getCost(RelNode rel, RelMetadataQuery mq) { assert rel != null : "pre-condition: rel != null"; if (rel instanceof RelSubset) { return ((RelSubset) rel).bestCost; } if (rel.getTraitSet().getTrait(ConventionTraitDef.INSTANCE) == Convention.NONE) { return costFactory.makeInfiniteCost(); } RelOptCost cost = mq.getNonCumulativeCost(rel); if (!zeroCost.isLt(cost)) { // cost must be positive, so nudge it cost = costFactory.makeTinyCost(); } for (RelNode input : rel.getInputs()) { cost = cost.plus(getCost(input, mq)); } return cost; }
public RelOptCost getCost(RelNode rel, RelMetadataQuery mq) { assert rel != null : "pre-condition: rel != null"; if (rel instanceof RelSubset) { return ((RelSubset) rel).bestCost; } if (rel.getTraitSet().getTrait(ConventionTraitDef.INSTANCE) == Convention.NONE) { return costFactory.makeInfiniteCost(); } RelOptCost cost = mq.getNonCumulativeCost(rel); if (!zeroCost.isLt(cost)) { // cost must be positive, so nudge it cost = costFactory.makeTinyCost(); } for (RelNode input : rel.getInputs()) { cost = cost.plus(getCost(input, mq)); } return cost; }
/** * Checks internal consistency. */ protected boolean isValid(Litmus litmus) { for (RelSet set : allSets) { if (set.equivalentSet != null) { return litmus.fail("set [{}] has been merged: it should not be in the list", set); } for (RelSubset subset : set.subsets) { if (subset.set != set) { return litmus.fail("subset [{}] is in wrong set [{}]", subset.getDescription(), set); } for (RelNode rel : subset.getRels()) { RelOptCost relCost = getCost(rel, rel.getCluster().getMetadataQuery()); if (relCost.isLt(subset.bestCost)) { return litmus.fail("rel [{}] has lower cost {} than best cost {} of subset [{}]", rel.getDescription(), relCost, subset.bestCost, subset.getDescription()); } } } } return litmus.succeed(); }
/** * Checks internal consistency. */ protected boolean isValid(Litmus litmus) { for (RelSet set : allSets) { if (set.equivalentSet != null) { return litmus.fail("set [{}] has been merged: it should not be in the list", set); } for (RelSubset subset : set.subsets) { if (subset.set != set) { return litmus.fail("subset [{}] is in wrong set [{}]", subset.getDescription(), set); } for (RelNode rel : subset.getRels()) { RelOptCost relCost = getCost(rel, rel.getCluster().getMetadataQuery()); if (relCost.isLt(subset.bestCost)) { return litmus.fail("rel [{}] has lower cost {} than best cost {} of subset [{}]", rel.getDescription(), relCost, subset.bestCost, subset.getDescription()); } } } } return litmus.succeed(); }
public RelOptCost getJoinCost(HiveJoin join) { // Select algorithm with min cost JoinAlgorithm joinAlgorithm = null; RelOptCost minJoinCost = null; if (LOG.isDebugEnabled()) { LOG.debug("Join algorithm selection for:\n" + RelOptUtil.toString(join)); } for (JoinAlgorithm possibleAlgorithm : this.joinAlgorithms) { if (!possibleAlgorithm.isExecutable(join)) { continue; } RelOptCost joinCost = possibleAlgorithm.getCost(join); if (LOG.isDebugEnabled()) { LOG.debug(possibleAlgorithm + " cost: " + joinCost); } if (minJoinCost == null || joinCost.isLt(minJoinCost) ) { joinAlgorithm = possibleAlgorithm; minJoinCost = joinCost; } } if (LOG.isDebugEnabled()) { LOG.debug(joinAlgorithm + " selected"); } join.setJoinAlgorithm(joinAlgorithm); join.setJoinCost(minJoinCost); return minJoinCost; }