This is an automated email from the ASF dual-hosted git repository.

caogaofei pushed a commit to branch beyyes/agg_plan_device_cross_region
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 1fd1dedc2e845ee44d6ee766fef9bf7080cc4413
Author: Beyyes <[email protected]>
AuthorDate: Thu Feb 29 22:01:10 2024 +0800

    add memory calc logic
---
 .../process/AggregationMergeSortOperator.java        | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/AggregationMergeSortOperator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/AggregationMergeSortOperator.java
index 4b0d959c882..096c242fb66 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/AggregationMergeSortOperator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/AggregationMergeSortOperator.java
@@ -245,7 +245,16 @@ public class AggregationMergeSortOperator extends 
AbstractConsumeAllOperator {
 
   @Override
   public long calculateMaxPeekMemory() {
-    return 0;
+    long maxPeekMemory = 
TSFileDescriptor.getInstance().getConfig().getPageSizeInByte();
+    // inputTsBlocks will cache all the tsBlocks returned by inputOperators
+    for (Operator operator : children) {
+      maxPeekMemory += operator.calculateMaxReturnSize();
+      maxPeekMemory += operator.calculateRetainedSizeAfterCallingNext();
+    }
+    for (Operator operator : children) {
+      maxPeekMemory = Math.max(maxPeekMemory, 
operator.calculateMaxPeekMemory());
+    }
+    return Math.max(maxPeekMemory, calculateMaxReturnSize());
   }
 
   @Override
@@ -255,7 +264,14 @@ public class AggregationMergeSortOperator extends 
AbstractConsumeAllOperator {
 
   @Override
   public long calculateRetainedSizeAfterCallingNext() {
-    return 0;
+    long currentRetainedSize = 0;
+    long minChildReturnSize = Long.MAX_VALUE;
+    for (Operator child : children) {
+      long maxReturnSize = child.calculateMaxReturnSize();
+      minChildReturnSize = Math.min(minChildReturnSize, maxReturnSize);
+      currentRetainedSize += (maxReturnSize + 
child.calculateRetainedSizeAfterCallingNext());
+    }
+    return currentRetainedSize - minChildReturnSize;
   }
 
   private boolean isInputNotEmpty(int index) {

Reply via email to