hello-stephen commented on code in PR #70223:
URL: https://github.com/apache/doris/pull/70223#discussion_r4767078079


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/AggStateType.java:
##########
@@ -101,14 +190,16 @@ public String getFunctionName() {
     @Override
     public Type toCatalogDataType() {
         List<Type> types = 
subTypes.stream().map(DataType::toCatalogDataType).collect(Collectors.toList());
-        return new org.apache.doris.catalog.AggStateType(functionName, 
returnNullable, types, subTypeNullables);
+        return new org.apache.doris.catalog.AggStateType(functionName, 
returnNullable, types, subTypeNullables,
+                resultTypeInferredFromLegacy || resultType == null ? null : 
resultType.toCatalogDataType());

Review Comment:
   [P2] Avoid exponential expansion of nested state result types
   
   With `enable_agg_state=true`, consider the supported scalar plan 
`Project(S20) -> OneRowRelation`, where `S0 = sum_state(CAST(1 AS INT))` and 
`S(n+1) = any_value_state(Sn)`. ANY_VALUE returns its argument type, so each 
wrapper keeps the inner state in both `subTypes[0]` and `resultType`. This 
method now converts those branches independently: 20 wrappers construct 
2,097,151 catalog `AggStateType` objects, versus 21 before this change, and 
Thrift serialization expands both branches again. The expression depth limit is 
3000 and `Type.exceedsMaxNestingDepth()` treats AGG_STATE as a leaf, so neither 
prevents this short query from consuming exponential FE planning time and 
memory. Avoid recursively expanding pass-through result signatures twice, or 
bound resolved signature complexity before conversion, and cover nested growth 
in a regression.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to