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

Signed-off-by: stdpain <[email protected]>
  • Loading branch information
stdpain committed Dec 2, 2024
1 parent fe38253 commit c1e812e
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 @@ -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

0 comments on commit c1e812e

Please sign in to comment.