Skip to content

Commit

Permalink
[BugFix] Fix wrong plan in max(count(distinct)) when enable lowcardin…
Browse files Browse the repository at this point in the history
…ality (#53403)

Signed-off-by: stdpain <[email protected]>
(cherry picked from commit aac4a21)
  • Loading branch information
stdpain authored and mergify[bot] committed Dec 2, 2024
1 parent ac3aef8 commit 1fbd88f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,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 @@ -681,7 +683,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

0 comments on commit 1fbd88f

Please sign in to comment.