Skip to content

Commit

Permalink
Ensure to pushdown the aggregation for count(const)
Browse files Browse the repository at this point in the history
Aggregate pushdown should be enabled even with count(const) query. Since
SimplifyCountOverConstant is applied after PushAggregationIntoTableScan,
the aggregation pushdown does not treat count(*) and count(const)
uniformally.
  • Loading branch information
Lewuathe authored and findepi committed Jul 23, 2020
1 parent 8db1d3a commit 84d3b06
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ public PlanOptimizers(
new MergeLimitWithDistinct(),
new PruneCountAggregationOverScalar(metadata),
new PruneOrderByInAggregation(metadata),
new RewriteSpatialPartitioningAggregation(metadata)))
new RewriteSpatialPartitioningAggregation(metadata),
new SimplifyCountOverConstant(metadata)))
.build()),
new IterativeOptimizer(
ruleStats,
Expand Down Expand Up @@ -552,11 +553,6 @@ public PlanOptimizers(
new UnaliasSymbolReferences(metadata), // Run again because predicate pushdown and projection pushdown might add more projections
columnPruningOptimizer, // Make sure to run this before index join. Filtered projections may not have all the columns.
new IndexJoinOptimizer(metadata), // Run this after projections and filters have been fully simplified and pushed down
new IterativeOptimizer(
ruleStats,
statsCalculator,
estimatedExchangesCostCalculator,
ImmutableSet.of(new SimplifyCountOverConstant(metadata))),
new LimitPushDown(), // Run LimitPushDown before WindowFilterPushDown
new WindowFilterPushDown(metadata), // This must run after PredicatePushDown and LimitPushDown so that it squashes any successive filter nodes and limits
new IterativeOptimizer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ public void testAggregationPushdown()

assertAggregationPushedDown("SELECT count(*) FROM nation");
assertAggregationPushedDown("SELECT count(nationkey) FROM nation");
assertAggregationPushedDown("SELECT count(1) FROM nation");
assertAggregationPushedDown("SELECT count() FROM nation");
assertAggregationPushedDown("SELECT regionkey, min(nationkey) FROM nation GROUP BY regionkey");
assertAggregationPushedDown("SELECT regionkey, max(nationkey) FROM nation GROUP BY regionkey");
assertAggregationPushedDown("SELECT regionkey, sum(nationkey) FROM nation GROUP BY regionkey");
Expand Down

0 comments on commit 84d3b06

Please sign in to comment.