8000 [Enhancement] prefer two-phase plan for distinct aggregation in single node env by murphyatwork · Pull Request #60029 · StarRocks/starrocks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Enhancement] prefer two-phase plan for distinct aggregation in single node env #60029

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: main
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
9 changes: 9 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/qe/ConnectContext.java
10000
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,15 @@ public int getAliveComputeNumber() {
return globalStateMgr.getNodeMgr().getClusterInfo().getAliveComputeNodeNumber();
}

/**
* BackendNode + ComputeNode
*/
public int getAliveExecutionNodesNumber() {
return getAliveBackendNumber() +
(RunMode.isSharedDataMode() ?
getGlobalStateMgr().getNodeMgr().getClusterInfo().getAliveComputeNodeNumber() : 0);
}

public void setPending(boolean pending) {
isPending = pending;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.starrocks.catalog.AggregateFunction;
import com.starrocks.catalog.FunctionSet;
import com.starrocks.catalog.Type;
import com.starrocks.common.FeConstants;
import com.starrocks.qe.ConnectContext;
import com.starrocks.sql.optimizer.OptExpression;
import com.starrocks.sql.optimizer.operator.AggType;
Expand Down Expand Up @@ -99,6 +100,13 @@ protected Type getIntermediateType(CallOperator aggregation) {
return af.getIntermediateType() == null ? af.getReturnType() : af.getIntermediateType();
}

/**
* If there's only one BE node, splitting into multi-phase has no benefit but only overhead
*/
private static boolean isSingleNodeExecution(ConnectContext context) {
return context.getAliveExecutionNodesNumber() == 1;
}

protected boolean isSuitableForTwoStageDistinct(OptExpression input, LogicalAggregationOperator operator,
List<ColumnRefOperator> distinctColumns) {
if (distinctColumns.isEmpty()) {
Expand All @@ -115,6 +123,10 @@ protected boolean isSuitableForTwoStageDistinct(OptExpression input, LogicalAggr
return true;
}

if (isSingleNodeExecution(ConnectContext.get()) && !FeConstants.runningUnitTest) {
return true;
}

return CollectionUtils.isNotEmpty(operator.getGroupingKeys())
&& aggMode == AUTO.ordinal()
&& isTwoStageMoreEfficient(input, distinctColumns);
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
The ConnectContext.get() method call assumes that a valid context instance will always be returned, which might not be the case. If it returns null, this would lead to a NullPointerException.

You can modify the code like this:

+        ConnectContext context = ConnectContext.get();
+        if (context != null && isSingleNodeExecution(context)) {
+            return true;
+        }

Expand Down
Loading
0