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

jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new e60408ce67c Fix last cache bugs because init the time last cache but 
not updated in later process
e60408ce67c is described below

commit e60408ce67c6cb11f7d16998ee390f1bff1b8d64
Author: Weihao Li <[email protected]>
AuthorDate: Tue Sep 16 10:58:22 2025 +0800

    Fix last cache bugs because init the time last cache but not updated in 
later process
---
 .../plan/planner/TableOperatorGenerator.java       | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/TableOperatorGenerator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/TableOperatorGenerator.java
index 88c4cc4b982..08be6377cb7 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/TableOperatorGenerator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/TableOperatorGenerator.java
@@ -279,6 +279,7 @@ import javax.validation.constraints.NotNull;
 import java.io.File;
 import java.util.AbstractMap;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -3126,18 +3127,19 @@ public class TableOperatorGenerator extends 
PlanVisitor<Operator, LocalExecution
       // LAST_VALUES optimize
       lastValuesCacheResults = new ArrayList<>();
       int measurementSize = parameter.getMeasurementColumnNames().size();
+      // We don't init time if the last cache will not be updated in process 
of operator
+      boolean needInitTime =
+          parameter.getTableAggregators().stream()
+              .anyMatch(
+                  aggregator ->
+                      aggregator.getAccumulator() instanceof 
LastDescAccumulator
+                          && !((LastDescAccumulator) 
aggregator.getAccumulator())
+                              .isMeasurementColumn());
       // When we need last cache of Time column if:
       // 1. query is group by (we need last cache of Time to help judge if 
there is no data in
       // device)
       // 2. last(time), last(device) or last(attribute) occurs
-      boolean needTime =
-          !node.getGroupingKeys().isEmpty()
-              || parameter.getTableAggregators().stream()
-                  .anyMatch(
-                      aggregator ->
-                          aggregator.getAccumulator() instanceof 
LastDescAccumulator
-                              && !((LastDescAccumulator) 
aggregator.getAccumulator())
-                                  .isMeasurementColumn());
+      boolean needTime = !node.getGroupingKeys().isEmpty() || needInitTime;
       String[] targetColumns;
 
       if (needTime) {
@@ -3198,7 +3200,9 @@ public class TableOperatorGenerator extends 
PlanVisitor<Operator, LocalExecution
               .initOrInvalidateLastCache(
                   node.getQualifiedObjectName().getDatabaseName(),
                   deviceEntry.getDeviceID(),
-                  targetColumns,
+                  needInitTime
+                      ? targetColumns
+                      : Arrays.copyOfRange(targetColumns, 0, 
targetColumns.length - 1),
                   false);
         } else {
           hitCachesIndexes.add(i);

Reply via email to