19
19
20
20
import org .apache .doris .nereids .memo .GroupExpression ;
21
21
import org .apache .doris .nereids .properties .LogicalProperties ;
22
+ import org .apache .doris .nereids .properties .OrderKey ;
22
23
import org .apache .doris .nereids .properties .PhysicalProperties ;
23
24
import org .apache .doris .nereids .properties .RequireProperties ;
24
25
import org .apache .doris .nereids .properties .RequirePropertiesSupplier ;
@@ -60,6 +61,9 @@ public class PhysicalHashAggregate<CHILD_TYPE extends Plan> extends PhysicalUnar
60
61
61
62
private final RequireProperties requireProperties ;
62
63
64
+ // only used in post processor
65
+ private TopnPushInfo topnPushInfo = null ;
66
+
63
67
public PhysicalHashAggregate (List <Expression > groupByExpressions , List <NamedExpression > outputExpressions ,
64
68
AggregateParam aggregateParam , boolean maybeUsingStream , LogicalProperties logicalProperties ,
65
69
RequireProperties requireProperties , CHILD_TYPE child ) {
@@ -196,6 +200,7 @@ public String toString() {
196
200
"outputExpr" , outputExpressions ,
197
201
"partitionExpr" , partitionExpressions ,
198
202
"requireProperties" , requireProperties ,
203
+ "topnOpt" , topnPushInfo != null ,
199
204
"stats" , statistics
200
205
);
201
206
}
@@ -231,19 +236,22 @@ public PhysicalHashAggregate<Plan> withChildren(List<Plan> children) {
231
236
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions , partitionExpressions ,
232
237
aggregateParam , maybeUsingStream , groupExpression , getLogicalProperties (),
233
238
requireProperties , physicalProperties , statistics ,
234
- children .get (0 ));
239
+ children .get (0 ))
240
+ .setTopnPushInfo (topnPushInfo );
235
241
}
236
242
237
243
public PhysicalHashAggregate <CHILD_TYPE > withPartitionExpressions (List <Expression > partitionExpressions ) {
238
244
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions ,
239
245
Optional .ofNullable (partitionExpressions ), aggregateParam , maybeUsingStream ,
240
- Optional .empty (), getLogicalProperties (), requireProperties , child ());
246
+ Optional .empty (), getLogicalProperties (), requireProperties , child ())
247
+ .setTopnPushInfo (topnPushInfo );
241
248
}
242
249
243
250
@ Override
244
251
public PhysicalHashAggregate <CHILD_TYPE > withGroupExpression (Optional <GroupExpression > groupExpression ) {
245
252
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions , partitionExpressions ,
246
- aggregateParam , maybeUsingStream , groupExpression , getLogicalProperties (), requireProperties , child ());
253
+ aggregateParam , maybeUsingStream , groupExpression , getLogicalProperties (), requireProperties , child ())
254
+ .setTopnPushInfo (topnPushInfo );
247
255
}
248
256
249
257
@ Override
@@ -252,7 +260,7 @@ public Plan withGroupExprLogicalPropChildren(Optional<GroupExpression> groupExpr
252
260
Preconditions .checkArgument (children .size () == 1 );
253
261
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions , partitionExpressions ,
254
262
aggregateParam , maybeUsingStream , groupExpression , logicalProperties .get (),
255
- requireProperties , children .get (0 ));
263
+ requireProperties , children .get (0 )). setTopnPushInfo ( topnPushInfo ) ;
256
264
}
257
265
258
266
@ Override
@@ -261,21 +269,21 @@ public PhysicalHashAggregate<CHILD_TYPE> withPhysicalPropertiesAndStats(Physical
261
269
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions , partitionExpressions ,
262
270
aggregateParam , maybeUsingStream , groupExpression , getLogicalProperties (),
263
271
requireProperties , physicalProperties , statistics ,
264
- child ());
272
+ child ()). setTopnPushInfo ( topnPushInfo ) ;
265
273
}
266
274
267
275
@ Override
268
276
public PhysicalHashAggregate <CHILD_TYPE > withAggOutput (List <NamedExpression > newOutput ) {
269
277
return new PhysicalHashAggregate <>(groupByExpressions , newOutput , partitionExpressions ,
270
278
aggregateParam , maybeUsingStream , Optional .empty (), getLogicalProperties (),
271
- requireProperties , physicalProperties , statistics , child ());
279
+ requireProperties , physicalProperties , statistics , child ()). setTopnPushInfo ( topnPushInfo ) ;
272
280
}
273
281
274
282
public <C extends Plan > PhysicalHashAggregate <C > withRequirePropertiesAndChild (
275
283
RequireProperties requireProperties , C newChild ) {
276
284
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions , partitionExpressions ,
277
285
aggregateParam , maybeUsingStream , Optional .empty (), getLogicalProperties (),
278
- requireProperties , physicalProperties , statistics , newChild );
286
+ requireProperties , physicalProperties , statistics , newChild ). setTopnPushInfo ( topnPushInfo ) ;
279
287
}
280
288
281
289
@ Override
@@ -299,4 +307,26 @@ public PhysicalHashAggregate<CHILD_TYPE> resetLogicalProperties() {
299
307
requireProperties , physicalProperties , statistics ,
300
308
child ());
301
309
}
310
+
311
+ /**
312
+ * used to push limit down to localAgg
313
+ */
314
+ public static class TopnPushInfo {
315
+ public List <OrderKey > orderkeys ;
316
+ public long limit ;
317
+
318
+ public TopnPushInfo (List <OrderKey > orderkeys , long limit ) {
319
+ this .orderkeys = ImmutableList .copyOf (orderkeys );
320
+ this .limit = limit ;
321
+ }
322
+ }
323
+
324
+ public TopnPushInfo getTopnPushInfo () {
325
+ return topnPushInfo ;
326
+ }
327
+
328
+ public PhysicalHashAggregate <CHILD_TYPE > setTopnPushInfo (TopnPushInfo topnPushInfo ) {
329
+ this .topnPushInfo = topnPushInfo ;
330
+ return this ;
331
+ }
302
332
}
0 commit comments