Java Code Examples for org.apache.calcite.plan.RelOptPlanner#getCost()

The following examples show how to use org.apache.calcite.plan.RelOptPlanner#getCost() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Correlate.java    From Bats with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: Correlate.java    From calcite with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: EnumerableBatchNestedLoopJoin.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public RelOptCost computeSelfCost(
    final RelOptPlanner planner,
    final 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()) / variablesSet.size();

  RelOptCost rightCost = planner.getCost(getRight(), mq);
  RelOptCost rescanCost =
      rightCost.multiplyBy(Math.max(1.0, restartCount - 1));

  // TODO Add cost of last loop (the one that looks for the match)
  return planner.getCostFactory().makeCost(
      rowCount + leftRowCount, 0, 0).plus(rescanCost);
}
 
Example 4
Source File: JdbcRelBase.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
  return planner.getCost(jdbcSubTree, mq);
}
 
Example 5
Source File: RelSubset.java    From Bats with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
    }
  }
}
 
Example 6
Source File: RelSubset.java    From calcite with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
    }
  }
}