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

justinchen pushed a commit to branch tree-fix-207
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/tree-fix-207 by this push:
     new 8624fcac7e2 Fixed the quote problem in "as" clause in view && Fixed 
the bug that the device may not be able to be queried from cache (#17241)
8624fcac7e2 is described below

commit 8624fcac7e22b7e6a831ad1558b35babc0466e6b
Author: Caideyipi <[email protected]>
AuthorDate: Wed Mar 4 12:56:16 2026 +0800

    Fixed the quote problem in "as" clause in view && Fixed the bug that the 
device may not be able to be queried from cache (#17241)
---
 .../view/recent/IoTDBComplexQueryTableViewIT.java  | 18 ++++----
 .../iotdb/relational/it/schema/IoTDBTableIT.java   | 54 ++++++++++++----------
 .../common/header/DatasetHeaderFactory.java        |  2 +-
 .../operator/schema/source/DeviceSchemaSource.java |  2 +-
 .../metadata/relational/ShowCreateViewTask.java    |  2 +-
 .../plan/planner/OperatorTreeGenerator.java        |  2 +-
 .../node/metadata/read/DevicesSchemaScanNode.java  | 24 +++++-----
 .../metadata/fetcher/TableDeviceSchemaFetcher.java | 12 ++---
 .../sql/ast/AbstractQueryDeviceWithCache.java      | 14 ++++--
 .../plan/relational/sql/parser/AstBuilder.java     | 30 ++++++++----
 .../read/resp/info/impl/ShowDevicesResult.java     |  5 +-
 .../logical/SchemaQueryLogicalPlannerTest.java     |  6 +--
 .../schema/column/ColumnHeaderConstant.java        |  2 +-
 13 files changed, 96 insertions(+), 77 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBComplexQueryTableViewIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBComplexQueryTableViewIT.java
index 96f0a9de596..b6617ec50dd 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBComplexQueryTableViewIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBComplexQueryTableViewIT.java
@@ -48,10 +48,10 @@ public class IoTDBComplexQueryTableViewIT {
         "create aligned timeseries root.test.employees.D002(name TEXT,Gender 
TEXT,Status BOOLEAN,employee_id INT32,salary DOUBLE,date_of_birth 
DATE,Contac_info string)",
         "create aligned timeseries root.test.employees.D002(name TEXT,Gender 
TEXT,Status BOOLEAN,employee_id INT32,salary DOUBLE,date_of_birth 
DATE,Contac_info string)",
         "create aligned timeseries root.test.employees.D003(name TEXT,Gender 
TEXT,Status BOOLEAN,employee_id INT32,salary DOUBLE,date_of_birth 
DATE,Contac_info string)",
-        "create aligned timeseries root.test.departments.D001(department_id 
STRING,dep_name TEXT,dep_phone TEXT,dep_status BOOLEAN,dep_member 
INT32,employee_id INT32)",
-        "create aligned timeseries root.test.departments.D002(department_id 
STRING,dep_name TEXT,dep_phone TEXT,dep_status BOOLEAN,dep_member 
INT32,employee_id INT32)",
-        "create aligned timeseries root.test.departments.D003(department_id 
STRING,dep_name TEXT,dep_phone TEXT,dep_status BOOLEAN,dep_member 
INT32,employee_id INT32)",
-        "create aligned timeseries root.test.departments.D004(department_id 
STRING,dep_name TEXT,dep_phone TEXT,dep_status BOOLEAN,dep_member 
INT32,employee_id INT32)",
+        "create aligned timeseries root.test.departments.D001(`1department_id` 
STRING,dep_name TEXT,dep_phone TEXT,dep_status BOOLEAN,dep_member 
INT32,employee_id INT32)",
+        "create aligned timeseries root.test.departments.D002(`1department_id` 
STRING,dep_name TEXT,dep_phone TEXT,dep_status BOOLEAN,dep_member 
INT32,employee_id INT32)",
+        "create aligned timeseries root.test.departments.D003(`1department_id` 
STRING,dep_name TEXT,dep_phone TEXT,dep_status BOOLEAN,dep_member 
INT32,employee_id INT32)",
+        "create aligned timeseries root.test.departments.D004(`1department_id` 
STRING,dep_name TEXT,dep_phone TEXT,dep_status BOOLEAN,dep_member 
INT32,employee_id INT32)",
         "insert into root.test.employees.D001(time, name, gender, status, 
employee_id, salary, date_of_birth, contac_info) aligned values(1, 
'Mary','Female', false, 1223, 5500.22, '1988-10-12', '133-1212-1234')",
         "insert into root.test.employees.D001(time, name, gender, status, 
employee_id, salary, date_of_birth, contac_info) aligned values(2, 'John', 
'Male', true, 40012, 8822, '1985-06-15', '130-1002-1334')",
         "insert into root.test.employees.D002(time, name, gender, status, 
employee_id, salary, date_of_birth, contac_info) aligned values(3, 'Nancy', 
'Female', true, 30112, 10002, '1983-08-15', '135-1302-1354')",
@@ -69,8 +69,8 @@ public class IoTDBComplexQueryTableViewIT {
       new String[] {
         "CREATE DATABASE " + DATABASE_NAME,
         "USE " + DATABASE_NAME,
-        "create view employees(department_id STRING TAG,name TEXT FIELD,Gender 
TEXT FIELD,Status BOOLEAN FIELD,employee_id INT32 FIELD,salary DOUBLE 
FIELD,date_of_birth DATE FIELD,Contac_info string FIELD) as 
root.test.employees.**",
-        "create view departments(department_id STRING TAG,dep_name TEXT 
FIELD,dep_phone TEXT FIELD,dep_status BOOLEAN FIELD,dep_member INT32 
FIELD,employee_id INT32 FIELD) as root.test.departments.**",
+        "create view employees(\"`1department_id`\" STRING TAG,name TEXT 
FIELD,Gender TEXT FIELD,Status BOOLEAN FIELD,employee_id INT32 FIELD,salary 
DOUBLE FIELD,date_of_birth DATE FIELD,Contac_info string FIELD) as 
root.test.employees.**",
+        "create view departments(\"`1department_id`\" STRING TAG,dep_name TEXT 
FIELD,dep_phone TEXT FIELD,dep_status BOOLEAN FIELD,dep_member INT32 
FIELD,employee_id INT32 FIELD) as root.test.departments.**",
       };
 
   @BeforeClass
@@ -88,11 +88,11 @@ public class IoTDBComplexQueryTableViewIT {
   @Test
   public void queryTest1() {
     // Look for the non-intersecting departments in the two tables
-    String[] expectedHeader = new String[] {"department_id", "dep_name"};
+    String[] expectedHeader = new String[] {"`1department_id`", "dep_name"};
     String[] retArray = new String[] {"D004,人事部,"};
     tableResultSetEqualTest(
-        "select department_id, dep_name from departments where not exists("
-            + "select 1 from employees where employees.department_id = 
departments.department_id)",
+        "select \"`1department_id`\", dep_name from departments where not 
exists("
+            + "select 1 from employees where employees.\"`1department_id`\" = 
departments.\"`1department_id`\")",
         expectedHeader,
         retArray,
         DATABASE_NAME);
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
index 54881fb8293..96fe00d2293 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
@@ -766,10 +766,10 @@ public class IoTDBTableIT {
     try (final Connection connection = EnvFactory.getEnv().getConnection();
         final Statement statement = connection.createStatement()) {
       statement.execute("create database root.another");
-      statement.execute("create database root.`重庆`.b");
-      statement.execute("create timeSeries root.`重庆`.b.c.S1 int32");
-      statement.execute("create timeSeries root.`重庆`.b.c.s2 string");
-      statement.execute("create timeSeries root.`重庆`.b.S1 int32");
+      statement.execute("create database root.`重庆`.`1`.b");
+      statement.execute("create timeSeries root.`重庆`.`1`.b.`2`.S1 int32");
+      statement.execute("create timeSeries root.`重庆`.`1`.b.`2`.s2 string");
+      statement.execute("create timeSeries root.`重庆`.`1`.b.S1 int32");
     } catch (SQLException e) {
       fail(e.getMessage());
     }
@@ -788,13 +788,13 @@ public class IoTDBTableIT {
             "701: Cannot specify view pattern to match more than one tree 
database.",
             e.getMessage());
       }
-      statement.execute("create view tree_table (tag1 tag, tag2 tag) as 
root.\"重庆\".**");
+      statement.execute("create view tree_table (tag1 tag, tag2 tag) as 
root.\"重庆\".\"1\".**");
       statement.execute("drop view tree_table");
     }
 
     try (final Connection connection = EnvFactory.getEnv().getConnection();
         final Statement statement = connection.createStatement()) {
-      statement.execute("create timeSeries root.`重庆`.b.d.s1 int32");
+      statement.execute("create timeSeries root.`重庆`.`1`.b.`1`.s1 int32");
     } catch (SQLException e) {
       fail(e.getMessage());
     }
@@ -805,7 +805,7 @@ public class IoTDBTableIT {
       statement.execute("use tree_view_db");
 
       try {
-        statement.execute("create view tree_table (tag1 tag, tag2 tag) as 
root.\"重庆\".**");
+        statement.execute("create view tree_table (tag1 tag, tag2 tag) as 
root.\"重庆\".\"1\".**");
         fail();
       } catch (final SQLException e) {
         final Set<String> result =
@@ -819,13 +819,13 @@ public class IoTDBTableIT {
 
     try (final Connection connection = EnvFactory.getEnv().getConnection();
         final Statement statement = connection.createStatement()) {
-      statement.execute("drop timeSeries root.`重庆`.b.d.s1");
+      statement.execute("drop timeSeries root.`重庆`.`1`.b.`1`.s1");
       statement.execute("create device template t1 (S1 boolean, s9 int32)");
-      statement.execute("set schema template t1 to root.`重庆`.b.d");
-      statement.execute("create timeSeries root.`重庆`.b.c.f.g.h.S1 int32");
+      statement.execute("set schema template t1 to root.`重庆`.`1`.b.`1`");
+      statement.execute("create timeSeries root.`重庆`.`1`.b.`2`.f.g.h.S1 
int32");
 
       // Put schema cache
-      statement.execute("select S1, s2 from root.`重庆`.b.c");
+      statement.execute("select S1, s2 from root.`重庆`.`1`.b.`2`");
     } catch (SQLException e) {
       fail(e.getMessage());
     }
@@ -836,7 +836,7 @@ public class IoTDBTableIT {
       statement.execute("use tree_view_db");
 
       try {
-        statement.execute("create view tree_table (tag1 tag, tag2 tag) as 
root.\"重庆\".**");
+        statement.execute("create view tree_table (tag1 tag, tag2 tag) as 
root.\"重庆\".\"1\".**");
         fail();
       } catch (final SQLException e) {
         assertEquals(
@@ -846,7 +846,7 @@ public class IoTDBTableIT {
 
       try {
         statement.execute(
-            "create view tree_table (tag1 tag, tag2 tag, S1 field) as 
root.\"重庆\".**");
+            "create view tree_table (tag1 tag, tag2 tag, S1 field) as 
root.\"重庆\".\"1\".**");
         fail();
       } catch (final SQLException e) {
         assertEquals(
@@ -857,7 +857,7 @@ public class IoTDBTableIT {
 
     try (final Connection connection = EnvFactory.getEnv().getConnection();
         final Statement statement = connection.createStatement()) {
-      statement.execute("create timeSeries root.`重庆`.b.e.s1 int32");
+      statement.execute("create timeSeries root.`重庆`.`1`.b.e.s1 int32");
     } catch (SQLException e) {
       fail(e.getMessage());
     }
@@ -878,7 +878,7 @@ public class IoTDBTableIT {
       // Temporary
       try {
         statement.execute(
-            "create or replace view tree_table (tag1 tag, tag2 tag, S1 int32 
field, s3 boolean from S1) as root.\"重庆\".**");
+            "create or replace view tree_table (tag1 tag, tag2 tag, S1 int32 
field, s3 boolean from S1) as root.\"重庆\".\"1\".**");
         fail();
       } catch (final SQLException e) {
         assertEquals(
@@ -887,14 +887,14 @@ public class IoTDBTableIT {
 
       try {
         statement.execute(
-            "create or replace view tree_table (tag1 tag, tag2 tag, S1 int32 
field, s3 from s2, s8 field) as root.\"重庆\".**");
+            "create or replace view tree_table (tag1 tag, tag2 tag, S1 int32 
field, s3 from s2, s8 field) as root.\"重庆\".\"1\".**");
         fail();
       } catch (final SQLException e) {
         assertEquals("528: Measurements not found for s8, cannot auto detect", 
e.getMessage());
       }
 
       statement.execute(
-          "create or replace view tree_table (tag1 tag, tag2 tag, S1 int32 
field, s3 from s2) as root.\"重庆\".**");
+          "create or replace view tree_table (tag1 tag, tag2 tag, S1 int32 
field, s3 from s2) as root.\"重庆\".\"1\".**");
 
       // Cannot be written
       try {
@@ -942,11 +942,15 @@ public class IoTDBTableIT {
       TestUtils.assertResultSetEqual(
           statement.executeQuery("show devices from view_table where tag1 = 
'b'"),
           "tag1,tag2,",
-          new HashSet<>(Arrays.asList("b,c,", "b,null,", "b,e,")));
+          new HashSet<>(Arrays.asList("b,`2`,", "b,null,", "b,e,")));
       TestUtils.assertResultSetEqual(
           statement.executeQuery("show devices from view_table where tag1 = 
'b' and tag2 is null"),
           "tag1,tag2,",
           Collections.singleton("b,null,"));
+      TestUtils.assertResultSetEqual(
+          statement.executeQuery("show devices from view_table where tag1 = 
'b' and tag2 = '`2`'"),
+          "tag1,tag2,",
+          Collections.singleton("b,`2`,"));
       TestUtils.assertResultSetEqual(
           statement.executeQuery("count devices from view_table"),
           "count(devices),",
@@ -958,7 +962,7 @@ public class IoTDBTableIT {
         final Statement statement = connection.createStatement()) {
       // Test create & replace + restrict
       statement.execute(
-          "create or replace view tree_view_db.view_table (tag1 tag, tag2 tag, 
s11 int32 field, s3 from s2) restrict with (ttl=100) as root.`重庆`.**");
+          "create or replace view tree_view_db.view_table (tag1 tag, tag2 tag, 
s11 int32 field, s3 from s2) restrict with (ttl=100) as root.`重庆`.`1`.**");
       fail();
     } catch (final SQLException e) {
       assertTrue(
@@ -979,7 +983,7 @@ public class IoTDBTableIT {
                 .getConnection("testUser", "testUser123456", 
BaseEnv.TABLE_SQL_DIALECT);
         final Statement statement = connection.createStatement()) {
       statement.execute(
-          "create or replace view tree_view_db.view_table (tag1 tag, tag2 tag, 
s11 int32 field, s3 from s2) restrict with (ttl=100) as root.\"重庆\".**");
+          "create or replace view tree_view_db.view_table (tag1 tag, tag2 tag, 
s11 int32 field, s3 from s2) restrict with (ttl=100) as root.\"重庆\".\"1\".**");
       fail();
     } catch (final SQLException e) {
       assertEquals(
@@ -1000,7 +1004,7 @@ public class IoTDBTableIT {
                 .getConnection("testUser", "testUser123456", 
BaseEnv.TABLE_SQL_DIALECT);
         final Statement statement = connection.createStatement()) {
       statement.execute(
-          "create or replace view tree_view_db.view_table (tag1 tag, tag2 tag, 
s11 int32 field, s3 from s2) restrict with (ttl=100) as root.\"重庆\".**");
+          "create or replace view tree_view_db.view_table (tag1 tag, tag2 tag, 
s11 int32 field, s3 from s2) restrict with (ttl=100) as root.\"重庆\".\"1\".**");
       fail();
     } catch (final SQLException e) {
       assertEquals(
@@ -1020,7 +1024,7 @@ public class IoTDBTableIT {
                 .getConnection("testUser", "testUser123456", 
BaseEnv.TABLE_SQL_DIALECT);
         final Statement statement = connection.createStatement()) {
       statement.execute(
-          "create or replace view tree_view_db.view_table (tag1 tag, tag2 tag, 
s11 int32 field, s3 from s2) restrict with (ttl=100) as root.\"重庆\".**");
+          "create or replace view tree_view_db.view_table (tag1 tag, tag2 tag, 
s11 int32 field, s3 from s2) restrict with (ttl=100) as root.\"重庆\".\"1\".**");
       fail();
     } catch (final SQLException e) {
       assertEquals(
@@ -1040,7 +1044,7 @@ public class IoTDBTableIT {
                 .getConnection("testUser", "testUser123456", 
BaseEnv.TABLE_SQL_DIALECT);
         final Statement statement = connection.createStatement()) {
       statement.execute(
-          "create or replace view tree_view_db.view_table (tag1 tag, tag2 tag, 
s11 int32 field, s3 from s2) restrict with (ttl=100) as root.\"重庆\".**");
+          "create or replace view tree_view_db.view_table (tag1 tag, tag2 tag, 
s11 int32 field, s3 from s2) restrict with (ttl=100) as root.\"重庆\".\"1\".**");
     } catch (final SQLException e) {
       fail();
     }
@@ -1059,14 +1063,14 @@ public class IoTDBTableIT {
           statement.executeQuery("show create view view_table"),
           "View,Create View,",
           Collections.singleton(
-              "view_table,CREATE VIEW \"view_table\" (\"tag1\" STRING 
TAG,\"tag2\" STRING TAG,\"s11\" INT32 FIELD,\"s3\" STRING FIELD FROM \"s2\") 
RESTRICT WITH (ttl=100) AS root.\"重庆\".**,"));
+              "view_table,CREATE VIEW \"view_table\" (\"tag1\" STRING 
TAG,\"tag2\" STRING TAG,\"s11\" INT32 FIELD,\"s3\" STRING FIELD FROM \"s2\") 
RESTRICT WITH (ttl=100) AS root.\"重庆\".\"1\".**,"));
 
       // Can also use "show create table"
       TestUtils.assertResultSetEqual(
           statement.executeQuery("show create table view_table"),
           "View,Create View,",
           Collections.singleton(
-              "view_table,CREATE VIEW \"view_table\" (\"tag1\" STRING 
TAG,\"tag2\" STRING TAG,\"s11\" INT32 FIELD,\"s3\" STRING FIELD FROM \"s2\") 
RESTRICT WITH (ttl=100) AS root.\"重庆\".**,"));
+              "view_table,CREATE VIEW \"view_table\" (\"tag1\" STRING 
TAG,\"tag2\" STRING TAG,\"s11\" INT32 FIELD,\"s3\" STRING FIELD FROM \"s2\") 
RESTRICT WITH (ttl=100) AS root.\"重庆\".\"1\".**,"));
 
       statement.execute("create table a ()");
       try {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/header/DatasetHeaderFactory.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/header/DatasetHeaderFactory.java
index a9e737ac06e..221483ee603 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/header/DatasetHeaderFactory.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/header/DatasetHeaderFactory.java
@@ -56,7 +56,7 @@ public class DatasetHeaderFactory {
   }
 
   public static DatasetHeader getShowDevicesWithSgHeader() {
-    return new 
DatasetHeader(ColumnHeaderConstant.showDevicesWithSgColumnHeaders, true);
+    return new 
DatasetHeader(ColumnHeaderConstant.showDevicesWithDbColumnHeaders, true);
   }
 
   public static DatasetHeader getShowDatabaseHeader(final boolean isDetailed) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/DeviceSchemaSource.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/DeviceSchemaSource.java
index c655cf9eae4..f9f1f53c83d 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/DeviceSchemaSource.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/DeviceSchemaSource.java
@@ -89,7 +89,7 @@ public class DeviceSchemaSource implements 
ISchemaSource<IDeviceSchemaInfo> {
   @Override
   public List<ColumnHeader> getInfoQueryColumnHeaders() {
     return hasSgCol
-        ? ColumnHeaderConstant.showDevicesWithSgColumnHeaders
+        ? ColumnHeaderConstant.showDevicesWithDbColumnHeaders
         : ColumnHeaderConstant.showDevicesColumnHeaders;
   }
 
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowCreateViewTask.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowCreateViewTask.java
index a0c8325b864..f4a8578c1e7 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowCreateViewTask.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowCreateViewTask.java
@@ -146,7 +146,7 @@ public class ShowCreateViewTask extends AbstractTableTask {
     final String[] pathNodes = 
TreeViewSchema.getPrefixPattern(table).getNodes();
     builder.append(pathNodes[0]);
     for (int i = 1; i < pathNodes.length - 1; ++i) {
-      builder.append(".\"").append(pathNodes[i]).append("\"");
+      builder.append(".\"").append(pathNodes[i].replace("`", "")).append("\"");
     }
     builder.append(".").append(pathNodes[pathNodes.length - 1]);
 
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java
index 4668b25c4c1..277daf643f3 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java
@@ -932,7 +932,7 @@ public class OperatorTreeGenerator extends 
PlanVisitor<Operator, LocalExecutionP
             node.isPrefixPath(),
             node.getLimit(),
             node.getOffset(),
-            node.isHasSgCol(),
+            node.isHasDbCol(),
             node.getSchemaFilter(),
             node.getScope()));
   }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/metadata/read/DevicesSchemaScanNode.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/metadata/read/DevicesSchemaScanNode.java
index e7c5067c4e3..d76e74d9d7a 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/metadata/read/DevicesSchemaScanNode.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/metadata/read/DevicesSchemaScanNode.java
@@ -40,7 +40,7 @@ import java.util.stream.Collectors;
 
 public class DevicesSchemaScanNode extends SchemaQueryScanNode {
 
-  private final boolean hasSgCol;
+  private final boolean hasDbCol;
   private final SchemaFilter schemaFilter;
 
   public DevicesSchemaScanNode(
@@ -49,16 +49,16 @@ public class DevicesSchemaScanNode extends 
SchemaQueryScanNode {
       long limit,
       long offset,
       boolean isPrefixPath,
-      boolean hasSgCol,
+      boolean hasDbCol,
       SchemaFilter schemaFilter,
       PathPatternTree scope) {
     super(id, path, limit, offset, isPrefixPath, scope);
-    this.hasSgCol = hasSgCol;
+    this.hasDbCol = hasDbCol;
     this.schemaFilter = schemaFilter;
   }
 
-  public boolean isHasSgCol() {
-    return hasSgCol;
+  public boolean isHasDbCol() {
+    return hasDbCol;
   }
 
   public SchemaFilter getSchemaFilter() {
@@ -73,13 +73,13 @@ public class DevicesSchemaScanNode extends 
SchemaQueryScanNode {
   @Override
   public PlanNode clone() {
     return new DevicesSchemaScanNode(
-        getPlanNodeId(), path, limit, offset, isPrefixPath, hasSgCol, 
schemaFilter, scope);
+        getPlanNodeId(), path, limit, offset, isPrefixPath, hasDbCol, 
schemaFilter, scope);
   }
 
   @Override
   public List<String> getOutputColumnNames() {
-    if (hasSgCol) {
-      return ColumnHeaderConstant.showDevicesWithSgColumnHeaders.stream()
+    if (hasDbCol) {
+      return ColumnHeaderConstant.showDevicesWithDbColumnHeaders.stream()
           .map(ColumnHeader::getColumnName)
           .collect(Collectors.toList());
     }
@@ -96,7 +96,7 @@ public class DevicesSchemaScanNode extends 
SchemaQueryScanNode {
     ReadWriteIOUtils.write(limit, byteBuffer);
     ReadWriteIOUtils.write(offset, byteBuffer);
     ReadWriteIOUtils.write(isPrefixPath, byteBuffer);
-    ReadWriteIOUtils.write(hasSgCol, byteBuffer);
+    ReadWriteIOUtils.write(hasDbCol, byteBuffer);
     SchemaFilter.serialize(schemaFilter, byteBuffer);
   }
 
@@ -108,7 +108,7 @@ public class DevicesSchemaScanNode extends 
SchemaQueryScanNode {
     ReadWriteIOUtils.write(limit, stream);
     ReadWriteIOUtils.write(offset, stream);
     ReadWriteIOUtils.write(isPrefixPath, stream);
-    ReadWriteIOUtils.write(hasSgCol, stream);
+    ReadWriteIOUtils.write(hasDbCol, stream);
     SchemaFilter.serialize(schemaFilter, stream);
   }
 
@@ -143,12 +143,12 @@ public class DevicesSchemaScanNode extends 
SchemaQueryScanNode {
       return false;
     }
     DevicesSchemaScanNode that = (DevicesSchemaScanNode) o;
-    return hasSgCol == that.hasSgCol && Objects.equals(schemaFilter, 
that.schemaFilter);
+    return hasDbCol == that.hasDbCol && Objects.equals(schemaFilter, 
that.schemaFilter);
   }
 
   @Override
   public int hashCode() {
-    return Objects.hash(super.hashCode(), hasSgCol, schemaFilter);
+    return Objects.hash(super.hashCode(), hasDbCol, schemaFilter);
   }
 
   @Override
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaFetcher.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaFetcher.java
index 643f5364faa..5c9f94543d5 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaFetcher.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaFetcher.java
@@ -351,17 +351,17 @@ public class TableDeviceSchemaFetcher {
       final Map<String, List<DeviceEntry>> deviceEntryMap,
       final String database,
       final TsTable tableInstance,
-      final Map<Integer, List<SchemaFilter>> idFilters,
+      final Map<Integer, List<SchemaFilter>> tagFilters,
       final Predicate<AlignedDeviceEntry> check,
       final List<String> attributeColumns,
       final List<IDeviceID> fetchPaths,
       final boolean isDirectDeviceQuery,
       final MPPQueryContext queryContext) {
-    final String[] idValues = new String[tableInstance.getTagNum()];
-    for (final List<SchemaFilter> schemaFilters : idFilters.values()) {
+    final String[] tagValues = new String[tableInstance.getTagNum()];
+    for (final List<SchemaFilter> schemaFilters : tagFilters.values()) {
       final TagFilter tagFilter = (TagFilter) schemaFilters.get(0);
       final SchemaFilter childFilter = tagFilter.getChild();
-      idValues[tagFilter.getIndex()] = ((PreciseFilter) 
childFilter).getValue();
+      tagValues[tagFilter.getIndex()] = ((PreciseFilter) 
childFilter).getValue();
     }
 
     return !TreeViewSchema.isTreeViewTable(tableInstance)
@@ -373,9 +373,9 @@ public class TableDeviceSchemaFetcher {
             attributeColumns,
             fetchPaths,
             isDirectDeviceQuery,
-            idValues,
+            tagValues,
             queryContext)
-        : tryGetTreeDeviceInCache(deviceEntryMap, tableInstance, check, 
fetchPaths, idValues);
+        : tryGetTreeDeviceInCache(deviceEntryMap, tableInstance, check, 
fetchPaths, tagValues);
   }
 
   private boolean tryGetTableDeviceInCache(
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AbstractQueryDeviceWithCache.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AbstractQueryDeviceWithCache.java
index 327b5703b4e..cf2d47492f2 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AbstractQueryDeviceWithCache.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AbstractQueryDeviceWithCache.java
@@ -61,16 +61,20 @@ public abstract class AbstractQueryDeviceWithCache extends 
AbstractTraverseDevic
     if (Objects.isNull(where)) {
       return true;
     }
-    final Map<String, List<DeviceEntry>> entries = new HashMap<>();
-    entries.put(database, new ArrayList<>());
+    final Map<String, List<DeviceEntry>> hitCacheEntries = new HashMap<>();
+    hitCacheEntries.put(database, new ArrayList<>());
 
     final boolean needFetch =
-        super.parseRawExpression(entries, tableInstance, attributeColumns, 
context);
+        super.parseRawExpression(hitCacheEntries, tableInstance, 
attributeColumns, context);
     if (!needFetch) {
       context.reserveMemoryForFrontEnd(
-          
entries.get(database).stream().map(DeviceEntry::ramBytesUsed).reduce(0L, 
Long::sum));
+          hitCacheEntries.values().stream()
+              .flatMap(List::stream)
+              .map(DeviceEntry::ramBytesUsed)
+              .reduce(0L, Long::sum));
       results =
-          entries.get(database).stream()
+          hitCacheEntries.values().stream()
+              .flatMap(List::stream)
               .map(
                   deviceEntry ->
                       ShowDevicesResult.convertDeviceEntry2ShowDeviceResult(
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
index 644a8de0472..6364b8adb59 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
@@ -22,6 +22,7 @@ package 
org.apache.iotdb.db.queryengine.plan.relational.sql.parser;
 import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
 import org.apache.iotdb.commons.auth.entity.PrivilegeType;
 import org.apache.iotdb.commons.cluster.NodeStatus;
+import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.schema.cache.CacheClearOptions;
 import org.apache.iotdb.commons.schema.table.InformationSchema;
@@ -704,17 +705,26 @@ public class AstBuilder extends 
RelationalSqlBaseVisitor<Node> {
 
   private PartialPath parsePrefixPath(final 
RelationalSqlParser.PrefixPathContext ctx) {
     final List<RelationalSqlParser.NodeNameContext> nodeNames = ctx.nodeName();
-    final String[] path = new String[nodeNames.size() + 1];
-    path[0] = ctx.ROOT().getText();
+    final StringBuilder builder = new StringBuilder("root.");
     for (int i = 0; i < nodeNames.size(); i++) {
-      path[i + 1] =
-          parseNodeString(
-              nodeNames.get(i).nodeNameWithoutWildcard() != null
-                  ? ((Identifier) 
visit(nodeNames.get(i).nodeNameWithoutWildcard().identifier()))
-                      .getValue()
-                  : nodeNames.get(i).getText());
-    }
-    return new PartialPath(path);
+      if (nodeNames.get(i).nodeNameWithoutWildcard() != null) {
+        builder
+            .append("`")
+            .append(
+                parseNodeString(
+                    ((Identifier) 
visit(nodeNames.get(i).nodeNameWithoutWildcard().identifier()))
+                        .getValue()))
+            .append("`")
+            .append(i == nodeNames.size() - 1 ? "" : ".");
+      } else {
+        builder.append(nodeNames.get(i).getText());
+      }
+    }
+    try {
+      return new PartialPath(builder.toString());
+    } catch (final IllegalPathException e) {
+      throw new SemanticException(e);
+    }
   }
 
   @Override
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/read/resp/info/impl/ShowDevicesResult.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/read/resp/info/impl/ShowDevicesResult.java
index ce805798715..eb098ac8c8f 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/read/resp/info/impl/ShowDevicesResult.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/read/resp/info/impl/ShowDevicesResult.java
@@ -34,8 +34,9 @@ import java.util.Objects;
 import java.util.function.Function;
 
 public class ShowDevicesResult extends ShowSchemaResult implements 
IDeviceSchemaInfo {
-  private Boolean isAligned;
-  private int templateId;
+
+  private final Boolean isAligned;
+  private final int templateId;
 
   private Function<String, Binary> attributeProvider;
 
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/planner/logical/SchemaQueryLogicalPlannerTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/planner/logical/SchemaQueryLogicalPlannerTest.java
index 83efa9162aa..31de153d287 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/planner/logical/SchemaQueryLogicalPlannerTest.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/planner/logical/SchemaQueryLogicalPlannerTest.java
@@ -580,7 +580,7 @@ public class SchemaQueryLogicalPlannerTest {
           (DevicesSchemaScanNode) metaMergeNode.getChildren().get(0);
       Assert.assertNotNull(showDevicesNode);
       Assert.assertEquals(new PartialPath("root.ln.wf01.wt01"), 
showDevicesNode.getPath());
-      Assert.assertTrue(showDevicesNode.isHasSgCol());
+      Assert.assertTrue(showDevicesNode.isHasDbCol());
       Assert.assertEquals(30, showDevicesNode.getLimit());
       Assert.assertEquals(0, showDevicesNode.getOffset());
       Assert.assertTrue(showDevicesNode.isHasLimit());
@@ -613,7 +613,7 @@ public class SchemaQueryLogicalPlannerTest {
           (DevicesSchemaScanNode) metaMergeNode.getChildren().get(0);
       Assert.assertNotNull(showDevicesNode);
       Assert.assertEquals(new PartialPath("root.ln.wf01.wt01"), 
showDevicesNode.getPath());
-      Assert.assertFalse(showDevicesNode.isHasSgCol());
+      Assert.assertFalse(showDevicesNode.isHasDbCol());
       Assert.assertEquals(
           SchemaFilterType.PATH_CONTAINS, 
showDevicesNode.getSchemaFilter().getSchemaFilterType());
       Assert.assertEquals(
@@ -630,7 +630,7 @@ public class SchemaQueryLogicalPlannerTest {
           (DevicesSchemaScanNode) PlanNodeType.deserialize(byteBuffer);
       Assert.assertNotNull(showDevicesNode2);
       Assert.assertEquals(new PartialPath("root.ln.wf01.wt01"), 
showDevicesNode2.getPath());
-      Assert.assertFalse(showDevicesNode2.isHasSgCol());
+      Assert.assertFalse(showDevicesNode2.isHasDbCol());
       Assert.assertEquals(
           SchemaFilterType.PATH_CONTAINS, 
showDevicesNode2.getSchemaFilter().getSchemaFilterType());
       Assert.assertEquals(
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/column/ColumnHeaderConstant.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/column/ColumnHeaderConstant.java
index 145cb7774fa..aaf2f5f7107 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/column/ColumnHeaderConstant.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/column/ColumnHeaderConstant.java
@@ -340,7 +340,7 @@ public class ColumnHeaderConstant {
           new ColumnHeader(DEADBAND_PARAMETERS, TSDataType.TEXT),
           new ColumnHeader(VIEW_TYPE, TSDataType.TEXT));
 
-  public static final List<ColumnHeader> showDevicesWithSgColumnHeaders =
+  public static final List<ColumnHeader> showDevicesWithDbColumnHeaders =
       ImmutableList.of(
           new ColumnHeader(DEVICE, TSDataType.TEXT),
           new ColumnHeader(DATABASE, TSDataType.TEXT),


Reply via email to