[BugFix] TableFunction not use low cardinality optimization (#62466)

Signed-off-by: satanson <ranpanf@gmail.com>
(cherry picked from commit 1ad0f4683e)
Signed-off-by: satanson <ranpanf@gmail.com>
This commit is contained in:
satanson 2025-08-29 10:25:00 +08:00
parent 440122c1d5
commit aad2c0ee7a
No known key found for this signature in database
3 changed files with 29 additions and 0 deletions

View File

@ -116,6 +116,8 @@ public class DecodeCollector extends OptExpressionVisitor<DecodeInfo, DecodeInfo
private final Map<Integer, List<CallOperator>> stringAggregateExpressions = Maps.newHashMap();
private final Map<Integer, Integer> tableFunctionDependencies = Maps.newHashMap();
private final Map<Integer, ScalarOperator> stringRefToDefineExprMap = Maps.newHashMap();
// string column use counter, 0 meanings decoded immediately after it was generated.
@ -180,6 +182,10 @@ public class DecodeCollector extends OptExpressionVisitor<DecodeInfo, DecodeInfo
}
}
});
this.tableFunctionDependencies.forEach((k, v) -> {
dependencyStringIds.computeIfAbsent(v, x -> Sets.newHashSet()).add(k);
});
// build relation groups. The same closure is built into the same group
// eg:
// 1 -> (2, 3)
@ -523,6 +529,7 @@ public class DecodeCollector extends OptExpressionVisitor<DecodeInfo, DecodeInfo
stringRefToDefineExprMap.put(unnestOutput.getId(), unnestInput);
expressionStringRefCounter.put(unnestOutput.getId(), 1);
info.outputStringColumns.union(unnestOutput);
tableFunctionDependencies.put(unnestInput.getId(), unnestOutput.getId());
}
}
return info;

View File

@ -1056,4 +1056,25 @@ public class ReplayFromDumpTest extends ReplayFromDumpTestBase {
}
}
@Test
public void testUnnestLowCardinalityOptimization() throws Exception {
try {
FeConstants.USE_MOCK_DICT_MANAGER = true;
String dumpString = getDumpInfoFromFile("query_dump/unnest_low_cardinality_optimization");
QueryDumpInfo queryDumpInfo = getDumpInfoFromJson(dumpString);
Pair<QueryDumpInfo, String> replayPair = getPlanFragment(dumpString, queryDumpInfo.getSessionVariable(),
TExplainLevel.NORMAL);
String plan = replayPair.second;
Assert.assertTrue(plan, plan.contains(" 30:Project\n" +
" | <slot 113> : 113: mock_field_111\n" +
" | <slot 278> : lower(142: jl_str)\n" +
" | \n" +
" 29:TableValueFunction\n" +
" | tableFunctionName: unnest\n" +
" | columns: [unnest]\n" +
" | returnTypes: [VARCHAR(65533)]"));
} finally {
FeConstants.USE_MOCK_DICT_MANAGER = false;
}
}
}

File diff suppressed because one or more lines are too long