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

JackieTien97 pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/dev/1.3 by this push:
     new 6636db4a8db [to dev/1.3] Prevent aligned LAST query from hanging with 
time filter (#18214)
6636db4a8db is described below

commit 6636db4a8dbf87ed8f814f3daec5edb80a31a558
Author: shuwenwei <[email protected]>
AuthorDate: Wed Jul 15 16:57:17 2026 +0800

    [to dev/1.3] Prevent aligned LAST query from hanging with time filter 
(#18214)
---
 .../IoTDBAlignedLastQueryWithTimeFilterIT.java     | 88 ++++++++++++++++++++++
 .../metadata/DiskAlignedChunkMetadataLoader.java   |  4 +-
 2 files changed, 89 insertions(+), 3 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedLastQueryWithTimeFilterIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedLastQueryWithTimeFilterIT.java
new file mode 100644
index 00000000000..5edca80c607
--- /dev/null
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedLastQueryWithTimeFilterIT.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.it.aligned;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import static org.junit.Assert.assertFalse;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBAlignedLastQueryWithTimeFilterIT {
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv()
+        .getConfig()
+        .getCommonConfig()
+        .setEnableLastCache(false)
+        .setEnableSeqSpaceCompaction(false)
+        .setEnableUnseqSpaceCompaction(false)
+        .setEnableCrossSpaceCompaction(false)
+        .setTargetChunkPointNum(2);
+    EnvFactory.getEnv().initClusterEnvironment();
+
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("create database root.last_query_filter");
+      statement.execute(
+          "create aligned timeseries root.last_query_filter.d1("
+              + "s1 INT32 encoding=RLE, s2 INT32 encoding=RLE, s3 INT32 
encoding=RLE)");
+      // The queried sensors only have values in the first chunk, while s3 
extends the aligned
+      // time-series statistics into the query's time range.
+      statement.execute("insert into root.last_query_filter.d1(time,s1,s2) 
aligned values(1,1,11)");
+      statement.execute("insert into root.last_query_filter.d1(time,s1,s2) 
aligned values(2,2,22)");
+      statement.execute("insert into root.last_query_filter.d1(time,s3) 
aligned values(100,100)");
+      statement.execute("insert into root.last_query_filter.d1(time,s3) 
aligned values(101,101)");
+      statement.execute("flush");
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanClusterEnvironment();
+  }
+
+  @Test
+  public void testLastQuerySkipsFilteredSingletonAlignedChunk() throws 
Exception {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.setQueryTimeout(10);
+      try (ResultSet resultSet =
+          statement.executeQuery(
+              "select last s1,s2 from root.last_query_filter.d1 "
+                  + "where time >= 100 and time <= 101")) {
+        assertFalse(resultSet.next());
+      }
+    }
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/metadata/DiskAlignedChunkMetadataLoader.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/metadata/DiskAlignedChunkMetadataLoader.java
index 3d17c955d12..67c783e07c1 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/metadata/DiskAlignedChunkMetadataLoader.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/metadata/DiskAlignedChunkMetadataLoader.java
@@ -75,9 +75,7 @@ public class DiskAlignedChunkMetadataLoader implements 
IChunkMetadataLoader {
       List<AlignedChunkMetadata> alignedChunkMetadataList =
           ((AlignedTimeSeriesMetadata) 
timeSeriesMetadata).getCopiedChunkMetadataList();
 
-      // when alignedChunkMetadataList.size() == 1, it means that the chunk 
statistics is same as
-      // the time series metadata, so we don't need to filter it again.
-      if (alignedChunkMetadataList.size() > 1) {
+      if (!alignedChunkMetadataList.isEmpty()) {
         // remove not satisfied ChunkMetaData
         final long t2 = System.nanoTime();
         alignedChunkMetadataList.removeIf(

Reply via email to