Skip to content

Commit 14c27bb

Browse files
authored
Fix highestPriority of SHOW QUERIES are not set correctly (#17505)
1 parent 519dec0 commit 14c27bb

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/Analysis.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RangeQuantifier;
6363
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Relation;
6464
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RowPattern;
65-
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowStatement;
6665
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Statement;
6766
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SubqueryExpression;
6867
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SubsetDefinition;
@@ -118,6 +117,7 @@ public class Analysis implements IAnalysis {
118117
private List<TEndPoint> redirectNodeList;
119118

120119
@Nullable private Statement root;
120+
private boolean needSetHighestPriority;
121121

122122
private final Map<NodeRef<Parameter>, Expression> parameters;
123123

@@ -268,6 +268,14 @@ public Analysis(@Nullable Statement root, Map<NodeRef<Parameter>, Expression> pa
268268
this.parameters = ImmutableMap.copyOf(requireNonNull(parameters, "parameters is null"));
269269
}
270270

271+
public void updateNeedSetHighestPriority(QualifiedObjectName tableName) {
272+
if (needSetHighestPriority) {
273+
return;
274+
}
275+
// the database of table has been judged to be 'information_schema' in outer
276+
needSetHighestPriority = InformationSchema.QUERIES.equals(tableName.getObjectName());
277+
}
278+
271279
public Map<NodeRef<Parameter>, Expression> getParameters() {
272280
return parameters;
273281
}
@@ -960,8 +968,7 @@ public void setQuery(boolean query) {
960968

961969
@Override
962970
public boolean needSetHighestPriority() {
963-
return root instanceof ShowStatement
964-
&& ((ShowStatement) root).getTableName().equals(InformationSchema.QUERIES);
971+
return needSetHighestPriority;
965972
}
966973

967974
@Override

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/RelationPlanner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ private RelationPlan processPhysicalTable(Table table, Scope scope) {
390390
tableScanNode =
391391
new InformationSchemaTableScanNode(
392392
idAllocator.genPlanNodeId(), qualifiedObjectName, outputSymbols, tableColumnSchema);
393+
analysis.updateNeedSetHighestPriority(qualifiedObjectName);
393394
} else {
394395
tableScanNode =
395396
new DeviceTableScanNode(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.db.queryengine.plan.relational.analyzer;
21+
22+
import org.apache.iotdb.db.queryengine.plan.relational.planner.PlanTester;
23+
24+
import org.junit.Test;
25+
26+
import static org.junit.Assert.assertTrue;
27+
28+
public class NeedSetHighestPriorityTest {
29+
30+
@Test
31+
public void testShowQueriesNeedSetHighestPriority() {
32+
final Analysis analysis = planAndGetAnalysis("show queries");
33+
assertTrue(analysis.needSetHighestPriority());
34+
}
35+
36+
@Test
37+
public void testInformationSchemaQueriesNeedSetHighestPriority() {
38+
final Analysis analysis = planAndGetAnalysis("select query_id from information_schema.queries");
39+
assertTrue(analysis.needSetHighestPriority());
40+
}
41+
42+
@Test
43+
public void testNestedInformationSchemaQueriesNeedSetHighestPriority() {
44+
final Analysis analysis =
45+
planAndGetAnalysis(
46+
"select * from (select query_id from information_schema.queries) t "
47+
+ "where t.query_id is not null");
48+
assertTrue(analysis.needSetHighestPriority());
49+
}
50+
51+
private Analysis planAndGetAnalysis(final String sql) {
52+
PlanTester planTester = new PlanTester();
53+
planTester.createPlan(sql);
54+
return planTester.getAnalysis();
55+
}
56+
}

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/planner/PlanTester.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ public LogicalQueryPlan createPlan(
161161
return plan;
162162
}
163163

164+
public Analysis getAnalysis() {
165+
return analysis;
166+
}
167+
164168
public LogicalQueryPlan createPlan(
165169
SessionInfo sessionInfo,
166170
String sql,

0 commit comments

Comments
 (0)