JackieTien97 commented on code in PR #16882:
URL: https://github.com/apache/iotdb/pull/16882#discussion_r2618868840


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/read/resp/info/impl/ShowDevicesResult.java:
##########
@@ -137,4 +139,24 @@ public boolean equals(final Object o) {
   public int hashCode() {
     return Objects.hash(path, isAligned, templateId);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = 
RamUsageEstimator.shallowSizeOfInstance(ShowDevicesResult.class);
+    if (path != null) {
+      size += RamUsageEstimator.sizeOf(path);
+    }
+    if (isAligned != null) {
+      size += RamUsageEstimator.shallowSizeOfInstance(Boolean.class);

Review Comment:
   ```suggestion
         size += 1;
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/read/resp/info/impl/ShowDevicesResult.java:
##########
@@ -137,4 +139,24 @@ public boolean equals(final Object o) {
   public int hashCode() {
     return Objects.hash(path, isAligned, templateId);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = 
RamUsageEstimator.shallowSizeOfInstance(ShowDevicesResult.class);

Review Comment:
   why not put it as a final static field?



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AstMemoryEstimationHelper.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.plan.relational.sql.ast;
+
+import org.apache.tsfile.utils.Accountable;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import javax.annotation.Nullable;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Helper class for estimating memory usage of AST nodes. This class provides 
utility methods that
+ * can be used by Node subclasses to calculate their memory footprint.
+ */
+public final class AstMemoryEstimationHelper {
+
+  public static final long OPTIONAL_INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(Optional.class);
+
+  public static final long NODE_LOCATION_INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(NodeLocation.class);
+
+  private AstMemoryEstimationHelper() {
+    // hide the constructor
+  }
+
+  public static long getEstimatedSizeOfAccountableObject(@Nullable final 
Accountable accountable) {
+    return accountable == null ? 0 : accountable.ramBytesUsed();
+  }
+
+  public static long getEstimatedSizeOfString(@Nullable final String str) {
+    return str == null ? 0L : RamUsageEstimator.sizeOf(str);
+  }
+
+  public static long getEstimatedSizeOfByteArray(@Nullable final byte[] bytes) 
{
+    return bytes == null ? 0L : RamUsageEstimator.sizeOf(bytes);
+  }
+
+  public static long getShallowSizeOfList(@Nullable final List<?> list) {
+    return list == null ? 0L : RamUsageEstimator.shallowSizeOf(list);
+  }
+
+  public static long getEstimatedSizeOfNodeLocation(@Nullable final 
NodeLocation location) {
+    if (location != null) {
+      return OPTIONAL_INSTANCE_SIZE + NODE_LOCATION_INSTANCE_SIZE;

Review Comment:
   define a new constant to store `OPTIONAL_INSTANCE_SIZE + 
NODE_LOCATION_INSTANCE_SIZE`, no need to do this calculation each time.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateDB.java:
##########
@@ -54,4 +58,15 @@ public String toString() {
         .add("properties", properties)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (dbName != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(dbName);
+    }

Review Comment:
   ```suggestion
       size += AstMemoryEstimationHelper.getEstimatedSizeOfString(dbName);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ColumnDefinition.java:
##########
@@ -130,4 +134,21 @@ public String toString() {
         .add("comment", comment)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(name);
+    if (type != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(type);
+    }
+    if (charsetName != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(charsetName);
+    }
+    if (comment != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(comment);
+    }

Review Comment:
   ```suggestion
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(type);
       size += AstMemoryEstimationHelper.getEstimatedSizeOfString(charsetName);
       size += AstMemoryEstimationHelper.getEstimatedSizeOfString(comment);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AliasedRelation.java:
##########
@@ -109,4 +113,16 @@ public boolean shallowEquals(Node other) {
     return alias.equals(otherRelation.alias)
         && Objects.equals(columnNames, otherRelation.columnNames);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(relation);
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(alias);
+    if (columnNames != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(columnNames);
+    }

Review Comment:
   ```suggestion
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(columnNames);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/Columns.java:
##########
@@ -93,4 +96,14 @@ public TableExpressionType getExpressionType() {
   public void serialize(DataOutputStream stream) throws IOException {
     throw new UnsupportedOperationException("Columns should be expanded in 
Analyze stage");
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (pattern != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(pattern);
+    }

Review Comment:
   ```suggestion
       size += AstMemoryEstimationHelper.getEstimatedSizeOfString(pattern);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AsofJoinOn.java:
##########
@@ -160,4 +163,16 @@ public String toString() {
   public List<Node> getNodes() {
     return ImmutableList.of(expression, asofExpression);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = super.ramBytesUsed();
+    // Subtract JoinOn's INSTANCE_SIZE and add AsofJoinOn's INSTANCE_SIZE
+    size -= RamUsageEstimator.shallowSizeOfInstance(JoinOn.class);

Review Comment:
   no need to calculate each time, you can extract a method in super class 
which doesn't contains the JoinOn.class's shallowSize.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CountDevice.java:
##########
@@ -65,4 +69,29 @@ public <R, C> R accept(final AstVisitor<R, C> visitor, final 
C context) {
   public String toString() {
     return "CountDevice" + toStringContent();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(table);
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(where);
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfString(database);
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfString(tableName);
+    size += 
AstMemoryEstimationHelper.getShallowSizeOfList(tagDeterminedFilterList);
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(tagFuzzyPredicate);
+    size += AstMemoryEstimationHelper.getShallowSizeOfList(columnHeaderList);
+    if (getAttributeColumns() != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfStringList(getAttributeColumns());
+    }

Review Comment:
   ```suggestion
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfStringList(getAttributeColumns());
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateOrUpdateDevice.java:
##########
@@ -137,4 +141,27 @@ public String toString() {
         + attributeValueList
         + '}';
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfString(database);
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfString(table);
+    size += AstMemoryEstimationHelper.getShallowSizeOfList(deviceIdList);
+    for (Object[] deviceId : deviceIdList) {
+      if (deviceId != null) {
+        size +=
+            
AstMemoryEstimationHelper.getEstimatedSizeOfByteArray(deviceId.toString().getBytes());
+      }
+    }

Review Comment:
   ```suggestion
       for (Object[] deviceId : deviceIdList) {
         size += RamUsageEstimator.sizeOf((String[]) deviceId);
       }
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CurrentTime.java:
##########
@@ -110,4 +114,14 @@ public boolean shallowEquals(Node other) {
     CurrentTime otherNode = (CurrentTime) other;
     return (function == otherNode.function) && Objects.equals(precision, 
otherNode.precision);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (precision != null) {
+      size += RamUsageEstimator.shallowSizeOfInstance(Integer.class);

Review Comment:
   ```suggestion
         size += Integer.BYTES;
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateTable.java:
##########
@@ -123,4 +127,20 @@ public String toString() {
         .add("properties", properties)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += name == null ? 0L : name.ramBytesUsed();
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(elements);
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(properties);
+    if (charsetName != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(charsetName);
+    }
+    if (comment != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(comment);
+    }

Review Comment:
   ```suggestion
       size += AstMemoryEstimationHelper.getEstimatedSizeOfString(charsetName);
       size += AstMemoryEstimationHelper.getEstimatedSizeOfString(comment);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateOrUpdateDevice.java:
##########
@@ -137,4 +141,27 @@ public String toString() {
         + attributeValueList
         + '}';
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfString(database);
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfString(table);
+    size += AstMemoryEstimationHelper.getShallowSizeOfList(deviceIdList);
+    for (Object[] deviceId : deviceIdList) {
+      if (deviceId != null) {
+        size +=
+            
AstMemoryEstimationHelper.getEstimatedSizeOfByteArray(deviceId.toString().getBytes());
+      }
+    }
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfStringList(attributeNameList);
+    size += AstMemoryEstimationHelper.getShallowSizeOfList(attributeValueList);
+    for (Object[] values : attributeValueList) {
+      if (values != null) {
+        size += 
AstMemoryEstimationHelper.getEstimatedSizeOfByteArray(values.toString().getBytes());
+      }

Review Comment:
   ```suggestion
         size += RamUsageEstimator.sizeOf((String[]) values);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateView.java:
##########
@@ -92,4 +98,16 @@ public String toString() {
         .add("restrict", restrict)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = super.ramBytesUsed();
+    // super.ramBytesUsed() includes CreateTable's INSTANCE_SIZE, but we need 
CreateView's
+    size -= RamUsageEstimator.shallowSizeOfInstance(CreateTable.class);

Review Comment:
   no need to calculate this each time, you should define a method without 
CreateTable instance size in super class.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/Delete.java:
##########
@@ -129,4 +132,15 @@ public Collection<TRegionReplicaSet> getReplicaSets() {
   public void setReplicaSets(final Collection<TRegionReplicaSet> replicaSets) {
     this.replicaSets = replicaSets;
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(table);
+    if (where != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(where);
+    }

Review Comment:
   ```suggestion
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(where);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/Fill.java:
##########
@@ -165,4 +168,24 @@ public boolean shallowEquals(Node other) {
         && Objects.equals(timeColumnIndex, fill.timeColumnIndex)
         && Objects.equals(fillGroupingElements, fill.fillGroupingElements);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (fillValue != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(fillValue);
+    }
+    if (timeColumnIndex != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(timeColumnIndex);
+    }
+    if (fillGroupingElements != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(fillGroupingElements);
+    }

Review Comment:
   ```suggestion
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(fillValue);
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(timeColumnIndex);
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(fillGroupingElements);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateView.java:
##########
@@ -92,4 +98,16 @@ public String toString() {
         .add("restrict", restrict)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = super.ramBytesUsed();
+    // super.ramBytesUsed() includes CreateTable's INSTANCE_SIZE, but we need 
CreateView's
+    size -= RamUsageEstimator.shallowSizeOfInstance(CreateTable.class);
+    size += INSTANCE_SIZE;
+    if (prefixPath != null) {
+      size += MemoryEstimationHelper.getEstimatedSizeOfPartialPath(prefixPath);
+    }

Review Comment:
   ```suggestion
       size += MemoryEstimationHelper.getEstimatedSizeOfPartialPath(prefixPath);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/DescribeTable.java:
##########
@@ -98,4 +101,15 @@ public String toString() {
         .add("isShowCreateView", isShowCreateView)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += table == null ? 0L : table.ramBytesUsed();
+    if (isShowCreateView != null) {
+      size += AstMemoryEstimationHelper.OPTIONAL_INSTANCE_SIZE;
+    }

Review Comment:
   ```suggestion
       if (isShowCreateView != null) {
         size += 1;
       }
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/IfExpression.java:
##########
@@ -102,4 +106,16 @@ public int hashCode() {
   public boolean shallowEquals(Node other) {
     return sameClass(this, other);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(condition);
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(trueValue);
+    if (falseValue != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(falseValue);
+    }

Review Comment:
   ```suggestion
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(falseValue);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/DeleteDevice.java:
##########
@@ -249,4 +252,27 @@ public <R, C> R accept(final AstVisitor<R, C> visitor, 
final C context) {
   public String toString() {
     return toStringHelper(this) + " - " + super.toStringContent();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(table);
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(where);
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfString(database);
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfString(tableName);
+    size += 
AstMemoryEstimationHelper.getShallowSizeOfList(tagDeterminedFilterList);
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(tagFuzzyPredicate);
+    size += AstMemoryEstimationHelper.getShallowSizeOfList(columnHeaderList);
+    if (getAttributeColumns() != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfStringList(getAttributeColumns());
+    }

Review Comment:
   ```suggestion
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfStringList(getAttributeColumns());
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/FetchDevice.java:
##########
@@ -107,4 +110,26 @@ public String toString() {
         + deviceIdList
         + '}';
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfString(database);
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfString(tableName);
+    size += AstMemoryEstimationHelper.getShallowSizeOfList(deviceIdList);
+    for (Object[] deviceId : deviceIdList) {
+      if (deviceId != null) {
+        size +=
+            
AstMemoryEstimationHelper.getEstimatedSizeOfByteArray(deviceId.toString().getBytes());
+      }

Review Comment:
   ```suggestion
         size += RamUsageEstimator.sizeOf((String []) deviceId);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/Insert.java:
##########
@@ -111,4 +114,16 @@ public String toString() {
         .add("query", query)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(table);
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(query);
+    if (columns != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(columns);
+    }

Review Comment:
   ```suggestion
       size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(columns);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/Property.java:
##########
@@ -117,4 +120,15 @@ public String toString() {
         .add("value", isSetToDefault() ? "DEFAULT" : getNonDefaultValue())
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(name);
+    if (value != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(value);
+    }

Review Comment:
   ```suggestion
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(value);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/LoadTsFile.java:
##########
@@ -324,4 +329,59 @@ public String toString() {
         .add("loadAttributes", loadAttributes)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (filePath != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(filePath);
+    }
+    if (database != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(database);
+    }
+    if (loadAttributes != null && !loadAttributes.isEmpty()) {
+      for (Map.Entry<String, String> entry : loadAttributes.entrySet()) {
+        size += 
AstMemoryEstimationHelper.getEstimatedSizeOfString(entry.getKey());
+        size += 
AstMemoryEstimationHelper.getEstimatedSizeOfString(entry.getValue());
+      }
+      // Map overhead
+      size +=
+          AstMemoryEstimationHelper.getShallowSizeOfList(
+              new ArrayList<>(loadAttributes.entrySet()));
+    }
+    if (tsFiles != null) {
+      size += AstMemoryEstimationHelper.getShallowSizeOfList(tsFiles);
+      for (File file : tsFiles) {
+        if (file != null) {
+          size += RamUsageEstimator.shallowSizeOfInstance(File.class);
+        }
+      }
+    }
+    if (resources != null) {
+      size += AstMemoryEstimationHelper.getShallowSizeOfList(resources);
+      for (TsFileResource resource : resources) {
+        if (resource != null) {
+          size += resource.calculateRamSize();
+        }
+      }
+    }
+    if (writePointCountList != null) {
+      size += 
AstMemoryEstimationHelper.getShallowSizeOfList(writePointCountList);
+      for (Long count : writePointCountList) {
+        if (count != null) {
+          size += RamUsageEstimator.shallowSizeOfInstance(Long.class);
+        }
+      }
+    }
+    if (isTableModel != null) {
+      size += AstMemoryEstimationHelper.getShallowSizeOfList(isTableModel);
+      for (Boolean bool : isTableModel) {
+        if (bool != null) {
+          size += RamUsageEstimator.shallowSizeOfInstance(Boolean.class);

Review Comment:
   ```suggestion
             size += 1;
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/KillQuery.java:
##########
@@ -78,4 +82,14 @@ public boolean shallowEquals(Node other) {
   public String toString() {
     return "KILL QUERY " + queryId;
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (queryId != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(queryId);
+    }

Review Comment:
   ```suggestion
       size += AstMemoryEstimationHelper.getEstimatedSizeOfString(queryId);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/DereferenceExpression.java:
##########
@@ -148,4 +152,17 @@ public int hashCode() {
   public boolean shallowEquals(Node other) {
     return sameClass(this, other);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (base != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(base);
+    }
+    if (field != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(field);
+    }

Review Comment:
   ```suggestion
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(base);
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(field);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/LoadTsFile.java:
##########
@@ -324,4 +329,59 @@ public String toString() {
         .add("loadAttributes", loadAttributes)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (filePath != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(filePath);
+    }
+    if (database != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(database);
+    }

Review Comment:
   ```suggestion
       size += AstMemoryEstimationHelper.getEstimatedSizeOfString(filePath);
       size += AstMemoryEstimationHelper.getEstimatedSizeOfString(database);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/QualifiedName.java:
##########
@@ -226,4 +233,36 @@ public static QualifiedName deserialize(ByteBuffer 
byteBuffer) {
 
     return new QualifiedName(originalParts, parts, name, prefix, suffix);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    if (originalParts != null) {
+      size += RamUsageEstimator.shallowSizeOf(originalParts);
+      for (Identifier identifier : originalParts) {
+        if (identifier != null) {
+          size += identifier.ramBytesUsed();
+        }
+      }
+    }
+    if (parts != null) {
+      size += RamUsageEstimator.shallowSizeOf(parts);
+      for (String part : parts) {
+        if (part != null) {
+          size += RamUsageEstimator.sizeOf(part);
+        }
+      }
+    }
+    if (name != null) {
+      size += RamUsageEstimator.sizeOf(name);
+    }

Review Comment:
   ```suggestion
       size += RamUsageEstimator.sizeOf(name);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/LoadModel.java:
##########
@@ -70,4 +75,17 @@ public int hashCode() {
   public String toString() {
     return "LoadModel{" + "modelId='" + modelId + '\'' + ", deviceIdList=" + 
deviceIdList + '}';
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (modelId != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(modelId);
+    }
+    if (deviceIdList != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfStringList(deviceIdList);
+    }

Review Comment:
   ```suggestion
       size += AstMemoryEstimationHelper.getEstimatedSizeOfString(modelId);
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfStringList(deviceIdList);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/QualifiedName.java:
##########
@@ -38,7 +40,12 @@
 import static java.util.Locale.ENGLISH;
 import static java.util.Objects.requireNonNull;
 
-public class QualifiedName {
+public class QualifiedName implements Accountable {
+
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(QualifiedName.class);
+  private static final long OPTIONAL_INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(Optional.class);

Review Comment:
   no need to define again? you can reuse 
AstMemoryEstimationHelper.OPTIONAL_INSTANCE_SIZE



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/QualifiedName.java:
##########
@@ -226,4 +233,36 @@ public static QualifiedName deserialize(ByteBuffer 
byteBuffer) {
 
     return new QualifiedName(originalParts, parts, name, prefix, suffix);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    if (originalParts != null) {
+      size += RamUsageEstimator.shallowSizeOf(originalParts);
+      for (Identifier identifier : originalParts) {
+        if (identifier != null) {
+          size += identifier.ramBytesUsed();
+        }
+      }
+    }
+    if (parts != null) {
+      size += RamUsageEstimator.shallowSizeOf(parts);
+      for (String part : parts) {
+        if (part != null) {
+          size += RamUsageEstimator.sizeOf(part);
+        }
+      }
+    }
+    if (name != null) {
+      size += RamUsageEstimator.sizeOf(name);
+    }
+    if (prefix != null) {
+      size += OPTIONAL_INSTANCE_SIZE;
+      size += prefix.ramBytesUsed();
+    }
+    if (suffix != null) {
+      size += RamUsageEstimator.sizeOf(suffix);
+    }

Review Comment:
   ```suggestion
       size += RamUsageEstimator.sizeOf(suffix);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/QualifiedName.java:
##########
@@ -226,4 +233,36 @@ public static QualifiedName deserialize(ByteBuffer 
byteBuffer) {
 
     return new QualifiedName(originalParts, parts, name, prefix, suffix);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    if (originalParts != null) {
+      size += RamUsageEstimator.shallowSizeOf(originalParts);
+      for (Identifier identifier : originalParts) {
+        if (identifier != null) {
+          size += identifier.ramBytesUsed();
+        }
+      }
+    }
+    if (parts != null) {
+      size += RamUsageEstimator.shallowSizeOf(parts);
+      for (String part : parts) {
+        if (part != null) {
+          size += RamUsageEstimator.sizeOf(part);
+        }

Review Comment:
   ```suggestion
           size += RamUsageEstimator.sizeOf(part);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/LoadTsFile.java:
##########
@@ -324,4 +329,59 @@ public String toString() {
         .add("loadAttributes", loadAttributes)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (filePath != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(filePath);
+    }
+    if (database != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(database);
+    }
+    if (loadAttributes != null && !loadAttributes.isEmpty()) {
+      for (Map.Entry<String, String> entry : loadAttributes.entrySet()) {
+        size += 
AstMemoryEstimationHelper.getEstimatedSizeOfString(entry.getKey());
+        size += 
AstMemoryEstimationHelper.getEstimatedSizeOfString(entry.getValue());
+      }
+      // Map overhead
+      size +=
+          AstMemoryEstimationHelper.getShallowSizeOfList(
+              new ArrayList<>(loadAttributes.entrySet()));
+    }
+    if (tsFiles != null) {
+      size += AstMemoryEstimationHelper.getShallowSizeOfList(tsFiles);
+      for (File file : tsFiles) {
+        if (file != null) {
+          size += RamUsageEstimator.shallowSizeOfInstance(File.class);

Review Comment:
   define a constant field about 
RamUsageEstimator.shallowSizeOfInstance(File.class).



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/SearchedCaseExpression.java:
##########
@@ -146,4 +150,15 @@ protected void serialize(DataOutputStream stream) throws 
IOException {
     }
     Expression.serialize(getDefaultValue().orElse(new NullLiteral()), stream);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(whenClauses);
+    if (defaultValue != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(defaultValue);
+    }

Review Comment:
   ```suggestion
       size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(defaultValue);
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/Fill.java:
##########
@@ -165,4 +168,24 @@ public boolean shallowEquals(Node other) {
         && Objects.equals(timeColumnIndex, fill.timeColumnIndex)
         && Objects.equals(fillGroupingElements, fill.fillGroupingElements);
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (fillValue != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(fillValue);
+    }
+    if (timeColumnIndex != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(timeColumnIndex);
+    }
+    if (fillGroupingElements != null) {
+      size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(fillGroupingElements);
+    }
+    // TimeDuration is a simple object, estimate its size
+    if (timeBound != null) {
+      size += RamUsageEstimator.shallowSizeOfInstance(TimeDuration.class);

Review Comment:
   ```suggestion
         size += TimeDuration.INSTANCE_SIZE;
   ```
   define INSTANCE_SIZE in TimeDuration class



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/LoadTsFile.java:
##########
@@ -324,4 +329,59 @@ public String toString() {
         .add("loadAttributes", loadAttributes)
         .toString();
   }
+
+  @Override
+  public long ramBytesUsed() {
+    long size = INSTANCE_SIZE;
+    size += 
AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
+    if (filePath != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(filePath);
+    }
+    if (database != null) {
+      size += AstMemoryEstimationHelper.getEstimatedSizeOfString(database);
+    }
+    if (loadAttributes != null && !loadAttributes.isEmpty()) {
+      for (Map.Entry<String, String> entry : loadAttributes.entrySet()) {
+        size += 
AstMemoryEstimationHelper.getEstimatedSizeOfString(entry.getKey());
+        size += 
AstMemoryEstimationHelper.getEstimatedSizeOfString(entry.getValue());
+      }
+      // Map overhead
+      size +=
+          AstMemoryEstimationHelper.getShallowSizeOfList(
+              new ArrayList<>(loadAttributes.entrySet()));
+    }
+    if (tsFiles != null) {
+      size += AstMemoryEstimationHelper.getShallowSizeOfList(tsFiles);
+      for (File file : tsFiles) {
+        if (file != null) {
+          size += RamUsageEstimator.shallowSizeOfInstance(File.class);
+        }
+      }
+    }
+    if (resources != null) {
+      size += AstMemoryEstimationHelper.getShallowSizeOfList(resources);
+      for (TsFileResource resource : resources) {
+        if (resource != null) {
+          size += resource.calculateRamSize();
+        }
+      }
+    }
+    if (writePointCountList != null) {
+      size += 
AstMemoryEstimationHelper.getShallowSizeOfList(writePointCountList);
+      for (Long count : writePointCountList) {
+        if (count != null) {
+          size += RamUsageEstimator.shallowSizeOfInstance(Long.class);

Review Comment:
   ```suggestion
             size += Long.BYTES;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to