Skip to content

Commit

Permalink
[CALCITE-6249] RelNode::estimatedRowCount should not be used in compu…
Browse files Browse the repository at this point in the history
…teSelfCost
  • Loading branch information
kramerul committed Feb 7, 2024
1 parent 5f2cfeb commit 4b05e05
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public static EnumerableBatchNestedLoopJoin create(
final RelMetadataQuery mq) {
double rowCount = mq.getRowCount(this);

final double rightRowCount = right.estimateRowCount(mq);
final double leftRowCount = left.estimateRowCount(mq);
final double rightRowCount = mq.getRowCount(right);
final double leftRowCount = mq.getRowCount(left);
if (Double.isInfinite(leftRowCount) || Double.isInfinite(rightRowCount)) {
return planner.getCostFactory().makeInfiniteCost();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public static EnumerableHashJoin create(

// Cheaper if the smaller number of rows is coming from the LHS.
// Model this by adding L log L to the cost.
final double rightRowCount = right.estimateRowCount(mq);
final double leftRowCount = left.estimateRowCount(mq);
final double rightRowCount = mq.getRowCount(right);
final double leftRowCount = mq.getRowCount(left);
if (Double.isInfinite(leftRowCount)) {
rowCount = leftRowCount;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ public static EnumerableMergeJoin create(RelNode left, RelNode right,
// We assume that the inputs are sorted. The price of sorting them has
// already been paid. The cost of the join is therefore proportional to the
// input and output size.
final double rightRowCount = right.estimateRowCount(mq);
final double leftRowCount = left.estimateRowCount(mq);
final double rightRowCount = mq.getRowCount(right);
final double leftRowCount = mq.getRowCount(left);
final double rowCount = mq.getRowCount(this);
final double d = leftRowCount + rightRowCount + rowCount;
return planner.getCostFactory().makeCost(d, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public static EnumerableNestedLoopJoin create(
}
}

final double rightRowCount = right.estimateRowCount(mq);
final double leftRowCount = left.estimateRowCount(mq);
final double rightRowCount = mq.getRowCount(right);
final double leftRowCount = mq.getRowCount(left);
if (Double.isInfinite(leftRowCount)) {
rowCount = leftRowCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ protected JdbcJoin(
}

@Override public double estimateRowCount(RelMetadataQuery mq) {
final double leftRowCount = left.estimateRowCount(mq);
final double rightRowCount = right.estimateRowCount(mq);
final double leftRowCount = mq.getRowCount(left);
final double rightRowCount = mq.getRowCount(right);
return Math.max(leftRowCount, rightRowCount);
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/apache/calcite/rel/core/Correlate.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ public ImmutableBitSet getRequiredColumns() {
RelMetadataQuery mq) {
double rowCount = mq.getRowCount(this);

final double rightRowCount = right.estimateRowCount(mq);
final double leftRowCount = left.estimateRowCount(mq);
final double rightRowCount = mq.getRowCount(right);
final double leftRowCount = mq.getRowCount(left);
if (Double.isInfinite(leftRowCount) || Double.isInfinite(rightRowCount)) {
return planner.getCostFactory().makeInfiniteCost();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected TableScan(RelInput input) {

@Override public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner,
RelMetadataQuery mq) {
double dRows = table.getRowCount();
double dRows = mq.getRowCount(this);
double dCpu = dRows + 1; // ensure non-zero cost
double dIo = 0;
return planner.getCostFactory().makeCost(dRows, dCpu, dIo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected void apply(RelOptRuleCall call, @Nullable Project postProject,
final CalciteSchema.TableEntry tableEntry = pair.left;
final TileKey tileKey = pair.right;
final RelMetadataQuery mq = call.getMetadataQuery();
final double rowCount = aggregate.estimateRowCount(mq);
final double rowCount = mq.getRowCount(aggregate);
final Table aggregateTable = tableEntry.getTable();
final RelDataType aggregateTableRowType =
aggregateTable.getRowType(cluster.getTypeFactory());
Expand Down

0 comments on commit 4b05e05

Please sign in to comment.