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

weihao pushed a commit to branch lwh/fixSQ
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 5c32f5a784710b8825c9d97514f1e281bb77a1b3
Author: Weihao Li <[email protected]>
AuthorDate: Fri Apr 17 10:56:26 2026 +0800

    fix
    
    Signed-off-by: Weihao Li <[email protected]>
---
 .../plan/relational/analyzer/Analysis.java         | 14 ++++--
 .../relational/analyzer/StatementAnalyzer.java     |  1 +
 .../analyzer/NeedSetHighestPriorityTest.java       | 58 ++++++++++++++++++++++
 3 files changed, 70 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..c9f6e712b4b 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,15 @@ public class Analysis implements IAnalysis {
     this.parameters = ImmutableMap.copyOf(requireNonNull(parameters, 
"parameters is null"));
   }
 
+  public void updateNeedSetHighestPriority(QualifiedObjectName tableName) {
+    if (needSetHighestPriority) {
+      return;
+    }
+    needSetHighestPriority =
+        
InformationSchema.INFORMATION_DATABASE.equals(tableName.getDatabaseName())
+            && InformationSchema.QUERIES.equals(tableName.getObjectName());
+  }
+
   public Map<NodeRef<Parameter>, Expression> getParameters() {
     return parameters;
   }
@@ -960,8 +969,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/analyzer/StatementAnalyzer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
index dade85d20b1..4151fb3a0de 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
@@ -3115,6 +3115,7 @@ public class StatementAnalyzer {
         }
       }
       QualifiedObjectName name = createQualifiedObjectName(sessionContext, 
table.getName());
+      analysis.updateNeedSetHighestPriority(name);
 
       // access control
       accessControl.checkCanSelectFromTable(sessionContext.getUserName(), 
name, queryContext);
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..b89a9616e8d
--- /dev/null
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/NeedSetHighestPriorityTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.common.MPPQueryContext;
+import org.apache.iotdb.db.queryengine.common.QueryId;
+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 = analyze("show queries");
+    assertTrue(analysis.needSetHighestPriority());
+  }
+
+  @Test
+  public void testInformationSchemaQueriesNeedSetHighestPriority() {
+    final Analysis analysis = analyze("select query_id from 
information_schema.queries");
+    assertTrue(analysis.needSetHighestPriority());
+  }
+
+  @Test
+  public void testNestedInformationSchemaQueriesNeedSetHighestPriority() {
+    final Analysis analysis =
+        analyze(
+            "select * from (select query_id from information_schema.queries) t 
"
+                + "where t.query_id is not null");
+    assertTrue(analysis.needSetHighestPriority());
+  }
+
+  private Analysis analyze(final String sql) {
+    final MPPQueryContext context =
+        new MPPQueryContext(sql, new 
QueryId("need_set_highest_priority_test"), null, null, null);
+    return PlanTester.analyze(sql, new TestMetadata(), context);
+  }
+}

Reply via email to