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

[BugFix] Fix wrong plan in max(count(distinct)) when enable lowcardinality #53403

Merged
merged 1 commit into from
Dec 2, 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 @@ -665,7 +665,9 @@ private PhysicalHashAggregateOperator rewriteAggOperator(PhysicalHashAggregateOp
if (canApplyDictDecodeOpt) {
CallOperator oldCall = kv.getValue();
int columnId = kv.getValue().getUsedColumns().getFirstId();
if (context.needRewriteMultiCountDistinctColumns.contains(columnId)) {
final String fnName = kv.getValue().getFnName();
if (context.needRewriteMultiCountDistinctColumns.contains(columnId)
&& fnName.equals(FunctionSet.MULTI_DISTINCT_COUNT)) {
// we only need rewrite TFunction
Type[] newTypes = new Type[] {ID_TYPE};
AggregateFunction newFunction =
Expand All @@ -682,7 +684,6 @@ private PhysicalHashAggregateOperator rewriteAggOperator(PhysicalHashAggregateOp

List<ScalarOperator> newArguments = Collections.singletonList(dictColumn);
Type[] newTypes = newArguments.stream().map(ScalarOperator::getType).toArray(Type[]::new);
String fnName = kv.getValue().getFnName();
AggregateFunction newFunction =
(AggregateFunction) Expr.getBuiltinFunction(kv.getValue().getFnName(), newTypes,
Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ public void testDecodeNodeRewriteMultiCountDistinct() throws Exception {
plan = getFragmentPlan(sql);
Assert.assertTrue(plan.contains(" multi_distinct_count(11: S_ADDRESS), " +
"multi_distinct_count(12: S_COMMENT)"));

sql = "select max(a) from (select count(distinct S_ADDRESS) a from supplier)t";
plan = getFragmentPlan(sql);
assertContains(plan, "multi_distinct_count(9: count)");

connectContext.getSessionVariable().setNewPlanerAggStage(3);
sql = "select max(S_ADDRESS), count(distinct S_ADDRESS) from supplier group by S_ADDRESS;";
plan = getFragmentPlan(sql);
Expand Down
Loading