Skip to content

Adaptive broadcast to partitioned #23206

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -202,6 +202,7 @@ public final class SystemSessionProperties
public static final String FAULT_TOLERANT_EXECUTION_ADAPTIVE_JOIN_REORDERING_ENABLED = "fault_tolerant_execution_adaptive_join_reordering_enabled";
public static final String FAULT_TOLERANT_EXECUTION_ADAPTIVE_JOIN_REORDERING_SIZE_DIFFERENCE_RATIO = "fault_tolerant_execution_adaptive_join_reordering_size_difference_ratio";
public static final String FAULT_TOLERANT_EXECUTION_ADAPTIVE_JOIN_REORDERING_MIN_SIZE_THRESHOLD = "fault_tolerant_execution_adaptive_join_reordering_min_size_threshold";
public static final String FAULT_TOLERANT_EXECUTION_ADAPTIVE_BROADCAST_TO_PARTITIONED_JOIN_ENABLED = "fault_tolerant_execution_adaptive_broadcast_to_partitioned_join_enabled";
public static final String ADAPTIVE_PARTIAL_AGGREGATION_ENABLED = "adaptive_partial_aggregation_enabled";
public static final String ADAPTIVE_PARTIAL_AGGREGATION_UNIQUE_ROWS_RATIO_THRESHOLD = "adaptive_partial_aggregation_unique_rows_ratio_threshold";
public static final String REMOTE_TASK_ADAPTIVE_UPDATE_REQUEST_SIZE_ENABLED = "remote_task_adaptive_update_request_size_enabled";
Expand Down Expand Up @@ -1040,6 +1041,11 @@ public SystemSessionProperties(
"The minimum size of the right side of join to consider reordering",
queryManagerConfig.getFaultTolerantExecutionAdaptiveJoinReorderingMinSizeThreshold(),
true),
booleanProperty(
FAULT_TOLERANT_EXECUTION_ADAPTIVE_BROADCAST_TO_PARTITIONED_JOIN_ENABLED,
"Adapt broadcast join to partitioned join based on runtime stats in fault tolerant execution",
queryManagerConfig.isFaultTolerantExecutionAdaptiveBroadcastToPartitionedJoinEnabled(),
false),
booleanProperty(
ADAPTIVE_PARTIAL_AGGREGATION_ENABLED,
"When enabled, partial aggregation might be adaptively turned off when it does not provide any performance gain",
Expand Down Expand Up @@ -1933,6 +1939,11 @@ public static DataSize getFaultTolerantExecutionAdaptiveJoinReorderingMinSizeThr
return session.getSystemProperty(FAULT_TOLERANT_EXECUTION_ADAPTIVE_JOIN_REORDERING_MIN_SIZE_THRESHOLD, DataSize.class);
}

public static boolean isFaultTolerantExecutionAdaptiveBroadcastToPartitionedJoinEnabled(Session session)
{
return session.getSystemProperty(FAULT_TOLERANT_EXECUTION_ADAPTIVE_BROADCAST_TO_PARTITIONED_JOIN_ENABLED, Boolean.class);
}

public static boolean isAdaptivePartialAggregationEnabled(Session session)
{
return session.getSystemProperty(ADAPTIVE_PARTIAL_AGGREGATION_ENABLED, Boolean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public class QueryManagerConfig
// above this threshold.
// TODO: Consider the cost of restarting the stage as part of adaptive planning.
private DataSize faultTolerantExecutionAdaptiveJoinReorderingMinSizeThreshold = DataSize.of(5, GIGABYTE);
private boolean faultTolerantExecutionAdaptiveBroadcastToPartitionedJoinEnabled = true;

@Min(1)
public int getScheduleSplitBatchSize()
Expand Down Expand Up @@ -1183,4 +1184,17 @@ public QueryManagerConfig setFaultTolerantExecutionAdaptiveJoinReorderingMinSize
this.faultTolerantExecutionAdaptiveJoinReorderingMinSizeThreshold = faultTolerantExecutionAdaptiveJoinReorderingMinSizeThreshold;
return this;
}

public boolean isFaultTolerantExecutionAdaptiveBroadcastToPartitionedJoinEnabled()
{
return faultTolerantExecutionAdaptiveBroadcastToPartitionedJoinEnabled;
}

@Config("fault-tolerant-execution-adaptive-broadcast-to-partitioned-join-enabled")
@ConfigDescription("Adapt broadcast join to partitioned join based on runtime stats in fault tolerant execution")
public QueryManagerConfig setFaultTolerantExecutionAdaptiveBroadcastToPartitionedJoinEnabled(boolean faultTolerantExecutionAdaptiveBroadcastToPartitionedJoinEnabled)
{
this.faultTolerantExecutionAdaptiveBroadcastToPartitionedJoinEnabled = faultTolerantExecutionAdaptiveBroadcastToPartitionedJoinEnabled;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
import static io.trino.sql.planner.AdaptivePlanner.ExchangeSourceId;
import static io.trino.sql.planner.SchedulingOrderVisitor.scheduleOrder;
import static io.trino.sql.planner.SystemPartitioningHandle.COORDINATOR_DISTRIBUTION;
import static io.trino.sql.planner.SystemPartitioningHandle.FIXED_ARBITRARY_DISTRIBUTION;
import static io.trino.sql.planner.SystemPartitioningHandle.FIXED_BROADCAST_DISTRIBUTION;
import static io.trino.sql.planner.SystemPartitioningHandle.FIXED_HASH_DISTRIBUTION;
import static io.trino.sql.planner.SystemPartitioningHandle.SCALED_WRITER_HASH_DISTRIBUTION;
import static io.trino.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION;
Expand Down Expand Up @@ -484,8 +486,12 @@ public PlanNode visitRemoteSource(RemoteSourceNode node, RewriteContext<Fragment
else if (node.getExchangeType() == ExchangeNode.Type.REPARTITION) {
for (SubPlan child : completedChildren) {
PartitioningScheme partitioningScheme = child.getFragment().getOutputPartitioningScheme();
PartitioningHandle handle = partitioningScheme.getPartitioning().getHandle();
if (handle.equals(FIXED_BROADCAST_DISTRIBUTION)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@losipiuk Can you take a look at this? This seems hacky but I'm not sure what's the best way to do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root cause of that is that handle not only describes how data is distributed, but also how it is consumed, which is not important if you look at fragment output.
But I do not see an easy way out of that without turning lot's of things around.

Maybe this is the best we can get.

Can you explain more the proposed change with extra PlanNode which can be used for adaptive planning in place of RemoteSourceNode. How does that simplify things?

cc: @martint

Copy link
Member Author

@gaurav8297 gaurav8297 Sep 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to solve the problem by introducing a new plan node specifically for the AdaptivePlan source. Instead of using RemoteSourceNode, we can create a new node that includes additional information like partitionHandle, which can be used during the PlanFragmenter. This extra information would be added through Adaptive planner rules. By doing this, we eliminate the need for an if condition, simplifying the PlanFragmenter code.

Additionally, currently, we are using RemoteSourceNode during AdaptivePlanning which is not intended for that use case.

cc @martint @losipiuk

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - that sounds fine to me.

handle = FIXED_ARBITRARY_DISTRIBUTION;
}
context.get().setDistribution(
partitioningScheme.getPartitioning().getHandle(),
handle,
partitioningScheme.getPartitionCount(),
metadata,
session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.trino.sql.planner.iterative.IterativeOptimizer;
import io.trino.sql.planner.iterative.Rule;
import io.trino.sql.planner.iterative.RuleStats;
import io.trino.sql.planner.iterative.rule.AdaptiveBroadcastToPartitionedJoin;
import io.trino.sql.planner.iterative.rule.AdaptiveReorderPartitionedJoin;
import io.trino.sql.planner.iterative.rule.AddDynamicFilterSource;
import io.trino.sql.planner.iterative.rule.AddExchangesBelowPartialAggregationOverGroupIdRuleSet;
Expand Down Expand Up @@ -1044,7 +1045,9 @@ public PlanOptimizers(
ruleStats,
statsCalculator,
costCalculator,
ImmutableSet.of(new AdaptiveReorderPartitionedJoin(metadata))));
ImmutableSet.of(
new AdaptiveReorderPartitionedJoin(metadata),
new AdaptiveBroadcastToPartitionedJoin(costComparator, taskCountEstimator))));
this.adaptivePlanOptimizers = adaptivePlanOptimizers.build();
}

Expand Down
Loading
Loading