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);
RelOptCost afterCost = mq.getCumulativeCost(r); RelOptCost beforeCost = mq.getCumulativeCost(aggregate); if (afterCost.isLt(beforeCost)) { call.transformTo(r);
public RelOptCost getCost(RelNode rel, RelMetadataQuery mq) { return mq.getCumulativeCost(rel); }
public RelOptCost getCost(RelNode rel, RelMetadataQuery mq) { return mq.getCumulativeCost(rel); }
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); } }
@Override public Double visitPrel(Prel prel, Void value) throws RuntimeException { RelMetadataQuery mq = RelMetadataQuery.instance(); return ((DrillCostBase) mq.getCumulativeCost(prel)).getMemory(); // return findCost(prel, mq); }
public RelOptCost getCumulativeCost(RelNode rel, RelMetadataQuery mq) { RelOptCost cost = mq.getNonCumulativeCost(rel); List<RelNode> inputs = rel.getInputs(); for (RelNode input : inputs) { cost = cost.plus(mq.getCumulativeCost(input)); } return cost; }
public RelOptCost getCumulativeCost(RelNode rel, RelMetadataQuery mq) { RelOptCost cost = mq.getNonCumulativeCost(rel); List<RelNode> inputs = rel.getInputs(); for (RelNode input : inputs) { cost = cost.plus(mq.getCumulativeCost(input)); } return cost; }
.append(mq.getRowCount(rel)) .append(", cumulative cost = ") .append(mq.getCumulativeCost(rel));
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); } }
@Override public RelNode visit(final TableScan scan) { final Optional<MaterializationDescriptor> descriptor = table.getDescriptor(scan.getTable().getQualifiedName()); if (descriptor.isPresent()) { // Always use metadataQuery from the cluster (do not use calcite's default CALCITE_INSTANCE) final RelOptCost cost = scan.getCluster().getMetadataQuery().getCumulativeCost(scan); final double acceleratedCost = DremioCost.aggregateCost(cost); final double originalCost = descriptor.get().getOriginalCost(); final double speedUp = originalCost/acceleratedCost; builder.addSubstitution(new SubstitutionInfo.Substitution(descriptor.get(), speedUp)); } return super.visit(scan); }
final RelOptCost cost = root.getCluster().getMetadataQuery().getCumulativeCost(root); final double acceleratedCost = DremioCost.aggregateCost(cost); builder.setCost(acceleratedCost);
@Override public void planRelTransform(PlannerPhase phase, RelOptPlanner planner, RelNode before, RelNode after, long millisTaken) { switch(phase){ case JOIN_PLANNING_MULTI_JOIN: // Join optimization starts with multijoin analysis phase builder.addPreJoinPlan(before); break; case LOGICAL: builder.addLogicalPlan(before, after); // Always use metadataQuery from the cluster (do not use calcite's default CALCITE_INSTANCE) final RelOptCost cost = before.getCluster().getMetadataQuery().getCumulativeCost(after); // set final pre-accelerated cost builder.addCost(cost); break; default: // noop. } }
@Override public void planRelTransform(PlannerPhase phase, RelOptPlanner planner, RelNode before, RelNode after, long millisTaken) { statusListener.planRelTransform(phase, before, after, millisTaken); switch(phase){ case LOGICAL: builder.addLogicalPlan(before, after); // set final pre-accelerated cost final RelOptCost cost = after.getCluster().getMetadataQuery().getCumulativeCost(after); builder.addCost(cost); break; case JOIN_PLANNING_MULTI_JOIN: // Join planning starts with multi-join analysis phase builder.addPreJoinPlan(before); break; default: return; } }
protected void explain_(RelNode rel, List<Pair<String, Object>> values) { final Map<String, Object> map = Maps.newLinkedHashMap(); // need the ordering RelMetadataQuery mq = rel.getCluster().getMetadataQuery(); putIntoMap(map, "op", relJson.classToTypeName(rel.getClass())); final Map<String, Object> valuesMap = jsonBuilder.map(); for (Pair<String, Object> value : values) { if (value.right instanceof RelNode) { continue; } putIntoMap(valuesMap, value.left, escapeSpecialChars(String.valueOf(value.right))); } putIntoMap(map, "values", valuesMap); final List<String> inputOpIds = getInputOpIds(rel.getInputs()); putIntoMap(map, "inputs", inputOpIds); putIntoMap(map, "rowType", escapeSpecialChars(String.valueOf(rel.getRowType()))); putIntoMap(map, "rowCount", mq.getRowCount(rel)); putIntoMap(map, "cumulativeCost", escapeSpecialChars(String.valueOf(mq.getCumulativeCost(rel)))); final OpId opId = ids.get(rel); putIntoMap(relExplainMap, String.format("%02d-%02d", opId.getFragmentId(), opId.getOpId()), map); explainInputs(rel.getInputs()); }
@Test public void testOne() throws Exception { RelNode planned = run(new PropAction(), RULES); if (CalcitePrepareImpl.DEBUG) { System.out.println( RelOptUtil.dumpPlan("LOGICAL PLAN", planned, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES)); } final RelMetadataQuery mq = RelMetadataQuery.instance(); assertEquals("Sortedness was not propagated", 3, mq.getCumulativeCost(planned).getRows(), 0); }
@Test public void testOne() throws Exception { RelNode planned = run(new PropAction(), RULES); if (CalcitePrepareImpl.DEBUG) { System.out.println( RelOptUtil.dumpPlan("LOGICAL PLAN", planned, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES)); } final RelMetadataQuery mq = RelMetadataQuery.instance(); assertEquals("Sortedness was not propagated", 3, mq.getCumulativeCost(planned).getRows(), 0); }