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 ea3cff508bf Memory estimate refine for TableScanOperator (#17230)
ea3cff508bf is described below

commit ea3cff508bf06776f020eb60974bb45cb475b054
Author: Jackie Tien <[email protected]>
AuthorDate: Sun Mar 1 15:01:29 2026 +0800

    Memory estimate refine for TableScanOperator (#17230)
---
 .../relational/AbstractTableScanOperator.java      |  10 +-
 .../source/relational/TableScanOperatorTest.java   | 113 +++++++++++++++++++++
 2 files changed, 119 insertions(+), 4 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/AbstractTableScanOperator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/AbstractTableScanOperator.java
index 151dd6f3f25..fa6a7093b58 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/AbstractTableScanOperator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/AbstractTableScanOperator.java
@@ -111,11 +111,11 @@ public abstract class AbstractTableScanOperator extends 
AbstractSeriesScanOperat
     this.currentDeviceIndex = 0;
     this.operatorContext.recordSpecifiedInfo(CURRENT_DEVICE_INDEX_STRING, 
Integer.toString(0));
 
+    // allSensors include time and all field columns
     this.maxReturnSize =
         Math.min(
             maxReturnSize,
-            (1L + parameter.columnsIndexArray.length)
-                * 
TSFileDescriptor.getInstance().getConfig().getPageSizeInByte());
+            allSensors.size() * 
TSFileDescriptor.getInstance().getConfig().getPageSizeInByte());
     this.maxTsBlockLineNum = parameter.maxTsBlockLineNum;
 
     constructAlignedSeriesScanUtil();
@@ -228,8 +228,10 @@ public abstract class AbstractTableScanOperator extends 
AbstractSeriesScanOperat
 
   @Override
   public long calculateMaxPeekMemory() {
-    return (1L + columnsIndexArray.length)
-        * TSFileDescriptor.getInstance().getConfig().getPageSizeInByte();
+    // allSensors have included time column and all field columns
+    return Math.max(
+        maxReturnSize,
+        allSensors.size() * 
TSFileDescriptor.getInstance().getConfig().getPageSizeInByte());
   }
 
   @Override
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/TableScanOperatorTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/TableScanOperatorTest.java
new file mode 100644
index 00000000000..d0e644eec96
--- /dev/null
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/TableScanOperatorTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.queryengine.execution.operator.source.relational;
+
+import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
+import org.apache.iotdb.db.queryengine.execution.operator.OperatorContext;
+import 
org.apache.iotdb.db.queryengine.execution.operator.source.relational.AbstractTableScanOperator.AbstractTableScanOperatorParameter;
+import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.SeriesScanOptions;
+import org.apache.iotdb.db.queryengine.plan.relational.metadata.ColumnSchema;
+import org.apache.iotdb.db.queryengine.plan.relational.metadata.DeviceEntry;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.type.TypeFactory;
+import org.apache.tsfile.write.schema.IMeasurementSchema;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+
+public class TableScanOperatorTest {
+
+  @Test
+  public void testCalculateMaxPeekMemory() {
+    OperatorContext operatorContext = Mockito.mock(OperatorContext.class);
+
+    PlanNodeId sourceId = new PlanNodeId("test");
+
+    List<ColumnSchema> columnSchemas =
+        Arrays.asList(
+            new ColumnSchema(
+                "time", TypeFactory.getType(TSDataType.INT64), false, 
TsTableColumnCategory.TIME),
+            new ColumnSchema(
+                "tag1", TypeFactory.getType(TSDataType.STRING), false, 
TsTableColumnCategory.TAG),
+            new ColumnSchema(
+                "attr1",
+                TypeFactory.getType(TSDataType.STRING),
+                false,
+                TsTableColumnCategory.ATTRIBUTE),
+            new ColumnSchema(
+                "field1",
+                TypeFactory.getType(TSDataType.BOOLEAN),
+                false,
+                TsTableColumnCategory.FIELD),
+            new ColumnSchema(
+                "field2",
+                TypeFactory.getType(TSDataType.INT32),
+                false,
+                TsTableColumnCategory.FIELD));
+
+    int[] columnsIndexArray = new int[] {0, 1, 2, 3, 4};
+    List<DeviceEntry> deviceEntries = Collections.emptyList();
+    Ordering scanOrder = Ordering.ASC;
+    SeriesScanOptions seriesScanOptions = 
Mockito.mock(SeriesScanOptions.class);
+    List<String> measurementColumnNames = Arrays.asList("field1", "field2");
+    List<IMeasurementSchema> measurementSchemas = new ArrayList<>();
+
+    Set<String> allSensors = new HashSet<>(measurementColumnNames);
+    allSensors.add("");
+    AbstractTableScanOperatorParameter parameter =
+        new AbstractTableScanOperatorParameter(
+            allSensors,
+            operatorContext,
+            sourceId,
+            columnSchemas,
+            columnsIndexArray,
+            deviceEntries,
+            scanOrder,
+            seriesScanOptions,
+            measurementColumnNames,
+            measurementSchemas,
+            1000);
+
+    TableScanOperator operator = new TableScanOperator(parameter);
+
+    long maxReturnSize =
+        Math.min(
+            
TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes(),
+            (1L + 2) * 
TSFileDescriptor.getInstance().getConfig().getPageSizeInByte());
+    long expectedMaxPeekMemory =
+        Math.max(
+            maxReturnSize,
+            (1L + 2) * 
TSFileDescriptor.getInstance().getConfig().getPageSizeInByte());
+
+    assertEquals(expectedMaxPeekMemory, operator.calculateMaxPeekMemory());
+  }
+}

Reply via email to