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 2482a71b100 Fixed the issue that columns may not be pruned when 
querying non-field columns in tree view scan
2482a71b100 is described below

commit 2482a71b10065292b563fdf8afe39c48ba0e1692
Author: shuwenwei <[email protected]>
AuthorDate: Sat Jun 28 08:40:22 2025 +0800

    Fixed the issue that columns may not be pruned when querying non-field 
columns in tree view scan
---
 .../relational/it/query/view/recent/IoTDBTableViewQueryIT.java     | 7 +++++++
 .../iotdb/db/queryengine/plan/planner/TableOperatorGenerator.java  | 6 ++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBTableViewQueryIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBTableViewQueryIT.java
index 9b80f829e94..3a738f87900 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBTableViewQueryIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBTableViewQueryIT.java
@@ -107,6 +107,7 @@ public class IoTDBTableViewQueryIT {
     "CREATE VIEW view1 (battery TAG, voltage INT32 FIELD, current FLOAT FIELD) 
as root.db.battery.**",
     "CREATE VIEW view2 (battery TAG, voltage INT32 FIELD FROM voltage, 
current_rename FLOAT FIELD FROM current) as root.db.battery.**",
     "CREATE VIEW view3 (battery TAG, voltage INT32 FIELD FROM voltage, 
current_rename FLOAT FIELD FROM current) with (ttl=1) as root.db.battery.**",
+    "CREATE VIEW view4 (battery TAG, voltage INT32 FIELD FROM voltage) as 
root.db.battery.**",
     "CREATE TABLE table1 (battery TAG, voltage INT32 FIELD, current FLOAT 
FIELD)",
     "INSERT INTO table1 (time, battery, voltage, current) values (1, 'b1', 1, 
1)",
     "INSERT INTO table1 (time, battery, voltage, current) values (2, 'b1', 1, 
1)",
@@ -356,6 +357,12 @@ public class IoTDBTableViewQueryIT {
           "select * from (select * from view1 where battery = 'b1') join 
(select * from view1 where battery = 'b1' and (voltage > 0 or current > 0)) 
using(time)",
           "select * from (select * from table1 where battery = 'b1') join 
(select * from table1 where battery = 'b1' and (voltage > 0 or current > 0)) 
using(time)",
           true);
+
+      compareQueryResults(
+          session,
+          "select count(distinct battery) from view4 where battery = 'b1'",
+          "select count(distinct battery) from table1 where battery = 'b1'",
+          true);
     }
   }
 
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 3ab89c139ee..8856a2ec43d 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
@@ -560,11 +560,13 @@ public class TableOperatorGenerator extends 
PlanVisitor<Operator, LocalExecution
           public void generateCurrentDeviceOperatorTree(DeviceEntry 
deviceEntry) {
             calculateSeriesScanOptionsList();
             operator = constructTreeToTableViewAdaptorOperator(deviceEntry);
+            boolean needToPruneColumn =
+                node.getAssignments().size() != node.getOutputSymbols().size();
             if (isSingleColumn) {
+              operator = needToPruneColumn ? 
getFilterAndProjectOperator(operator) : operator;
               return;
             }
-            if (!cannotPushDownConjuncts.isEmpty()
-                || node.getAssignments().size() != 
node.getOutputSymbols().size()) {
+            if (!cannotPushDownConjuncts.isEmpty() || needToPruneColumn) {
               operator = getFilterAndProjectOperator(operator);
             }
             if (!node.isPushLimitToEachDevice() || 
removeUpperOffsetAndLimitOperator) {

Reply via email to