diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java index 62c8f56dae1..e9129a5857a 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java @@ -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(); } diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java index cfe44da75d7..8bd9ffbf08d 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java @@ -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 { diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java index 3f42e065c83..97eae019d3f 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java @@ -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); diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableNestedLoopJoin.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableNestedLoopJoin.java index 6b1bf40cf77..de539ad574c 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableNestedLoopJoin.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableNestedLoopJoin.java @@ -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; } diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java index 4fbe4c55c96..8bfedbe47fe 100644 --- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java +++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java @@ -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); } diff --git a/core/src/main/java/org/apache/calcite/rel/core/Correlate.java b/core/src/main/java/org/apache/calcite/rel/core/Correlate.java index f5194a1e749..752dd9bf15a 100644 --- a/core/src/main/java/org/apache/calcite/rel/core/Correlate.java +++ b/core/src/main/java/org/apache/calcite/rel/core/Correlate.java @@ -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(); } diff --git a/core/src/main/java/org/apache/calcite/rel/core/TableScan.java b/core/src/main/java/org/apache/calcite/rel/core/TableScan.java index 2a1c498a441..390852f838a 100644 --- a/core/src/main/java/org/apache/calcite/rel/core/TableScan.java +++ b/core/src/main/java/org/apache/calcite/rel/core/TableScan.java @@ -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); diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java b/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java index 7b2e9a16961..565e0cd734e 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java @@ -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());