Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable push partial aggregation though join #23812

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class OptimizerConfig
private boolean preferPartialAggregation = true;
raunaqmorarka marked this conversation as resolved.
Show resolved Hide resolved
private boolean pushAggregationThroughOuterJoin = true;
private boolean enableIntermediateAggregations;
private boolean pushPartialAggregationThroughJoin;
private boolean pushPartialAggregationThroughJoin = true;
private boolean preAggregateCaseAggregationsEnabled = true;
private boolean enableForcedExchangeBelowGroupId = true;
private boolean optimizeTopNRanking = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,13 @@ public PlanOptimizers(
ruleStats,
statsCalculator,
costCalculator,
ImmutableSet.of(
new PushPartialAggregationThroughJoin(),
new PushPartialAggregationThroughExchange(plannerContext),
new PruneJoinColumns(),
new PruneJoinChildrenColumns())));
ImmutableSet.<Rule<?>>builder()
.addAll(new PushPartialAggregationThroughJoin().rules())
.add(new PushPartialAggregationThroughExchange(plannerContext),
new PruneJoinColumns(),
new PruneJoinChildrenColumns(),
new RemoveRedundantIdentityProjections())
.build()));
builder.add(new IterativeOptimizer(
plannerContext,
ruleStats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ private PlanNode pushPartial(AggregationNode aggregation, ExchangeNode exchange,

SymbolMapper symbolMapper = mappingsBuilder.build();
AggregationNode mappedPartial = symbolMapper.map(aggregation, source, context.getIdAllocator().getNextId());
mappedPartial = AggregationNode.builderFrom(mappedPartial)
.setIsInputReducingAggregation(true)
.build();

Assignments.Builder assignments = Assignments.builder();

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public class AggregationNode
private final Optional<Symbol> hashSymbol;
private final Optional<Symbol> groupIdSymbol;
private final List<Symbol> outputs;
/**
* Indicates whether it is beneficial (e.g. reduces remote exchange input) to retain this aggregation
* as an auxiliary step when making a decision to push down partial aggregation more aggressively.
*/
private final Optional<Boolean> isInputReducingAggregation;

public static AggregationNode singleAggregation(
PlanNodeId id,
Expand All @@ -63,6 +68,19 @@ public static AggregationNode singleAggregation(
return new AggregationNode(id, source, aggregations, groupingSets, ImmutableList.of(), SINGLE, Optional.empty(), Optional.empty());
}

public AggregationNode(
PlanNodeId id,
PlanNode source,
Map<Symbol, Aggregation> aggregations,
GroupingSetDescriptor groupingSets,
List<Symbol> preGroupedSymbols,
Step step,
Optional<Symbol> hashSymbol,
Optional<Symbol> groupIdSymbol)
{
this(id, source, aggregations, groupingSets, preGroupedSymbols, step, hashSymbol, groupIdSymbol, Optional.empty());
}

@JsonCreator
public AggregationNode(
@JsonProperty("id") PlanNodeId id,
Expand All @@ -72,7 +90,8 @@ public AggregationNode(
@JsonProperty("preGroupedSymbols") List<Symbol> preGroupedSymbols,
@JsonProperty("step") Step step,
@JsonProperty("hashSymbol") Optional<Symbol> hashSymbol,
@JsonProperty("groupIdSymbol") Optional<Symbol> groupIdSymbol)
@JsonProperty("groupIdSymbol") Optional<Symbol> groupIdSymbol,
@JsonProperty("isInputReducingAggregation") Optional<Boolean> isInputReducingAggregation)
{
super(id);

Expand Down Expand Up @@ -104,6 +123,7 @@ public AggregationNode(
outputs.addAll(aggregations.keySet());

this.outputs = outputs.build();
this.isInputReducingAggregation = requireNonNull(isInputReducingAggregation, "exchangeInputAggregation is null");
}

public List<Symbol> getGroupingKeys()
Expand Down Expand Up @@ -207,6 +227,12 @@ public Optional<Symbol> getGroupIdSymbol()
return groupIdSymbol;
}

@JsonProperty("isInputReducingAggregation")
public boolean isInputReducingAggregation()
{
return isInputReducingAggregation.orElse(false);
}

public boolean hasOrderings()
{
return aggregations.values().stream()
Expand Down Expand Up @@ -513,6 +539,7 @@ public static class Builder
private Step step;
private Optional<Symbol> hashSymbol;
private Optional<Symbol> groupIdSymbol;
private Optional<Boolean> isInputReducingAggregation;

public Builder(AggregationNode node)
{
Expand All @@ -525,6 +552,7 @@ public Builder(AggregationNode node)
this.step = node.getStep();
this.hashSymbol = node.getHashSymbol();
this.groupIdSymbol = node.getGroupIdSymbol();
this.isInputReducingAggregation = node.isInputReducingAggregation;
}

public Builder setId(PlanNodeId id)
Expand Down Expand Up @@ -575,6 +603,12 @@ public Builder setGroupIdSymbol(Optional<Symbol> groupIdSymbol)
return this;
}

public Builder setIsInputReducingAggregation(boolean isInputReducingAggregation)
{
this.isInputReducingAggregation = Optional.of(isInputReducingAggregation);
return this;
}

public AggregationNode build()
{
return new AggregationNode(
Expand All @@ -585,7 +619,8 @@ public AggregationNode build()
preGroupedSymbols,
step,
hashSymbol,
groupIdSymbol);
groupIdSymbol,
isInputReducingAggregation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testDefaults()
.setEnableForcedExchangeBelowGroupId(true)
.setEnableIntermediateAggregations(false)
.setPushAggregationThroughOuterJoin(true)
.setPushPartialAggregationThroughJoin(false)
.setPushPartialAggregationThroughJoin(true)
.setPreAggregateCaseAggregationsEnabled(true)
.setDistinctAggregationsStrategy(null)
.setPreferPartialAggregation(true)
Expand Down Expand Up @@ -126,7 +126,7 @@ public void testExplicitPropertyMappings()
.put("optimizer.push-table-write-through-union", "false")
.put("optimizer.dictionary-aggregation", "true")
.put("optimizer.push-aggregation-through-outer-join", "false")
.put("optimizer.push-partial-aggregation-through-join", "true")
.put("optimizer.push-partial-aggregation-through-join", "false")
.put("optimizer.pre-aggregate-case-aggregations.enabled", "false")
.put("optimizer.enable-intermediate-aggregations", "true")
.put("optimizer.force-single-node-output", "true")
Expand Down Expand Up @@ -181,7 +181,7 @@ public void testExplicitPropertyMappings()
.setPushTableWriteThroughUnion(false)
.setDictionaryAggregation(true)
.setPushAggregationThroughOuterJoin(false)
.setPushPartialAggregationThroughJoin(true)
.setPushPartialAggregationThroughJoin(false)
.setPreAggregateCaseAggregationsEnabled(false)
.setEnableIntermediateAggregations(true)
.setDistinctAggregationsStrategy(MARK_DISTINCT)
Expand Down
Loading