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

weihao 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 14c27bba99e Fix highestPriority of SHOW QUERIES are not set correctly 
(#17505)
14c27bba99e is described below

commit 14c27bba99ea7a67f53d62fde099b811d27e11cf
Author: Weihao Li <[email protected]>
AuthorDate: Fri Apr 17 15:36:34 2026 +0800

    Fix highestPriority of SHOW QUERIES are not set correctly (#17505)
---
 .../plan/relational/analyzer/Analysis.java         | 13 +++--
 .../plan/relational/planner/RelationPlanner.java   |  1 +
 .../analyzer/NeedSetHighestPriorityTest.java       | 56 ++++++++++++++++++++++
 .../plan/relational/planner/PlanTester.java        |  4 ++
 4 files changed, 71 insertions(+), 3 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/Analysis.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/Analysis.java
index 4a0fe9daa57..51499453743 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/Analysis.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/Analysis.java
@@ -62,7 +62,6 @@ import 
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.QuerySpecificatio
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RangeQuantifier;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Relation;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RowPattern;
-import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowStatement;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Statement;
 import 
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SubqueryExpression;
 import 
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SubsetDefinition;
@@ -118,6 +117,7 @@ public class Analysis implements IAnalysis {
   private List<TEndPoint> redirectNodeList;
 
   @Nullable private Statement root;
+  private boolean needSetHighestPriority;
 
   private final Map<NodeRef<Parameter>, Expression> parameters;
 
@@ -268,6 +268,14 @@ public class Analysis implements IAnalysis {
     this.parameters = ImmutableMap.copyOf(requireNonNull(parameters, 
"parameters is null"));
   }
 
+  public void updateNeedSetHighestPriority(QualifiedObjectName tableName) {
+    if (needSetHighestPriority) {
+      return;
+    }
+    //  the database of table has been judged to be 'information_schema' in 
outer
+    needSetHighestPriority = 
InformationSchema.QUERIES.equals(tableName.getObjectName());
+  }
+
   public Map<NodeRef<Parameter>, Expression> getParameters() {
     return parameters;
   }
@@ -960,8 +968,7 @@ public class Analysis implements IAnalysis {
 
   @Override
   public boolean needSetHighestPriority() {
-    return root instanceof ShowStatement
-        && ((ShowStatement) 
root).getTableName().equals(InformationSchema.QUERIES);
+    return needSetHighestPriority;
   }
 
   @Override
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/RelationPlanner.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/RelationPlanner.java
index 47dc87499b9..457a03ab4a0 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/RelationPlanner.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/RelationPlanner.java
@@ -390,6 +390,7 @@ public class RelationPlanner extends 
AstVisitor<RelationPlan, Void> {
       tableScanNode =
           new InformationSchemaTableScanNode(
               idAllocator.genPlanNodeId(), qualifiedObjectName, outputSymbols, 
tableColumnSchema);
+      analysis.updateNeedSetHighestPriority(qualifiedObjectName);
     } else {
       tableScanNode =
           new DeviceTableScanNode(
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/NeedSetHighestPriorityTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/NeedSetHighestPriorityTest.java
new file mode 100644
index 00000000000..f3643da1f4b
--- /dev/null
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/NeedSetHighestPriorityTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.analyzer;
+
+import org.apache.iotdb.db.queryengine.plan.relational.planner.PlanTester;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class NeedSetHighestPriorityTest {
+
+  @Test
+  public void testShowQueriesNeedSetHighestPriority() {
+    final Analysis analysis = planAndGetAnalysis("show queries");
+    assertTrue(analysis.needSetHighestPriority());
+  }
+
+  @Test
+  public void testInformationSchemaQueriesNeedSetHighestPriority() {
+    final Analysis analysis = planAndGetAnalysis("select query_id from 
information_schema.queries");
+    assertTrue(analysis.needSetHighestPriority());
+  }
+
+  @Test
+  public void testNestedInformationSchemaQueriesNeedSetHighestPriority() {
+    final Analysis analysis =
+        planAndGetAnalysis(
+            "select * from (select query_id from information_schema.queries) t 
"
+                + "where t.query_id is not null");
+    assertTrue(analysis.needSetHighestPriority());
+  }
+
+  private Analysis planAndGetAnalysis(final String sql) {
+    PlanTester planTester = new PlanTester();
+    planTester.createPlan(sql);
+    return planTester.getAnalysis();
+  }
+}
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/planner/PlanTester.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/planner/PlanTester.java
index d7d4169a360..968b0d28de9 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/planner/PlanTester.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/planner/PlanTester.java
@@ -161,6 +161,10 @@ public class PlanTester {
     return plan;
   }
 
+  public Analysis getAnalysis() {
+    return analysis;
+  }
+
   public LogicalQueryPlan createPlan(
       SessionInfo sessionInfo,
       String sql,

Reply via email to