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

ycycse pushed a commit to branch ycy/memoryIssueFix
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/ycy/memoryIssueFix by this 
push:
     new a1e2f8f1b51 fix: consider startTime
a1e2f8f1b51 is described below

commit a1e2f8f1b511d4c7d755ea7630eb9317e9f6d3c0
Author: ycycse <[email protected]>
AuthorDate: Wed Jun 12 21:12:48 2024 +0800

    fix: consider startTime
---
 .../iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java   | 13 +++++++++----
 .../org/apache/iotdb/commons/utils/TimePartitionUtils.java  |  4 ++--
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
index 08d2958fe9e..d8f822257dc 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
@@ -2072,7 +2072,9 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
     }
 
     List<TTimePartitionSlot> result = new ArrayList<>();
-    reserveMemoryForTimePartitionSlot(timeRangeList.get(index).getMax(), 
context);
+    TimeRange currentTimeRange = timeRangeList.get(index);
+    reserveMemoryForTimePartitionSlot(
+        currentTimeRange.getMax(), currentTimeRange.getMin(), context);
     while (index < size) {
       long curLeft = timeRangeList.get(index).getMin();
       long curRight = timeRangeList.get(index).getMax();
@@ -2089,7 +2091,9 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
       } else {
         index++;
         if (index < size) {
-          reserveMemoryForTimePartitionSlot(timeRangeList.get(index).getMax(), 
context);
+          currentTimeRange = timeRangeList.get(index);
+          reserveMemoryForTimePartitionSlot(
+              currentTimeRange.getMax(), currentTimeRange.getMin(), context);
         }
       }
     }
@@ -2106,8 +2110,9 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
     return new Pair<>(result, new Pair<>(needLeftAll, needRightAll));
   }
 
-  private static void reserveMemoryForTimePartitionSlot(long maxTime, 
MPPQueryContext context) {
-    long size = TimePartitionUtils.getTimePartitionSize(maxTime);
+  private static void reserveMemoryForTimePartitionSlot(
+      long maxTime, long minTime, MPPQueryContext context) {
+    long size = TimePartitionUtils.getEstimateTimePartitionSize(minTime, 
maxTime);
     context.reserveMemoryForFrontEnd(
         RamUsageEstimator.shallowSizeOfInstance(TTimePartitionSlot.class) * 
size);
   }
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TimePartitionUtils.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TimePartitionUtils.java
index f1d840b6981..b0339cb6822 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TimePartitionUtils.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TimePartitionUtils.java
@@ -83,7 +83,7 @@ public class TimePartitionUtils {
     TimePartitionUtils.timePartitionInterval = timePartitionInterval;
   }
 
-  public static long getTimePartitionSize(long endTime) {
-    return endTime / timePartitionInterval + 1;
+  public static long getEstimateTimePartitionSize(long startTime, long 
endTime) {
+    return (endTime - startTime) / timePartitionInterval + 1;
   }
 }

Reply via email to