From b1ac9337fb59b44b0281ba6b7d568ce8b3c377c5 Mon Sep 17 00:00:00 2001 From: Leto_b Date: Mon, 12 Jan 2026 17:41:44 +0800 Subject: [PATCH 1/5] add Time Series Data Model and Modeling Design Plan to table management, update related document --- .../Database-Management_apache.md | 189 +++++ .../Database-Management_timecho.md | 189 +++++ .../Basic-Concept/TTL-Delete-Data_apache.md | 145 ++++ .../Basic-Concept/TTL-Delete-Data_timecho.md | 145 ++++ .../Table/Basic-Concept/Table-Management.md | 5 + .../Basic-Concept/Table-Management_apache.md | 309 ++++++++ .../Basic-Concept/Table-Management_timecho.md | 309 ++++++++ .../Table/Reference/System-Tables_apache.md | 600 ++++++++++++++++ .../Table/Reference/System-Tables_timecho.md | 600 ++++++++++++++++ .../SQL-Metadata-Operations_apache.md | 304 ++++++++ .../SQL-Metadata-Operations_timecho.md | 304 ++++++++ .../Maintenance-commands_apache.md | 653 +++++++++++++++++ .../Maintenance-commands_timecho.md | 653 +++++++++++++++++ .../Table/User-Manual/Tree-to-Table_apache.md | 582 +++++++++++++++ .../User-Manual/Tree-to-Table_timecho.md | 582 +++++++++++++++ .../Database-Management_apache.md | 189 +++++ .../Database-Management_timecho.md | 189 +++++ .../Basic-Concept/TTL-Delete-Data_apache.md | 145 ++++ .../Basic-Concept/TTL-Delete-Data_timecho.md | 145 ++++ .../Basic-Concept/Table-Management.md | 4 + .../Basic-Concept/Table-Management_apache.md | 309 ++++++++ .../Basic-Concept/Table-Management_timecho.md | 309 ++++++++ .../Reference/System-Tables_apache.md | 600 ++++++++++++++++ .../Reference/System-Tables_timecho.md | 600 ++++++++++++++++ .../SQL-Metadata-Operations_apache.md | 304 ++++++++ .../SQL-Metadata-Operations_timecho.md | 304 ++++++++ .../Maintenance-commands_apache.md | 653 +++++++++++++++++ .../Maintenance-commands_timecho.md | 653 +++++++++++++++++ .../User-Manual/Tree-to-Table_apache.md | 582 +++++++++++++++ .../User-Manual/Tree-to-Table_timecho.md | 582 +++++++++++++++ .../Database-Management_apache.md | 191 +++++ .../Database-Management_timecho.md | 191 +++++ .../Basic-Concept/TTL-Delete-Data_apache.md | 141 ++++ .../Basic-Concept/TTL-Delete-Data_timecho.md | 141 ++++ .../Table/Basic-Concept/Table-Management.md | 6 +- .../Basic-Concept/Table-Management_apache.md | 315 +++++++++ .../Basic-Concept/Table-Management_timecho.md | 315 +++++++++ .../Table/Reference/System-Tables_apache.md | 593 ++++++++++++++++ .../Table/Reference/System-Tables_timecho.md | 593 ++++++++++++++++ .../SQL-Metadata-Operations_apache.md | 304 ++++++++ .../SQL-Metadata-Operations_timecho.md | 304 ++++++++ .../Maintenance-statement_apache.md | 664 ++++++++++++++++++ .../Maintenance-statement_timecho.md | 664 ++++++++++++++++++ .../Table/User-Manual/Tree-to-Table_apache.md | 579 +++++++++++++++ .../User-Manual/Tree-to-Table_timecho.md | 579 +++++++++++++++ .../Database-Management_apache.md | 191 +++++ .../Database-Management_timecho.md | 191 +++++ .../Basic-Concept/TTL-Delete-Data_apache.md | 141 ++++ .../Basic-Concept/TTL-Delete-Data_timecho.md | 141 ++++ .../Basic-Concept/Table-Management.md | 4 + .../Basic-Concept/Table-Management_apache.md | 315 +++++++++ .../Basic-Concept/Table-Management_timecho.md | 315 +++++++++ .../Reference/System-Tables_apache.md | 593 ++++++++++++++++ .../Reference/System-Tables_timecho.md | 593 ++++++++++++++++ .../SQL-Metadata-Operations_apache.md | 304 ++++++++ .../SQL-Metadata-Operations_timecho.md | 304 ++++++++ .../Maintenance-statement_apache.md | 664 ++++++++++++++++++ .../Maintenance-statement_timecho.md | 664 ++++++++++++++++++ .../User-Manual/Tree-to-Table_apache.md | 579 +++++++++++++++ .../User-Manual/Tree-to-Table_timecho.md | 579 +++++++++++++++ 60 files changed, 22294 insertions(+), 1 deletion(-) create mode 100644 src/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md create mode 100644 src/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md create mode 100644 src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md create mode 100644 src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md create mode 100644 src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md create mode 100644 src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md create mode 100644 src/UserGuide/Master/Table/Reference/System-Tables_apache.md create mode 100644 src/UserGuide/Master/Table/Reference/System-Tables_timecho.md create mode 100644 src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md create mode 100644 src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md create mode 100644 src/UserGuide/Master/Table/User-Manual/Maintenance-commands_apache.md create mode 100644 src/UserGuide/Master/Table/User-Manual/Maintenance-commands_timecho.md create mode 100644 src/UserGuide/Master/Table/User-Manual/Tree-to-Table_apache.md create mode 100644 src/UserGuide/Master/Table/User-Manual/Tree-to-Table_timecho.md create mode 100644 src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md create mode 100644 src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md create mode 100644 src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md create mode 100644 src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md create mode 100644 src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md create mode 100644 src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md create mode 100644 src/UserGuide/latest-Table/Reference/System-Tables_apache.md create mode 100644 src/UserGuide/latest-Table/Reference/System-Tables_timecho.md create mode 100644 src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md create mode 100644 src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md create mode 100644 src/UserGuide/latest-Table/User-Manual/Maintenance-commands_apache.md create mode 100644 src/UserGuide/latest-Table/User-Manual/Maintenance-commands_timecho.md create mode 100644 src/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md create mode 100644 src/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md create mode 100644 src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md create mode 100644 src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md create mode 100644 src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md create mode 100644 src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md create mode 100644 src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md create mode 100644 src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md create mode 100644 src/zh/UserGuide/Master/Table/Reference/System-Tables_apache.md create mode 100644 src/zh/UserGuide/Master/Table/Reference/System-Tables_timecho.md create mode 100644 src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md create mode 100644 src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md create mode 100644 src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement_apache.md create mode 100644 src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement_timecho.md create mode 100644 src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table_apache.md create mode 100644 src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table_timecho.md create mode 100644 src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md create mode 100644 src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md create mode 100644 src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md create mode 100644 src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md create mode 100644 src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md create mode 100644 src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md create mode 100644 src/zh/UserGuide/latest-Table/Reference/System-Tables_apache.md create mode 100644 src/zh/UserGuide/latest-Table/Reference/System-Tables_timecho.md create mode 100644 src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md create mode 100644 src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md create mode 100644 src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_apache.md create mode 100644 src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_timecho.md create mode 100644 src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md create mode 100644 src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md diff --git a/src/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md b/src/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md new file mode 100644 index 000000000..d4414a17e --- /dev/null +++ b/src/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md @@ -0,0 +1,189 @@ + + +# Database Management + +## 1. Database Management + +### 1.1 Create a Database + +This command is used to create a database. + +**Syntax:** + +```SQL + CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +**Note: ** + +1. ``: The name of the database, with the following characteristics: + - Case-insensitive. After creation, it will be displayed uniformly in lowercase. + - Can include commas (`,`), underscores (`_`), numbers, letters, and Chinese characters. + - Maximum length is 64 characters. + - Names with special characters or Chinese characters must be enclosed in double quotes (`""`). + +2. `WITH properties`: Property names are case-insensitive. For more details, refer to the case sensitivity rules [case-sensitivity](../SQL-Manual/Identifier.md#2-case-sensitivity)。Configurable properties include: + +| Property | Description | Default Value | +| ----------------------- | ------------------------------------------------------------ | -------------------- | +| TTL | Automatic data expiration time, in milliseconds | `INF` | +| TIME_PARTITION_INTERVAL | Time partition interval for the database, in milliseconds | `604800000` (7 days) | +| SCHEMA_REGION_GROUP_NUM | Number of metadata replica groups; generally does not require modification | `1` | +| DATA_REGION_GROUP_NUM | Number of data replica groups; generally does not require modification | `2` | + +**Examples:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +// Sets TTL to 1 year. +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 Use a Database + +Specify the current database as the namespace for table operations. + +**Syntax:** + +```SQL +USE +``` + +**Example:** + +```SQL +USE database1 +``` + +### 1.3 View the Current Database + +Displays the name of the currently connected database. If no USE statement has been executed, the default is `null`. + +**Syntax:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**Example:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 View All Databases + +Displays all databases and their properties. + +**Syntax:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +**Columns Explained:** + + +| Column Name | Description | +| ----------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| database | Name of the database. | +| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management_apache.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management_apache.md#14-update-tables) . | +| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | +| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | +| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | +| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | + +**Examples:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 Update a Database + +Used to modify some attributes in the database. + +**Syntax:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**Note:** + +1. The `ALTER DATABASE` operation currently only supports modifications to the database's `SCHEMA_REGION_GROUP_NUM`, `DATA_REGION_GROUP_NUM`, and `TTL` attributes. + +**Example:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 Delete a Database + +Deletes the specified database and all associated tables and data. + +**Syntax:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**Note:** + +1. A database currently in use can still be dropped. +2. Deleting a database removes all its tables and stored data. + +**Example:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` diff --git a/src/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md b/src/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md new file mode 100644 index 000000000..d24e95e28 --- /dev/null +++ b/src/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md @@ -0,0 +1,189 @@ + + +# Database Management + +## 1. Database Management + +### 1.1 Create a Database + +This command is used to create a database. + +**Syntax:** + +```SQL + CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +**Note: ** + +1. ``: The name of the database, with the following characteristics: + - Case-insensitive. After creation, it will be displayed uniformly in lowercase. + - Can include commas (`,`), underscores (`_`), numbers, letters, and Chinese characters. + - Maximum length is 64 characters. + - Names with special characters or Chinese characters must be enclosed in double quotes (`""`). + +2. `WITH properties`: Property names are case-insensitive. For more details, refer to the case sensitivity rules [case-sensitivity](../SQL-Manual/Identifier.md#2-case-sensitivity)。Configurable properties include: + +| Property | Description | Default Value | +| ----------------------- | ------------------------------------------------------------ | -------------------- | +| TTL | Automatic data expiration time, in milliseconds | `INF` | +| TIME_PARTITION_INTERVAL | Time partition interval for the database, in milliseconds | `604800000` (7 days) | +| SCHEMA_REGION_GROUP_NUM | Number of metadata replica groups; generally does not require modification | `1` | +| DATA_REGION_GROUP_NUM | Number of data replica groups; generally does not require modification | `2` | + +**Examples:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +// Sets TTL to 1 year. +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 Use a Database + +Specify the current database as the namespace for table operations. + +**Syntax:** + +```SQL +USE +``` + +**Example:** + +```SQL +USE database1 +``` + +### 1.3 View the Current Database + +Displays the name of the currently connected database. If no USE statement has been executed, the default is `null`. + +**Syntax:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**Example:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 View All Databases + +Displays all databases and their properties. + +**Syntax:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +**Columns Explained:** + + +| Column Name | Description | +| ----------------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| database | Name of the database. | +| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management_timecho.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management_timecho.md#14-update-tables) . | +| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | +| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | +| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | +| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | + +**Examples:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 Update a Database + +Used to modify some attributes in the database. + +**Syntax:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**Note:** + +1. The `ALTER DATABASE` operation currently only supports modifications to the database's `SCHEMA_REGION_GROUP_NUM`, `DATA_REGION_GROUP_NUM`, and `TTL` attributes. + +**Example:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 Delete a Database + +Deletes the specified database and all associated tables and data. + +**Syntax:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**Note:** + +1. A database currently in use can still be dropped. +2. Deleting a database removes all its tables and stored data. + +**Example:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` diff --git a/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md b/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md new file mode 100644 index 000000000..23789deec --- /dev/null +++ b/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md @@ -0,0 +1,145 @@ + + +# TTL Delete Data + +## 1. Overview + +Time-to-Live (TTL) is a mechanism for defining the lifespan of data in a database. In IoTDB, TTL allows setting table-level expiration policies, enabling the system to automatically delete outdated data periodically. This helps manage disk space efficiently, maintain high query performance, and reduce memory usage. + +TTL values are specified in milliseconds, and once data exceeds its defined lifespan, it becomes unavailable for queries and cannot be written to. However, the physical deletion of expired data occurs later during the compaction process. Note that changes to TTL settings can briefly impact the accessibility of data. + +**Notes:** + +1. TTL defines the expiration time of data in milliseconds, independent of the time precision configuration file. +2. Modifying TTL settings can cause temporary variations in data accessibility. +3. The system eventually removes expired data, though this process may involve some delay.。 +4. The TTL expiration check is based on the data point timestamp, not the write time. + +## 2. Set TTL + +In the table model, IoTDB’s TTL operates at the granularity of individual tables. You can set TTL directly on a table or at the database level. When TTL is configured at the database level, it serves as the default for new tables created within the database. However, each table can still have its own independent TTL settings. + +**Note:** Modifying the database-level TTL does not retroactively affect the TTL settings of existing tables. + +### 2.1 Set TTL for Tables + +If TTL is specified when creating a table using SQL, the table’s TTL takes precedence. Refer to [Table-Management](../Basic-Concept/Table-Management_apache.md)for details. + +Example 1: Setting TTL during table creation: + +```SQL +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600) +``` + +Example 2: Changing TTL for an existing table: + +```SQL +ALTER TABLE tableB SET PROPERTIES TTL=3600; +``` + +**Example 3:** If TTL is not specified or set to the default value, it will inherit the database's TTL. By default, the database TTL is `'INF'` (infinite): + +```SQL +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT) +CREATE TABLE test3 ("site" string id, "temperature" int32) +ALTER TABLE tableB set properties TTL=DEFAULT +``` + +### 2.2 Set TTL for Databases + +Tables without explicit TTL settings inherit the TTL of their database. Refer to [Database-Management](../Basic-Concept/Database-Management_apache.md)for details. + +Example 4: A database with TTL=3600000 creates tables inheriting this TTL: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) +``` + +Example 5: A database without a TTL setting creates tables without TTL: + +```SQL +CREATE DATABASE db +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) +``` + +Example 6: Setting a table with no TTL explicitly (TTL=INF) in a database with a configured TTL: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') +``` + +## 3. Remove TTL + +To cancel a TTL setting, modify the table's TTL to 'INF'. Note that IoTDB does not currently support modifying the TTL of a database. + +```SQL +ALTER TABLE tableB set properties TTL='INF' +``` + +## 4. View TTL Information + +Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for databases and tables. Refer to [Database-Management](../Basic-Concept/Database-Management_apache.md)、 [Table-Management](../Basic-Concept/Table-Management_apache.md)for details. + +> Note: TTL settings in tree-model will also be shown. + +Example Output: + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 1| 3| 100000| +| test2| 300| 1| 1| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +|test_prop| 300| 1| 3| 100000|TABLE| +| test2| 300| 1| 1| 604800000| TREE| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +IoTDB> show tables ++---------+-------+ +|TableName|TTL(ms)| ++---------+-------+ +| grass| 1000| +| bamboo| 300| +| flower| INF| ++---------+-------+ + +IoTDB> show tables details ++---------+-------+----------+ +|TableName|TTL(ms)| Status| ++---------+-------+----------+ +| bean| 300|PRE_CREATE| +| grass| 1000| USING| +| bamboo| 300| USING| +| flower| INF| USING| ++---------+-------+----------+ +``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md b/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md new file mode 100644 index 000000000..c29379e6b --- /dev/null +++ b/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md @@ -0,0 +1,145 @@ + + +# TTL Delete Data + +## 1. Overview + +Time-to-Live (TTL) is a mechanism for defining the lifespan of data in a database. In IoTDB, TTL allows setting table-level expiration policies, enabling the system to automatically delete outdated data periodically. This helps manage disk space efficiently, maintain high query performance, and reduce memory usage. + +TTL values are specified in milliseconds, and once data exceeds its defined lifespan, it becomes unavailable for queries and cannot be written to. However, the physical deletion of expired data occurs later during the compaction process. Note that changes to TTL settings can briefly impact the accessibility of data. + +**Notes:** + +1. TTL defines the expiration time of data in milliseconds, independent of the time precision configuration file. +2. Modifying TTL settings can cause temporary variations in data accessibility. +3. The system eventually removes expired data, though this process may involve some delay.。 +4. The TTL expiration check is based on the data point timestamp, not the write time. + +## 2. Set TTL + +In the table model, IoTDB’s TTL operates at the granularity of individual tables. You can set TTL directly on a table or at the database level. When TTL is configured at the database level, it serves as the default for new tables created within the database. However, each table can still have its own independent TTL settings. + +**Note:** Modifying the database-level TTL does not retroactively affect the TTL settings of existing tables. + +### 2.1 Set TTL for Tables + +If TTL is specified when creating a table using SQL, the table’s TTL takes precedence. Refer to [Table-Management](../Basic-Concept/Table-Management_timecho.md)for details. + +Example 1: Setting TTL during table creation: + +```SQL +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600) +``` + +Example 2: Changing TTL for an existing table: + +```SQL +ALTER TABLE tableB SET PROPERTIES TTL=3600; +``` + +**Example 3:** If TTL is not specified or set to the default value, it will inherit the database's TTL. By default, the database TTL is `'INF'` (infinite): + +```SQL +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT) +CREATE TABLE test3 ("site" string id, "temperature" int32) +ALTER TABLE tableB set properties TTL=DEFAULT +``` + +### 2.2 Set TTL for Databases + +Tables without explicit TTL settings inherit the TTL of their database. Refer to [Database-Management](../Basic-Concept/Database-Management_timecho.md)for details. + +Example 4: A database with TTL=3600000 creates tables inheriting this TTL: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) +``` + +Example 5: A database without a TTL setting creates tables without TTL: + +```SQL +CREATE DATABASE db +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) +``` + +Example 6: Setting a table with no TTL explicitly (TTL=INF) in a database with a configured TTL: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') +``` + +## 3. Remove TTL + +To cancel a TTL setting, modify the table's TTL to 'INF'. Note that IoTDB does not currently support modifying the TTL of a database. + +```SQL +ALTER TABLE tableB set properties TTL='INF' +``` + +## 4. View TTL Information + +Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for databases and tables. Refer to [Database-Management](../Basic-Concept/Database-Management_timecho.md)、 [Table-Management](../Basic-Concept/Table-Management_timecho.md)for details. + +> Note: TTL settings in tree-model will also be shown. + +Example Output: + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 1| 3| 100000| +| test2| 300| 1| 1| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +|test_prop| 300| 1| 3| 100000|TABLE| +| test2| 300| 1| 1| 604800000| TREE| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +IoTDB> show tables ++---------+-------+ +|TableName|TTL(ms)| ++---------+-------+ +| grass| 1000| +| bamboo| 300| +| flower| INF| ++---------+-------+ + +IoTDB> show tables details ++---------+-------+----------+ +|TableName|TTL(ms)| Status| ++---------+-------+----------+ +| bean| 300|PRE_CREATE| +| grass| 1000| USING| +| bamboo| 300| USING| +| flower| INF| USING| ++---------+-------+----------+ +``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md b/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md index 20caa49bf..c78cf2091 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md +++ b/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md @@ -21,6 +21,10 @@ # Table Management +Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: +* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. +* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. + ## 1. Table Management ### 1.1 Create a Table @@ -90,6 +94,7 @@ CREATE TABLE table1 ( arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); + CREATE TABLE if not exists table2 (); CREATE TABLE tableC ( diff --git a/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md new file mode 100644 index 000000000..9e5d6f433 --- /dev/null +++ b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md @@ -0,0 +1,309 @@ + + +# Table Management + +Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: +* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. +* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_apache.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. + +## 1. Table Management + +### 1.1 Create a Table + +#### 1.1.1 Manually create a table with CREATE + +Manually create a table within the current or specified database.The format is "database name. table name". + +**Syntax:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +**Note:** + +1. If the time column (`TIME`) is not specified, IoTDB automatically adds one. Other columns can be added using the `enable_auto_create_schema` configuration or session interface commands. +2. Column categories default to `FIELD` if not specified. `TAG` and `ATTRIBUTE` columns must be of type `STRING`. +3. Table `TTL` defaults to the database `TTL`. You can omit this property or set it to `default` if the default value is used. +4. ``: + 1. Case-insensitive. After creation, it will be displayed uniformly in lowercase. + 2. Can include special characters such as `~!`"`%`, etc. + 3. Names with special or Chinese characters must be enclosed in double quotes (`""`). + 4. Outer double quotes are not retained in the final table name. For example: `"a""b"` becomes `a"b`. + 5. Note: In SQL, table or column names with special characters or Chinese characters must be wrapped in double quotes. However, in the native API, do not add extra quotes—otherwise, the quotation marks will become part of the name itself. +5. **`columnDefinition`**: Column names share the same characteristics as table names and can include special characters such as `.`. +6. COMMENT adds comments to the table. + +**Examples:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "Site" STRING TAG, + "Temperature" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +#### 1.1.2 Automatically Create Tables via SESSION + +Tables can be created automatically when inserting data via session. + +**Examples:** + +```Java +try (ITableSession session = + new TableSessionBuilder() + .nodeUrls(Collections.singletonList("127.0.0.1:6667")) + .username("root") + .password("root") + .build()) { + + session.executeNonQueryStatement("CREATE DATABASE db1"); + session.executeNonQueryStatement("use db1"); + + // Insert data without manually creating the table + List columnNameList = + Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); + List dataTypeList = + Arrays.asList( + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.FLOAT, + TSDataType.DOUBLE); + List columnTypeList = + new ArrayList<>( + Arrays.asList( + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.ATTRIBUTE, + ColumnCategory.FIELD, + ColumnCategory.FIELD)); + Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); + for (long timestamp = 0; timestamp < 100; timestamp++) { + int rowIndex = tablet.getRowSize(); + tablet.addTimestamp(rowIndex, timestamp); + tablet.addValue("region_id", rowIndex, "1"); + tablet.addValue("plant_id", rowIndex, "5"); + tablet.addValue("device_id", rowIndex, "3"); + tablet.addValue("model", rowIndex, "A"); + tablet.addValue("temperature", rowIndex, 37.6F); + tablet.addValue("humidity", rowIndex, 111.1); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + session.insert(tablet); + tablet.reset(); + } + } + if (tablet.getRowSize() != 0) { + session.insert(tablet); + tablet.reset(); + } +} +``` + +After the code execution is complete, you can use the following statement to verify that the table has been successfully created, including details about the time column, tag columns, attribute columns, and field columns. + +```SQL +IoTDB> desc table1 ++-----------+---------+-----------+-------+ +| ColumnName| DataType| Category|Comment| ++-----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| region_id| STRING| TAG| null| +| plant_id| STRING| TAG| null| +| device_id| STRING| TAG| null| +| model| STRING| ATTRIBUTE| null| +|temperature| FLOAT| FIELD| null| +| humidity| DOUBLE| FIELD| null| ++-----------+---------+-----------+-------+ +``` + +### 1.2 View Tables + +Used to view all tables and their properties in the current or a specified database. + +**Syntax:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**Note:** + +1. If the `FROM` or `IN` clause is specified, the command lists all tables in the specified database. +2. If neither `FROM` nor `IN` is specified, the command lists all tables in the currently selected database. If no database is selected (`USE` statement not executed), an error is returned. +3. When the `DETAILS` option is used, the command shows the current state of each table: + 1. `USING`: The table is available and operational. + 2. `PRE_CREATE`: The table is in the process of being created or the creation has failed; the table is not available. + 3. `PRE_DELETE`: The table is in the process of being deleted or the deletion has failed; the table will remain permanently unavailable. + +**Examples:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 1.3 View Table Columns + +Used to view column names, data types, categories, and states of a table. + +**Syntax:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**Note:** If the `DETAILS` option is specified, detailed state information of the columns is displayed: + +- `USING`: The column is in normal use. +- `PRE_DELETE`: The column is being deleted or the deletion has failed; it is permanently unavailable. + + + +**Examples:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 1.4 Update Tables + +Used to update a table, including adding or deleting columns and configuring table properties. + +**Syntax:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**Note::** + +1. The `SET PROPERTIES` operation currently only supports configuring the `TTL` property of a table +2. The delete column function only supports deleting the ATTRIBUTE and FILD columns, and the TAG column does not support deletion. +3. The modified comment will overwrite the original comment. If null is specified, the previous comment will be erased. + +**Example:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 1.5 Delete Tables + +Used to delete a table. + +**Syntax:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md new file mode 100644 index 000000000..c78cf2091 --- /dev/null +++ b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md @@ -0,0 +1,309 @@ + + +# Table Management + +Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: +* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. +* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. + +## 1. Table Management + +### 1.1 Create a Table + +#### 1.1.1 Manually create a table with CREATE + +Manually create a table within the current or specified database.The format is "database name. table name". + +**Syntax:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +**Note:** + +1. If the time column (`TIME`) is not specified, IoTDB automatically adds one. Other columns can be added using the `enable_auto_create_schema` configuration or session interface commands. +2. Column categories default to `FIELD` if not specified. `TAG` and `ATTRIBUTE` columns must be of type `STRING`. +3. Table `TTL` defaults to the database `TTL`. You can omit this property or set it to `default` if the default value is used. +4. ``: + 1. Case-insensitive. After creation, it will be displayed uniformly in lowercase. + 2. Can include special characters such as `~!`"`%`, etc. + 3. Names with special or Chinese characters must be enclosed in double quotes (`""`). + 4. Outer double quotes are not retained in the final table name. For example: `"a""b"` becomes `a"b`. + 5. Note: In SQL, table or column names with special characters or Chinese characters must be wrapped in double quotes. However, in the native API, do not add extra quotes—otherwise, the quotation marks will become part of the name itself. +5. **`columnDefinition`**: Column names share the same characteristics as table names and can include special characters such as `.`. +6. COMMENT adds comments to the table. + +**Examples:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "Site" STRING TAG, + "Temperature" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +#### 1.1.2 Automatically Create Tables via SESSION + +Tables can be created automatically when inserting data via session. + +**Examples:** + +```Java +try (ITableSession session = + new TableSessionBuilder() + .nodeUrls(Collections.singletonList("127.0.0.1:6667")) + .username("root") + .password("root") + .build()) { + + session.executeNonQueryStatement("CREATE DATABASE db1"); + session.executeNonQueryStatement("use db1"); + + // Insert data without manually creating the table + List columnNameList = + Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); + List dataTypeList = + Arrays.asList( + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.FLOAT, + TSDataType.DOUBLE); + List columnTypeList = + new ArrayList<>( + Arrays.asList( + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.ATTRIBUTE, + ColumnCategory.FIELD, + ColumnCategory.FIELD)); + Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); + for (long timestamp = 0; timestamp < 100; timestamp++) { + int rowIndex = tablet.getRowSize(); + tablet.addTimestamp(rowIndex, timestamp); + tablet.addValue("region_id", rowIndex, "1"); + tablet.addValue("plant_id", rowIndex, "5"); + tablet.addValue("device_id", rowIndex, "3"); + tablet.addValue("model", rowIndex, "A"); + tablet.addValue("temperature", rowIndex, 37.6F); + tablet.addValue("humidity", rowIndex, 111.1); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + session.insert(tablet); + tablet.reset(); + } + } + if (tablet.getRowSize() != 0) { + session.insert(tablet); + tablet.reset(); + } +} +``` + +After the code execution is complete, you can use the following statement to verify that the table has been successfully created, including details about the time column, tag columns, attribute columns, and field columns. + +```SQL +IoTDB> desc table1 ++-----------+---------+-----------+-------+ +| ColumnName| DataType| Category|Comment| ++-----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| region_id| STRING| TAG| null| +| plant_id| STRING| TAG| null| +| device_id| STRING| TAG| null| +| model| STRING| ATTRIBUTE| null| +|temperature| FLOAT| FIELD| null| +| humidity| DOUBLE| FIELD| null| ++-----------+---------+-----------+-------+ +``` + +### 1.2 View Tables + +Used to view all tables and their properties in the current or a specified database. + +**Syntax:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**Note:** + +1. If the `FROM` or `IN` clause is specified, the command lists all tables in the specified database. +2. If neither `FROM` nor `IN` is specified, the command lists all tables in the currently selected database. If no database is selected (`USE` statement not executed), an error is returned. +3. When the `DETAILS` option is used, the command shows the current state of each table: + 1. `USING`: The table is available and operational. + 2. `PRE_CREATE`: The table is in the process of being created or the creation has failed; the table is not available. + 3. `PRE_DELETE`: The table is in the process of being deleted or the deletion has failed; the table will remain permanently unavailable. + +**Examples:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 1.3 View Table Columns + +Used to view column names, data types, categories, and states of a table. + +**Syntax:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**Note:** If the `DETAILS` option is specified, detailed state information of the columns is displayed: + +- `USING`: The column is in normal use. +- `PRE_DELETE`: The column is being deleted or the deletion has failed; it is permanently unavailable. + + + +**Examples:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 1.4 Update Tables + +Used to update a table, including adding or deleting columns and configuring table properties. + +**Syntax:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**Note::** + +1. The `SET PROPERTIES` operation currently only supports configuring the `TTL` property of a table +2. The delete column function only supports deleting the ATTRIBUTE and FILD columns, and the TAG column does not support deletion. +3. The modified comment will overwrite the original comment. If null is specified, the previous comment will be erased. + +**Example:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 1.5 Delete Tables + +Used to delete a table. + +**Syntax:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/Reference/System-Tables_apache.md b/src/UserGuide/Master/Table/Reference/System-Tables_apache.md new file mode 100644 index 000000000..2f914109d --- /dev/null +++ b/src/UserGuide/Master/Table/Reference/System-Tables_apache.md @@ -0,0 +1,600 @@ + + +# System Tables + +IoTDB has a built-in system database called `INFORMATION_SCHEMA`, which contains a series of system tables for storing IoTDB runtime information (such as currently executing SQL statements, etc.). Currently, the `INFORMATION_SCHEMA` database only supports read operations. + +## 1. System Database + +* ​**Name**​: `INFORMATION_SCHEMA` +* ​**Commands**​: Read-only, only supports `Show databases (DETAILS)` / `Show Tables (DETAILS)` / `Use`. Other operations will result in an error: `"The database 'information_schema' can only be queried."` +* ​**Attributes**​:` TTL=INF`, other attributes default to `null ` +* ​**SQL Example**​: + +```sql +IoTDB> show databases ++------------------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++------------------+-------+-----------------------+---------------------+---------------------+ +|information_schema| INF| null| null| null| ++------------------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show tables from information_schema ++--------------+-------+ +| TableName|TTL(ms)| ++--------------+-------+ +| columns| INF| +| config_nodes| INF| +|configurations| INF| +| data_nodes| INF| +| databases| INF| +| functions| INF| +| keywords| INF| +| models| INF| +| nodes| INF| +| pipe_plugins| INF| +| pipes| INF| +| queries| INF| +| regions| INF| +| subscriptions| INF| +| tables| INF| +| topics| INF| +| views| INF| ++--------------+-------+ +``` + +## 2. System Tables + +* ​**Names**​: `DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES` (detailed descriptions in later sections) +* ​**Operations**​: Read-only, only supports `SELECT`, `COUNT/SHOW DEVICES`, `DESC`. Any modifications to table structure or content are not allowed and will result in an error: `"The database 'information_schema' can only be queried." ` +* ​**Column Names**​: System table column names are all lowercase by default and separated by underscores (`_`). + +### 2.1 DATABASES + +* Contains information about all databases in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| --------------------------------- | ----------- | ------------- | -------------------------------- | +| `database` | STRING | TAG | Database name | +| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | +| `schema_replication_factor` | INT32 | ATTRIBUTE | Schema replica count | +| `data_replication_factor` | INT32 | ATTRIBUTE | Data replica count | +| `time_partition_interval` | INT64 | ATTRIBUTE | Time partition interval | +| `schema_region_group_num` | INT32 | ATTRIBUTE | Number of schema region groups | +| `data_region_group_num` | INT32 | ATTRIBUTE | Number of data region groups | + +* The query results only display the collection of databases for which you have any permission on the database itself or any table within the database. +* Query Example: + +```sql +IoTDB> select * from information_schema.databases ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +|information_schema| INF| null| null| null| null| null| +| database1| INF| 1| 1| 604800000| 0| 0| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +``` + +### 2.2 TABLES + +* Contains information about all tables in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------ | ----------- | ------------- | --------------------- | +| `database` | STRING | TAG | Database name | +| `table_name` | STRING | TAG | Table name | +| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | +| `status` | STRING | ATTRIBUTE | Status | +| `comment` | STRING | ATTRIBUTE | Description/comment | + +* Note: Possible values for `status`: `USING`, `PRE_CREATE`, `PRE_DELETE`. For details, refer to the [View Tables](../Basic-Concept/Table-Management_apache.md#12-view-tables) in Table Management documentation +* The query results only display the collection of tables for which you have any permission. +* Query Example: + +```sql +IoTDB> select * from information_schema.tables ++------------------+--------------+-----------+------+-------+-----------+ +| database| table_name| ttl(ms)|status|comment| table_type| ++------------------+--------------+-----------+------+-------+-----------+ +|information_schema| databases| INF| USING| null|SYSTEM VIEW| +|information_schema| models| INF| USING| null|SYSTEM VIEW| +|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| +|information_schema| regions| INF| USING| null|SYSTEM VIEW| +|information_schema| functions| INF| USING| null|SYSTEM VIEW| +|information_schema| keywords| INF| USING| null|SYSTEM VIEW| +|information_schema| columns| INF| USING| null|SYSTEM VIEW| +|information_schema| topics| INF| USING| null|SYSTEM VIEW| +|information_schema|configurations| INF| USING| null|SYSTEM VIEW| +|information_schema| queries| INF| USING| null|SYSTEM VIEW| +|information_schema| tables| INF| USING| null|SYSTEM VIEW| +|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| +|information_schema| nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| pipes| INF| USING| null|SYSTEM VIEW| +|information_schema| views| INF| USING| null|SYSTEM VIEW| +|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| +| database1| table1|31536000000| USING| null| BASE TABLE| ++------------------+--------------+-----------+------+-------+-----------+ +``` + +### 2.3 REGIONS + +* Contains information about all regions in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------------- | ----------- | ------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `region_id` | INT32 | TAG | Region ID | +| `datanode_id` | INT32 | TAG | DataNode ID | +| `type` | STRING | ATTRIBUTE | Type (`SchemaRegion`/`DataRegion`) | +| `status` | STRING | ATTRIBUTE | Status (`Running`,`Unknown`, etc.) | +| `database` | STRING | ATTRIBUTE | Database name | +| `series_slot_num` | INT32 | ATTRIBUTE | Number of series slots | +| `time_slot_num` | INT64 | ATTRIBUTE | Number of time slots | +| `rpc_address` | STRING | ATTRIBUTE | RPC address | +| `rpc_port` | INT32 | ATTRIBUTE | RPC port | +| `internal_address` | STRING | ATTRIBUTE | Internal communication address | +| `role` | STRING | ATTRIBUTE | Role (`Leader`/`Follower`) | +| `create_time` | TIMESTAMP | ATTRIBUTE | Creation time | +| `tsfile_size_bytes` | INT64 | ATTRIBUTE | - For​**DataRegion with statistics ​**​: Total file size of TsFiles.
- For**DataRegion without statistics**(Unknown):`-1`.
- For​**SchemaRegion**​:`null`. | + +* Only administrators are allowed to perform query operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.regions ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| +| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| +| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +``` + +### 2.4 QUERIES + +* Contains information about all currently executing queries in the cluster. Can also be queried using the `SHOW QUERIES` syntax. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| -------------------- | ----------- | ------------- | ------------------------------------------------------------ | +| `query_id` | STRING | TAG | Query ID | +| `start_time` | TIMESTAMP | ATTRIBUTE | Query start timestamp (precision matches system precision) | +| `datanode_id` | INT32 | ATTRIBUTE | DataNode ID that initiated the query | +| `elapsed_time` | FLOAT | ATTRIBUTE | Query execution duration (in seconds) | +| `statement` | STRING | ATTRIBUTE | SQL statement of the query | +| `user` | STRING | ATTRIBUTE | User who initiated the query | + +* For regular users, the query results only display the queries executed by themselves; for administrators, all queries are displayed. +* Query Example: + +```SQL +IoTDB> select * from information_schema.queries ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +``` + +### 2.5 COLUMNS + +* Contains information about all columns in tables across the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------- | ----------- | ------------- | -------------------- | +| `database` | STRING | TAG | Database name | +| `table_name` | STRING | TAG | Table name | +| `column_name` | STRING | TAG | Column name | +| `datatype` | STRING | ATTRIBUTE | Column data type | +| `category` | STRING | ATTRIBUTE | Column category | +| `status` | STRING | ATTRIBUTE | Column status | +| `comment` | STRING | ATTRIBUTE | Column description | + +Notes: +* Possible values for `status`: `USING`, `PRE_DELETE`. For details, refer to [Viewing Table Columns](../Basic-Concept/Table-Management_apache.html#13-view-table-columns) in Table Management documentation. +* The query results only display the column information of tables for which you have any permission. + +* Query Example: + +```SQL +IoTDB> select * from information_schema.columns where database = 'database1' ++---------+----------+------------+---------+---------+------+-------+ +| database|table_name| column_name| datatype| category|status|comment| ++---------+----------+------------+---------+---------+------+-------+ +|database1| table1| time|TIMESTAMP| TIME| USING| null| +|database1| table1| region| STRING| TAG| USING| null| +|database1| table1| plant_id| STRING| TAG| USING| null| +|database1| table1| device_id| STRING| TAG| USING| null| +|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| +|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| +|database1| table1| temperature| FLOAT| FIELD| USING| null| +|database1| table1| humidity| FLOAT| FIELD| USING| null| +|database1| table1| status| BOOLEAN| FIELD| USING| null| +|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| ++---------+----------+------------+---------+---------+------+-------+ +``` + +### 2.6 PIPES + +* Contains information about all pipes in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ----------------------------------- | ----------- | ------------- | ---------------------------------------------------------- | +| `id` | STRING | TAG | Pipe name | +| `creation_time` | TIMESTAMP | ATTRIBUTE | Creation time | +| `state` | STRING | ATTRIBUTE | Pipe status (`RUNNING`/`STOPPED`) | +| `pipe_source` | STRING | ATTRIBUTE | Source plugin parameters | +| `pipe_processor` | STRING | ATTRIBUTE | Processor plugin parameters | +| `pipe_sink` | STRING | ATTRIBUTE | Sink plugin parameters | +| `exception_message` | STRING | ATTRIBUTE | Exception message | +| `remaining_event_count` | INT64 | ATTRIBUTE | Remaining event count (`-1`if Unknown) | +| `estimated_remaining_seconds` | DOUBLE | ATTRIBUTE | Estimated remaining time in seconds (`-1`if Unknown) | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +select * from information_schema.pipes ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +``` + +### 2.7 PIPE\_PLUGINS + +* Contains information about all PIPE plugins in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------- | ----------- | ------------- | ----------------------------------------------------- | +| `plugin_name` | STRING | TAG | Plugin name | +| `plugin_type` | STRING | ATTRIBUTE | Plugin type (`Builtin`/`External`) | +| `class_name` | STRING | ATTRIBUTE | Plugin's main class name | +| `plugin_jar` | STRING | ATTRIBUTE | Plugin's JAR file name (`null`for builtin type) | + +* Query Example: + +```SQL +IoTDB> select * from information_schema.pipe_plugins ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +| plugin_name|plugin_type| class_name|plugin_jar| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| +| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| +| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| +| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| +| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| +| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +``` + +### 2.8 SUBSCRIPTIONS + +* Contains information about all data subscriptions in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ---------------------------- | ----------- | ------------- | ------------------------- | +| `topic_name` | STRING | TAG | Subscription topic name | +| `consumer_group_name` | STRING | TAG | Consumer group name | +| `subscribed_consumers` | STRING | ATTRIBUTE | Subscribed consumers | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' ++----------+-------------------+--------------------------------+ +|topic_name|consumer_group_name| subscribed_consumers| ++----------+-------------------+--------------------------------+ +| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| ++----------+-------------------+--------------------------------+ +``` + +### 2.9 TOPICS + +* Contains information about all data subscription topics in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| --------------------- | ----------- | ------------- | -------------------------------- | +| `topic_name` | STRING | TAG | Subscription topic name | +| `topic_configs` | STRING | ATTRIBUTE | Topic configuration parameters | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.topics ++----------+----------------------------------------------------------------+ +|topic_name| topic_configs| ++----------+----------------------------------------------------------------+ +| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| ++----------+----------------------------------------------------------------+ +``` + +### 2.10 VIEWS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all table views in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------ | ----------- | ----------------- | --------------------------------- | +| database | STRING | TAG | Database name | +| table\_name | STRING | TAG | View name | +| view\_definition | STRING | ATTRIBUTE | SQL statement for view creation | + +* The query results only display the collection of views for which you have any permission. +* Query example: + +```SQL +IoTDB> select * from information_schema.views ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +| database|table_name| view_definition| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +``` + + +### 2.11 MODELS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all models in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------------------------------------------------------------------------ | +| model\_id | STRING | TAG | Model name | +| model\_type | STRING | ATTRIBUTE | Model type (Forecast, Anomaly Detection, Custom) | +| state | STRING | ATTRIBUTE | Model status (Available/Unavailable) | +| configs | STRING | ATTRIBUTE | String format of model hyperparameters, consistent with the output of the `show` command | +| notes | STRING | ATTRIBUTE | Model description\* Built-in model: Built-in model in IoTDB\* User-defined model: Custom model | + +* Query example: + +```SQL +-- Find all built-in forecast models +IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' ++---------------------+-----------------+------+-------+-----------------------+ +| model_id| model_type| state|configs| notes| ++---------------------+-----------------+------+-------+-----------------------+ +| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| ++---------------------+-----------------+------+-------+-----------------------+ +``` + + +### 2.12 FUNCTIONS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all functions in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------ | ----------- | ----------------- | -------------------------------------------------------------------------- | +| function\_name | STRING | TAG | Function name | +| function\_type | STRING | ATTRIBUTE | Function type (Built-in/User-defined, Scalar/Aggregation/Table Function) | +| class\_name(udf) | STRING | ATTRIBUTE | Class name if it is a UDF, otherwise null (tentative) | +| state | STRING | ATTRIBUTE | Availability status | + +* Query example: + +```SQL +IoTDB> select * from information_schema.functions where function_type='built-in table function' ++--------------+-----------------------+---------------+---------+ +|function_name | function_type|class_name(udf)| state| ++--------------+-----------------------+---------------+---------+ +| CUMULATE|built-in table function| null|AVAILABLE| +| SESSION|built-in table function| null|AVAILABLE| +| HOP|built-in table function| null|AVAILABLE| +| TUMBLE|built-in table function| null|AVAILABLE| +| FORECAST|built-in table function| null|AVAILABLE| +| VARIATION|built-in table function| null|AVAILABLE| +| CAPACITY|built-in table function| null|AVAILABLE| ++--------------+-----------------------+---------------+---------+ +``` + + +### 2.13 CONFIGURATIONS Table + +> This system table is available starting from version V2.0.5. + +* Contains all configuration properties of the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------ | +| variable | STRING | TAG | Configuration property name | +| value | STRING | ATTRIBUTE | Configuration property value | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.configurations ++----------------------------------+-----------------------------------------------------------------+ +| variable| value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + + +### 2.14 KEYWORDS Table + +> This system table is available starting from version V2.0.5. + +* Contains all keywords in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------------------------- | +| word | STRING | TAG | Keyword | +| reserved | INT32 | ATTRIBUTE | Whether it is a reserved word (1 = Yes, 0 = No) | + +* Query example: + +```SQL +IoTDB> select * from information_schema.keywords limit 10 ++----------+--------+ +| word|reserved| ++----------+--------+ +| ABSENT| 0| +|ACTIVATION| 1| +| ACTIVATE| 1| +| ADD| 0| +| ADMIN| 0| +| AFTER| 0| +| AINODES| 1| +| ALL| 0| +| ALTER| 1| +| ANALYZE| 0| ++----------+--------+ +``` + + +### 2.15 NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all nodes in the database cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| -------------------------------------------- | ----------- | ----------------- | ---------------------- | +| node\_id | INT32 | TAG | Node ID | +| node\_type | STRING | ATTRIBUTE | Node type | +| status | STRING | ATTRIBUTE | Node status | +| internal\_address | STRING | ATTRIBUTE | Internal RPC address | +| internal\_port | INT32 | ATTRIBUTE | Internal port | +| version | STRING | ATTRIBUTE | Version number | +| build\_info | STRING | ATTRIBUTE | Commit ID | +| activate\_status (Enterprise Edition only) | STRING | ATTRIBUTE | Activation status | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.nodes ++-------+----------+-------+----------------+-------------+-------+----------+ +|node_id| node_type| status|internal_address|internal_port|version|build_info| ++-------+----------+-------+----------------+-------------+-------+----------+ +| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| +| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| ++-------+----------+-------+----------------+-------------+-------+----------+ +``` + + +### 2.16 CONFIG\_NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all ConfigNodes in the cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------------- | ----------- | ----------------- | --------------------------- | +| node\_id | INT32 | TAG | Node ID | +| config\_consensus\_port | INT32 | ATTRIBUTE | ConfigNode consensus port | +| role | STRING | ATTRIBUTE | ConfigNode role | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.config_nodes ++-------+---------------------+------+ +|node_id|config_consensus_port| role| ++-------+---------------------+------+ +| 0| 10720|Leader| ++-------+---------------------+------+ +``` + + +### 2.17 DATA\_NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all DataNodes in the cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------------- | ----------- | ----------------- | ----------------------------- | +| node\_id | INT32 | TAG | Node ID | +| data\_region\_num | INT32 | ATTRIBUTE | Number of DataRegions | +| schema\_region\_num | INT32 | ATTRIBUTE | Number of SchemaRegions | +| rpc\_address | STRING | ATTRIBUTE | RPC address | +| rpc\_port | INT32 | ATTRIBUTE | RPC port | +| mpp\_port | INT32 | ATTRIBUTE | MPP communication port | +| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion consensus port | +| schema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion consensus port | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.data_nodes ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +``` + +## 3. Permission Description + +* GRANT/REVOKE operations are not supported for the `information_schema` database or any of its tables. +* All users can view `information_schema` database details via the `SHOW DATABASES` statement. +* All users can list system tables via `SHOW TABLES FROM information_schema`. +* All users can inspect system table structures using the `DESC` statement. diff --git a/src/UserGuide/Master/Table/Reference/System-Tables_timecho.md b/src/UserGuide/Master/Table/Reference/System-Tables_timecho.md new file mode 100644 index 000000000..a680e0ebd --- /dev/null +++ b/src/UserGuide/Master/Table/Reference/System-Tables_timecho.md @@ -0,0 +1,600 @@ + + +# System Tables + +IoTDB has a built-in system database called `INFORMATION_SCHEMA`, which contains a series of system tables for storing IoTDB runtime information (such as currently executing SQL statements, etc.). Currently, the `INFORMATION_SCHEMA` database only supports read operations. + +## 1. System Database + +* ​**Name**​: `INFORMATION_SCHEMA` +* ​**Commands**​: Read-only, only supports `Show databases (DETAILS)` / `Show Tables (DETAILS)` / `Use`. Other operations will result in an error: `"The database 'information_schema' can only be queried."` +* ​**Attributes**​:` TTL=INF`, other attributes default to `null ` +* ​**SQL Example**​: + +```sql +IoTDB> show databases ++------------------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++------------------+-------+-----------------------+---------------------+---------------------+ +|information_schema| INF| null| null| null| ++------------------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show tables from information_schema ++--------------+-------+ +| TableName|TTL(ms)| ++--------------+-------+ +| columns| INF| +| config_nodes| INF| +|configurations| INF| +| data_nodes| INF| +| databases| INF| +| functions| INF| +| keywords| INF| +| models| INF| +| nodes| INF| +| pipe_plugins| INF| +| pipes| INF| +| queries| INF| +| regions| INF| +| subscriptions| INF| +| tables| INF| +| topics| INF| +| views| INF| ++--------------+-------+ +``` + +## 2. System Tables + +* ​**Names**​: `DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES` (detailed descriptions in later sections) +* ​**Operations**​: Read-only, only supports `SELECT`, `COUNT/SHOW DEVICES`, `DESC`. Any modifications to table structure or content are not allowed and will result in an error: `"The database 'information_schema' can only be queried." ` +* ​**Column Names**​: System table column names are all lowercase by default and separated by underscores (`_`). + +### 2.1 DATABASES + +* Contains information about all databases in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| --------------------------------- | ----------- | ------------- | -------------------------------- | +| `database` | STRING | TAG | Database name | +| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | +| `schema_replication_factor` | INT32 | ATTRIBUTE | Schema replica count | +| `data_replication_factor` | INT32 | ATTRIBUTE | Data replica count | +| `time_partition_interval` | INT64 | ATTRIBUTE | Time partition interval | +| `schema_region_group_num` | INT32 | ATTRIBUTE | Number of schema region groups | +| `data_region_group_num` | INT32 | ATTRIBUTE | Number of data region groups | + +* The query results only display the collection of databases for which you have any permission on the database itself or any table within the database. +* Query Example: + +```sql +IoTDB> select * from information_schema.databases ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +|information_schema| INF| null| null| null| null| null| +| database1| INF| 1| 1| 604800000| 0| 0| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +``` + +### 2.2 TABLES + +* Contains information about all tables in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------ | ----------- | ------------- | --------------------- | +| `database` | STRING | TAG | Database name | +| `table_name` | STRING | TAG | Table name | +| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | +| `status` | STRING | ATTRIBUTE | Status | +| `comment` | STRING | ATTRIBUTE | Description/comment | + +* Note: Possible values for `status`: `USING`, `PRE_CREATE`, `PRE_DELETE`. For details, refer to the [View Tables](../Basic-Concept/Table-Management_timecho.md#12-view-tables) in Table Management documentation +* The query results only display the collection of tables for which you have any permission. +* Query Example: + +```sql +IoTDB> select * from information_schema.tables ++------------------+--------------+-----------+------+-------+-----------+ +| database| table_name| ttl(ms)|status|comment| table_type| ++------------------+--------------+-----------+------+-------+-----------+ +|information_schema| databases| INF| USING| null|SYSTEM VIEW| +|information_schema| models| INF| USING| null|SYSTEM VIEW| +|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| +|information_schema| regions| INF| USING| null|SYSTEM VIEW| +|information_schema| functions| INF| USING| null|SYSTEM VIEW| +|information_schema| keywords| INF| USING| null|SYSTEM VIEW| +|information_schema| columns| INF| USING| null|SYSTEM VIEW| +|information_schema| topics| INF| USING| null|SYSTEM VIEW| +|information_schema|configurations| INF| USING| null|SYSTEM VIEW| +|information_schema| queries| INF| USING| null|SYSTEM VIEW| +|information_schema| tables| INF| USING| null|SYSTEM VIEW| +|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| +|information_schema| nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| pipes| INF| USING| null|SYSTEM VIEW| +|information_schema| views| INF| USING| null|SYSTEM VIEW| +|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| +| database1| table1|31536000000| USING| null| BASE TABLE| ++------------------+--------------+-----------+------+-------+-----------+ +``` + +### 2.3 REGIONS + +* Contains information about all regions in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------------- | ----------- | ------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `region_id` | INT32 | TAG | Region ID | +| `datanode_id` | INT32 | TAG | DataNode ID | +| `type` | STRING | ATTRIBUTE | Type (`SchemaRegion`/`DataRegion`) | +| `status` | STRING | ATTRIBUTE | Status (`Running`,`Unknown`, etc.) | +| `database` | STRING | ATTRIBUTE | Database name | +| `series_slot_num` | INT32 | ATTRIBUTE | Number of series slots | +| `time_slot_num` | INT64 | ATTRIBUTE | Number of time slots | +| `rpc_address` | STRING | ATTRIBUTE | RPC address | +| `rpc_port` | INT32 | ATTRIBUTE | RPC port | +| `internal_address` | STRING | ATTRIBUTE | Internal communication address | +| `role` | STRING | ATTRIBUTE | Role (`Leader`/`Follower`) | +| `create_time` | TIMESTAMP | ATTRIBUTE | Creation time | +| `tsfile_size_bytes` | INT64 | ATTRIBUTE | - For​**DataRegion with statistics ​**​: Total file size of TsFiles.
- For**DataRegion without statistics**(Unknown):`-1`.
- For​**SchemaRegion**​:`null`. | + +* Only administrators are allowed to perform query operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.regions ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| +| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| +| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +``` + +### 2.4 QUERIES + +* Contains information about all currently executing queries in the cluster. Can also be queried using the `SHOW QUERIES` syntax. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| -------------------- | ----------- | ------------- | ------------------------------------------------------------ | +| `query_id` | STRING | TAG | Query ID | +| `start_time` | TIMESTAMP | ATTRIBUTE | Query start timestamp (precision matches system precision) | +| `datanode_id` | INT32 | ATTRIBUTE | DataNode ID that initiated the query | +| `elapsed_time` | FLOAT | ATTRIBUTE | Query execution duration (in seconds) | +| `statement` | STRING | ATTRIBUTE | SQL statement of the query | +| `user` | STRING | ATTRIBUTE | User who initiated the query | + +* For regular users, the query results only display the queries executed by themselves; for administrators, all queries are displayed. +* Query Example: + +```SQL +IoTDB> select * from information_schema.queries ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +``` + +### 2.5 COLUMNS + +* Contains information about all columns in tables across the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------- | ----------- | ------------- | -------------------- | +| `database` | STRING | TAG | Database name | +| `table_name` | STRING | TAG | Table name | +| `column_name` | STRING | TAG | Column name | +| `datatype` | STRING | ATTRIBUTE | Column data type | +| `category` | STRING | ATTRIBUTE | Column category | +| `status` | STRING | ATTRIBUTE | Column status | +| `comment` | STRING | ATTRIBUTE | Column description | + +Notes: +* Possible values for `status`: `USING`, `PRE_DELETE`. For details, refer to [Viewing Table Columns](../Basic-Concept/Table-Management_timecho.html#13-view-table-columns) in Table Management documentation. +* The query results only display the column information of tables for which you have any permission. + +* Query Example: + +```SQL +IoTDB> select * from information_schema.columns where database = 'database1' ++---------+----------+------------+---------+---------+------+-------+ +| database|table_name| column_name| datatype| category|status|comment| ++---------+----------+------------+---------+---------+------+-------+ +|database1| table1| time|TIMESTAMP| TIME| USING| null| +|database1| table1| region| STRING| TAG| USING| null| +|database1| table1| plant_id| STRING| TAG| USING| null| +|database1| table1| device_id| STRING| TAG| USING| null| +|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| +|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| +|database1| table1| temperature| FLOAT| FIELD| USING| null| +|database1| table1| humidity| FLOAT| FIELD| USING| null| +|database1| table1| status| BOOLEAN| FIELD| USING| null| +|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| ++---------+----------+------------+---------+---------+------+-------+ +``` + +### 2.6 PIPES + +* Contains information about all pipes in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ----------------------------------- | ----------- | ------------- | ---------------------------------------------------------- | +| `id` | STRING | TAG | Pipe name | +| `creation_time` | TIMESTAMP | ATTRIBUTE | Creation time | +| `state` | STRING | ATTRIBUTE | Pipe status (`RUNNING`/`STOPPED`) | +| `pipe_source` | STRING | ATTRIBUTE | Source plugin parameters | +| `pipe_processor` | STRING | ATTRIBUTE | Processor plugin parameters | +| `pipe_sink` | STRING | ATTRIBUTE | Sink plugin parameters | +| `exception_message` | STRING | ATTRIBUTE | Exception message | +| `remaining_event_count` | INT64 | ATTRIBUTE | Remaining event count (`-1`if Unknown) | +| `estimated_remaining_seconds` | DOUBLE | ATTRIBUTE | Estimated remaining time in seconds (`-1`if Unknown) | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +select * from information_schema.pipes ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +``` + +### 2.7 PIPE\_PLUGINS + +* Contains information about all PIPE plugins in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------- | ----------- | ------------- | ----------------------------------------------------- | +| `plugin_name` | STRING | TAG | Plugin name | +| `plugin_type` | STRING | ATTRIBUTE | Plugin type (`Builtin`/`External`) | +| `class_name` | STRING | ATTRIBUTE | Plugin's main class name | +| `plugin_jar` | STRING | ATTRIBUTE | Plugin's JAR file name (`null`for builtin type) | + +* Query Example: + +```SQL +IoTDB> select * from information_schema.pipe_plugins ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +| plugin_name|plugin_type| class_name|plugin_jar| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| +| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| +| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| +| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| +| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| +| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +``` + +### 2.8 SUBSCRIPTIONS + +* Contains information about all data subscriptions in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ---------------------------- | ----------- | ------------- | ------------------------- | +| `topic_name` | STRING | TAG | Subscription topic name | +| `consumer_group_name` | STRING | TAG | Consumer group name | +| `subscribed_consumers` | STRING | ATTRIBUTE | Subscribed consumers | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' ++----------+-------------------+--------------------------------+ +|topic_name|consumer_group_name| subscribed_consumers| ++----------+-------------------+--------------------------------+ +| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| ++----------+-------------------+--------------------------------+ +``` + +### 2.9 TOPICS + +* Contains information about all data subscription topics in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| --------------------- | ----------- | ------------- | -------------------------------- | +| `topic_name` | STRING | TAG | Subscription topic name | +| `topic_configs` | STRING | ATTRIBUTE | Topic configuration parameters | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.topics ++----------+----------------------------------------------------------------+ +|topic_name| topic_configs| ++----------+----------------------------------------------------------------+ +| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| ++----------+----------------------------------------------------------------+ +``` + +### 2.10 VIEWS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all table views in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------ | ----------- | ----------------- | --------------------------------- | +| database | STRING | TAG | Database name | +| table\_name | STRING | TAG | View name | +| view\_definition | STRING | ATTRIBUTE | SQL statement for view creation | + +* The query results only display the collection of views for which you have any permission. +* Query example: + +```SQL +IoTDB> select * from information_schema.views ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +| database|table_name| view_definition| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +``` + + +### 2.11 MODELS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all models in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------------------------------------------------------------------------ | +| model\_id | STRING | TAG | Model name | +| model\_type | STRING | ATTRIBUTE | Model type (Forecast, Anomaly Detection, Custom) | +| state | STRING | ATTRIBUTE | Model status (Available/Unavailable) | +| configs | STRING | ATTRIBUTE | String format of model hyperparameters, consistent with the output of the `show` command | +| notes | STRING | ATTRIBUTE | Model description\* Built-in model: Built-in model in IoTDB\* User-defined model: Custom model | + +* Query example: + +```SQL +-- Find all built-in forecast models +IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' ++---------------------+-----------------+------+-------+-----------------------+ +| model_id| model_type| state|configs| notes| ++---------------------+-----------------+------+-------+-----------------------+ +| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| ++---------------------+-----------------+------+-------+-----------------------+ +``` + + +### 2.12 FUNCTIONS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all functions in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------ | ----------- | ----------------- | -------------------------------------------------------------------------- | +| function\_name | STRING | TAG | Function name | +| function\_type | STRING | ATTRIBUTE | Function type (Built-in/User-defined, Scalar/Aggregation/Table Function) | +| class\_name(udf) | STRING | ATTRIBUTE | Class name if it is a UDF, otherwise null (tentative) | +| state | STRING | ATTRIBUTE | Availability status | + +* Query example: + +```SQL +IoTDB> select * from information_schema.functions where function_type='built-in table function' ++--------------+-----------------------+---------------+---------+ +|function_name | function_type|class_name(udf)| state| ++--------------+-----------------------+---------------+---------+ +| CUMULATE|built-in table function| null|AVAILABLE| +| SESSION|built-in table function| null|AVAILABLE| +| HOP|built-in table function| null|AVAILABLE| +| TUMBLE|built-in table function| null|AVAILABLE| +| FORECAST|built-in table function| null|AVAILABLE| +| VARIATION|built-in table function| null|AVAILABLE| +| CAPACITY|built-in table function| null|AVAILABLE| ++--------------+-----------------------+---------------+---------+ +``` + + +### 2.13 CONFIGURATIONS Table + +> This system table is available starting from version V2.0.5. + +* Contains all configuration properties of the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------ | +| variable | STRING | TAG | Configuration property name | +| value | STRING | ATTRIBUTE | Configuration property value | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.configurations ++----------------------------------+-----------------------------------------------------------------+ +| variable| value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + + +### 2.14 KEYWORDS Table + +> This system table is available starting from version V2.0.5. + +* Contains all keywords in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------------------------- | +| word | STRING | TAG | Keyword | +| reserved | INT32 | ATTRIBUTE | Whether it is a reserved word (1 = Yes, 0 = No) | + +* Query example: + +```SQL +IoTDB> select * from information_schema.keywords limit 10 ++----------+--------+ +| word|reserved| ++----------+--------+ +| ABSENT| 0| +|ACTIVATION| 1| +| ACTIVATE| 1| +| ADD| 0| +| ADMIN| 0| +| AFTER| 0| +| AINODES| 1| +| ALL| 0| +| ALTER| 1| +| ANALYZE| 0| ++----------+--------+ +``` + + +### 2.15 NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all nodes in the database cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| -------------------------------------------- | ----------- | ----------------- | ---------------------- | +| node\_id | INT32 | TAG | Node ID | +| node\_type | STRING | ATTRIBUTE | Node type | +| status | STRING | ATTRIBUTE | Node status | +| internal\_address | STRING | ATTRIBUTE | Internal RPC address | +| internal\_port | INT32 | ATTRIBUTE | Internal port | +| version | STRING | ATTRIBUTE | Version number | +| build\_info | STRING | ATTRIBUTE | Commit ID | +| activate\_status (Enterprise Edition only) | STRING | ATTRIBUTE | Activation status | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.nodes ++-------+----------+-------+----------------+-------------+-------+----------+ +|node_id| node_type| status|internal_address|internal_port|version|build_info| ++-------+----------+-------+----------------+-------------+-------+----------+ +| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| +| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| ++-------+----------+-------+----------------+-------------+-------+----------+ +``` + + +### 2.16 CONFIG\_NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all ConfigNodes in the cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------------- | ----------- | ----------------- | --------------------------- | +| node\_id | INT32 | TAG | Node ID | +| config\_consensus\_port | INT32 | ATTRIBUTE | ConfigNode consensus port | +| role | STRING | ATTRIBUTE | ConfigNode role | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.config_nodes ++-------+---------------------+------+ +|node_id|config_consensus_port| role| ++-------+---------------------+------+ +| 0| 10720|Leader| ++-------+---------------------+------+ +``` + + +### 2.17 DATA\_NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all DataNodes in the cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------------- | ----------- | ----------------- | ----------------------------- | +| node\_id | INT32 | TAG | Node ID | +| data\_region\_num | INT32 | ATTRIBUTE | Number of DataRegions | +| schema\_region\_num | INT32 | ATTRIBUTE | Number of SchemaRegions | +| rpc\_address | STRING | ATTRIBUTE | RPC address | +| rpc\_port | INT32 | ATTRIBUTE | RPC port | +| mpp\_port | INT32 | ATTRIBUTE | MPP communication port | +| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion consensus port | +| schema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion consensus port | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.data_nodes ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +``` + +## 3. Permission Description + +* GRANT/REVOKE operations are not supported for the `information_schema` database or any of its tables. +* All users can view `information_schema` database details via the `SHOW DATABASES` statement. +* All users can list system tables via `SHOW TABLES FROM information_schema`. +* All users can inspect system table structures using the `DESC` statement. diff --git a/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md b/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md new file mode 100644 index 000000000..625e2ed75 --- /dev/null +++ b/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md @@ -0,0 +1,304 @@ + + +# Metadata Operations + +## 1. Database Management + +### 1.1 Create Database + +**Syntax:** + +```SQL +CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +[Detailed syntax reference](../Basic-Concept/Database-Management_apache.md#_1-1-create-a-database) + +**Examples:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +-- Create database with 1-year TTL +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 Use Database + +**Syntax:** + +```SQL +USE +``` + +**Examples:** + +```SQL +USE database1 +``` + +### 1.3 View Current Database + +**Syntax:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**Examples:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 List All Databases + +**Syntax:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +[Detailed syntax reference](../Basic-Concept/Database-Management_apache.md#_1-4-view-all-databases) + +**Examples:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 Modify Database + +**Syntax:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**Examples:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 Drop Database + +**Syntax:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` + +## 2. Table Management + +### 2.1 Create Table + +**Syntax:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +[Detailed syntax reference](../Basic-Concept/Table-Management_apache.md#_1-1-create-a-table) + +**Examples:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status BOOLEAN FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE IF NOT EXISTS table2 (); + +CREATE TABLE tableC ( + "plant" STRING TAG, + "temperature" INT32 FIELD COMMENT 'temperature' +) WITH (TTL=DEFAULT); +``` + +### 2.2 List Tables + +**Syntax:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**Examples:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 2.3 Describe Table Columns + +**Syntax:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**Examples:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 2.4 Modify Table + +**Syntax:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**Examples:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 2.5 Drop Table + +**Syntax:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` + + diff --git a/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md b/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md new file mode 100644 index 000000000..d3f8967d9 --- /dev/null +++ b/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md @@ -0,0 +1,304 @@ + + +# Metadata Operations + +## 1. Database Management + +### 1.1 Create Database + +**Syntax:** + +```SQL +CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +[Detailed syntax reference](../Basic-Concept/Database-Management_timecho.md#_1-1-create-a-database) + +**Examples:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +-- Create database with 1-year TTL +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 Use Database + +**Syntax:** + +```SQL +USE +``` + +**Examples:** + +```SQL +USE database1 +``` + +### 1.3 View Current Database + +**Syntax:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**Examples:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 List All Databases + +**Syntax:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +[Detailed syntax reference](../Basic-Concept/Database-Management_timecho.md#_1-4-view-all-databases) + +**Examples:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 Modify Database + +**Syntax:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**Examples:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 Drop Database + +**Syntax:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` + +## 2. Table Management + +### 2.1 Create Table + +**Syntax:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +[Detailed syntax reference](../Basic-Concept/Table-Management_timecho.md#_1-1-create-a-table) + +**Examples:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status BOOLEAN FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE IF NOT EXISTS table2 (); + +CREATE TABLE tableC ( + "plant" STRING TAG, + "temperature" INT32 FIELD COMMENT 'temperature' +) WITH (TTL=DEFAULT); +``` + +### 2.2 List Tables + +**Syntax:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**Examples:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 2.3 Describe Table Columns + +**Syntax:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**Examples:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 2.4 Modify Table + +**Syntax:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**Examples:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 2.5 Drop Table + +**Syntax:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` + + diff --git a/src/UserGuide/Master/Table/User-Manual/Maintenance-commands_apache.md b/src/UserGuide/Master/Table/User-Manual/Maintenance-commands_apache.md new file mode 100644 index 000000000..e2be89e66 --- /dev/null +++ b/src/UserGuide/Master/Table/User-Manual/Maintenance-commands_apache.md @@ -0,0 +1,653 @@ + +# Maintenance Statement + +## 1. Status Checking + +### 1.1 Viewing the Connected Model + +**Description**: Returns the current SQL dialect model (`Tree` or `Table`). + +**Syntax**: + +```SQL +showCurrentSqlDialectStatement + : SHOW CURRENT_SQL_DIALECT + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_SQL_DIALECT; +``` + +**Result:** + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 1.2 Viewing the Logged-in Username + +**Description**: Returns the currently logged-in username. + +**Syntax**: + +```SQL +showCurrentUserStatement + : SHOW CURRENT_USER + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_USER; +``` + +**Result**: + +```Plain ++-----------+ +|CurrentUser| ++-----------+ +| root| ++-----------+ +``` + +### 1.3 Viewing the Connected Database Name + +**Description**: Returns the name of the currently connected database. If no `USE` statement has been executed, it returns `null`. + +**Syntax**: + +```SQL +showCurrentDatabaseStatement + : SHOW CURRENT_DATABASE + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_DATABASE; +IoTDB> USE test; +IoTDB> SHOW CURRENT_DATABASE; +``` + +**Result**: + +```Plain ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ ++---------------+ +|CurrentDatabase| ++---------------+ +| test| ++---------------+ +``` + +### 1.4 Viewing the Cluster Version + +**Description**: Returns the current cluster version. + +**Syntax**: + +```SQL +showVersionStatement + : SHOW VERSION + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW VERSION; +``` + +**Result**: + +```Plain ++-------+---------+ +|Version|BuildInfo| ++-------+---------+ +|2.0.1.2| 1ca4008| ++-------+---------+ +``` + +### 1.5 Viewing Cluster Key Parameters + +**Description**: Returns key parameters of the current cluster. + +**Syntax**: + +```SQL +showVariablesStatement + : SHOW VARIABLES + ; +``` + +Key Parameters: + +1. **ClusterName**: The name of the current cluster. +2. **DataReplicationFactor**: Number of data replicas per DataRegion. +3. **SchemaReplicationFactor**: Number of schema replicas per SchemaRegion. +4. **DataRegionConsensusProtocolClass**: Consensus protocol class for DataRegions. +5. **SchemaRegionConsensusProtocolClass**: Consensus protocol class for SchemaRegions. +6. **ConfigNodeConsensusProtocolClass**: Consensus protocol class for ConfigNodes. +7. **TimePartitionOrigin**: The starting timestamp of database time partitions. +8. **TimePartitionInterval**: The interval of database time partitions (in milliseconds). +9. **ReadConsistencyLevel**: The consistency level for read operations. +10. **SchemaRegionPerDataNode**: Number of SchemaRegions per DataNode. +11. **DataRegionPerDataNode**: Number of DataRegions per DataNode. +12. **SeriesSlotNum**: Number of SeriesSlots per DataRegion. +13. **SeriesSlotExecutorClass**: Implementation class for SeriesSlots. +14. **DiskSpaceWarningThreshold**: Disk space warning threshold (in percentage). +15. **TimestampPrecision**: Timestamp precision. + +**Example**: + +```SQL +IoTDB> SHOW VARIABLES; +``` + +**Result**: + +```Plain ++----------------------------------+-----------------------------------------------------------------+ +| Variable| Value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 1.6 Viewing the Cluster ID + +**Description**: Returns the ID of the current cluster. + +**Syntax**: + +```SQL +showClusterIdStatement + : SHOW (CLUSTERID | CLUSTER_ID) + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CLUSTER_ID; +``` + +**Result**: + +```Plain ++------------------------------------+ +| ClusterId| ++------------------------------------+ +|40163007-9ec1-4455-aa36-8055d740fcda| ++------------------------------------+ +``` + +### 1.7 Viewing the Timestamp of the Connected DataNode + +**Description**: Returns the current timestamp of the DataNode process directly connected to the client. + +**Syntax**: + +```SQL +showCurrentTimestampStatement + : SHOW CURRENT_TIMESTAMP + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_TIMESTAMP; +``` + +**Result**: + +```Plain ++-----------------------------+ +| CurrentTimestamp| ++-----------------------------+ +|2025-02-17T11:11:52.987+08:00| ++-----------------------------+ +``` + +### 1.8 Viewing Executing Queries + +**Description**: Displays information about all currently executing queries. + +> For more details on how to use system tables, please refer to [System Tables](../Reference/System-Tables_apache.md) + +**Syntax**: + +```SQL +showQueriesStatement + : SHOW (QUERIES | QUERY PROCESSLIST) + (WHERE where=booleanExpression)? + (ORDER BY sortItem (',' sortItem)*)? + limitOffsetClause + ; +``` + +**Parameters**: + +1. **WHERE Clause**: Filters the result set based on specified conditions. +2. **ORDER BY Clause**: Sorts the result set based on specified columns. +3. **limitOffsetClause**: Limits the number of rows returned. + 1. Format: `LIMIT , `. + +**Columns in QUERIES Table**: + +- **query_id**: Unique ID of the query. +- **start_time**: Timestamp when the query started. +- **datanode_id**: ID of the DataNode executing the query. +- **elapsed_time**: Time elapsed since the query started (in seconds). +- **statement**: The SQL statement being executed. +- **user**: The user who initiated the query. + +**Example**: + +```SQL +IoTDB> SHOW QUERIES WHERE elapsed_time > 30; +``` + +**Result**: + +```Plain ++-----------------------+-----------------------------+-----------+------------+------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +``` + + +### 1.9 Viewing Region Information + +**Description**: Displays regions' information of the current cluster. + +**Syntax**: + +```SQL +showRegionsStatement + : SHOW REGIONS + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW REGIONS +``` + +**Result**: + +```SQL ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | +| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| +| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +``` + + +## 2. Status Setting + +### 2.1 Setting the Connected Model + +**Description**: Sets the current SQL dialect model to `Tree` or `Table` which can be used in both tree and table models. + +**Syntax**: + +```SQL +SET SQL_DIALECT = (TABLE | TREE); +``` + +**Example**: + +```SQL +IoTDB> SET SQL_DIALECT=TABLE; +IoTDB> SHOW CURRENT_SQL_DIALECT; +``` + +**Result**: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 2.2 Updating Configuration Items + +**Description**: Updates configuration items. Changes take effect immediately without restarting if the items support hot modification. + +**Syntax**: + +```SQL +setConfigurationStatement + : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? + ; + +propertyAssignments + : property (',' property)* + ; + +property + : identifier EQ propertyValue + ; + +propertyValue + : DEFAULT + | expression + ; +``` + +**Parameters**: + +1. **propertyAssignments**: A list of properties to update. + 1. Format: `property (',' property)*`. + 2. Values: + - `DEFAULT`: Resets the configuration to its default value. + - `expression`: A specific value (must be a string). +2. **ON INTEGER_VALUE** **(Optional):** Specifies the node ID to update. + 1. If not specified or set to a negative value, updates all ConfigNodes and DataNodes. + +**Example**: + +```SQL +IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; +``` + +### 2.3 Loading Manually Modified Configuration Files + +**Description**: Loads manually modified configuration files and hot-loads the changes. Configuration items that support hot modification take effect immediately. + +**Syntax**: + +```SQL +loadConfigurationStatement + : LOAD CONFIGURATION localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode** **(Optional):** + 1. Specifies the scope of configuration loading. + 2. Default: `CLUSTER`. + 3. Values: + - `LOCAL`: Loads configuration only on the DataNode directly connected to the client. + - `CLUSTER`: Loads configuration on all DataNodes in the cluster. + +**Example**: + +```SQL +IoTDB> LOAD CONFIGURATION ON LOCAL; +``` + +### 2.4 Setting the System Status + +**Description**: Sets the system status to either `READONLY` or `RUNNING`. + +**Syntax**: + +```SQL +setSystemStatusStatement + : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **RUNNING |** **READONLY**: + 1. **RUNNING**: Sets the system to running mode, allowing both read and write operations. + 2. **READONLY**: Sets the system to read-only mode, allowing only read operations and prohibiting writes. +2. **localOrClusterMode** **(Optional):** + 1. **LOCAL**: Applies the status change only to the DataNode directly connected to the client. + 2. **CLUSTER**: Applies the status change to all DataNodes in the cluster. + 3. **Default**: `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> SET SYSTEM TO READONLY ON CLUSTER; +``` + +## 3. Data Management + +### 3.1 Flushing Data from Memory to Disk + +**Description**: Flushes data from the memory table to disk. + +**Syntax**: + +```SQL +flushStatement + : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? + ; + +booleanValue + : TRUE | FALSE + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **identifier** **(Optional):** + 1. Specifies the name of the database to flush. + 2. If not specified, all databases are flushed. + 3. **Multiple Databases**: Multiple database names can be specified, separated by commas (e.g., `FLUSH test_db1, test_db2`). +2. **booleanValue** **(****Optional****)**: + 1. Specifies the type of data to flush. + 2. **TRUE**: Flushes only the sequential memory table. + 3. **FALSE**: Flushes only the unsequential MemTable. + 4. **Default**: Flushes both sequential and unsequential memory tables. +3. **localOrClusterMode** **(****Optional****)**: + 1. **ON LOCAL**: Flushes only the memory tables on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Flushes memory tables on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> FLUSH test_db TRUE ON LOCAL; +``` + +### 3.2 Clearing Cache on DataNode + +**Description**: Clears a specific type of cache on DataNode. + +**Syntax**: + +```SQL +clearCacheStatement + : CLEAR clearCacheOptions? CACHE localOrClusterMode? + ; + +clearCacheOptions + : ATTRIBUTE + | QUERY + | ALL + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **clearCacheOptions(Optional)**: + 1. Specifies the type of cache to clear. + 2. **ATTRIBUTE**: Clears device attribute cache. + 3. **QUERY**: Clears query cache in the storage engine. + 4. **ALL**: Clears all caches, including device attribute cache, query cache, and schema cache in the tree model. + 5. **Default**: `QUERY`. +2. **localOrClusterMode(Optional)**: + 1. **ON LOCAL**: Clears cache only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Clears cache on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> CLEAR ALL CACHE ON LOCAL; +``` + +## 4. Data Repair + +### 4.1 Starting Background Scan and Repair of TsFiles + +**Description**: Starts a background task to scan and repair TsFiles, fixing issues such as timestamp disorder within data files. + +**Syntax**: + +```SQL +startRepairDataStatement + : START REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode(Optional)**: + 1. **ON LOCAL**: Executes the repair task only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Executes the repair task on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> START REPAIR DATA ON CLUSTER; +``` + +### 4.2 Pausing Background TsFile Repair Task + +**Description**: Pauses the background repair task. The paused task can be resumed by executing the `START REPAIR DATA` command again. + +**Syntax**: + +```SQL +stopRepairDataStatement + : STOP REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode** **(Optional):** + 1. **ON LOCAL**: Executes the pause command only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Executes the pause command on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> STOP REPAIR DATA ON CLUSTER; +``` + +## 5. Query Termination + +### 5.1 Terminating Queries + +**Description**: Terminates one or more running queries. + +**Syntax**: + +```SQL +killQueryStatement + : KILL (QUERY queryId=string | ALL QUERIES) + ; +``` + +**Parameters**: + +1. **QUERY** **queryId:** Specifies the ID of the query to terminate. + +- To obtain the `queryId`, use the `SHOW QUERIES` command. + +2. **ALL QUERIES:** Terminates all currently running queries. + +**Example**: + +Terminate a specific query: + +```SQL +IoTDB> KILL QUERY 20250108_101015_00000_1; +``` + +Terminate all queries: + +```SQL +IoTDB> KILL ALL QUERIES; +``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/User-Manual/Maintenance-commands_timecho.md b/src/UserGuide/Master/Table/User-Manual/Maintenance-commands_timecho.md new file mode 100644 index 000000000..c4c4feec5 --- /dev/null +++ b/src/UserGuide/Master/Table/User-Manual/Maintenance-commands_timecho.md @@ -0,0 +1,653 @@ + +# Maintenance Statement + +## 1. Status Checking + +### 1.1 Viewing the Connected Model + +**Description**: Returns the current SQL dialect model (`Tree` or `Table`). + +**Syntax**: + +```SQL +showCurrentSqlDialectStatement + : SHOW CURRENT_SQL_DIALECT + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_SQL_DIALECT; +``` + +**Result:** + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 1.2 Viewing the Logged-in Username + +**Description**: Returns the currently logged-in username. + +**Syntax**: + +```SQL +showCurrentUserStatement + : SHOW CURRENT_USER + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_USER; +``` + +**Result**: + +```Plain ++-----------+ +|CurrentUser| ++-----------+ +| root| ++-----------+ +``` + +### 1.3 Viewing the Connected Database Name + +**Description**: Returns the name of the currently connected database. If no `USE` statement has been executed, it returns `null`. + +**Syntax**: + +```SQL +showCurrentDatabaseStatement + : SHOW CURRENT_DATABASE + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_DATABASE; +IoTDB> USE test; +IoTDB> SHOW CURRENT_DATABASE; +``` + +**Result**: + +```Plain ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ ++---------------+ +|CurrentDatabase| ++---------------+ +| test| ++---------------+ +``` + +### 1.4 Viewing the Cluster Version + +**Description**: Returns the current cluster version. + +**Syntax**: + +```SQL +showVersionStatement + : SHOW VERSION + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW VERSION; +``` + +**Result**: + +```Plain ++-------+---------+ +|Version|BuildInfo| ++-------+---------+ +|2.0.1.2| 1ca4008| ++-------+---------+ +``` + +### 1.5 Viewing Cluster Key Parameters + +**Description**: Returns key parameters of the current cluster. + +**Syntax**: + +```SQL +showVariablesStatement + : SHOW VARIABLES + ; +``` + +Key Parameters: + +1. **ClusterName**: The name of the current cluster. +2. **DataReplicationFactor**: Number of data replicas per DataRegion. +3. **SchemaReplicationFactor**: Number of schema replicas per SchemaRegion. +4. **DataRegionConsensusProtocolClass**: Consensus protocol class for DataRegions. +5. **SchemaRegionConsensusProtocolClass**: Consensus protocol class for SchemaRegions. +6. **ConfigNodeConsensusProtocolClass**: Consensus protocol class for ConfigNodes. +7. **TimePartitionOrigin**: The starting timestamp of database time partitions. +8. **TimePartitionInterval**: The interval of database time partitions (in milliseconds). +9. **ReadConsistencyLevel**: The consistency level for read operations. +10. **SchemaRegionPerDataNode**: Number of SchemaRegions per DataNode. +11. **DataRegionPerDataNode**: Number of DataRegions per DataNode. +12. **SeriesSlotNum**: Number of SeriesSlots per DataRegion. +13. **SeriesSlotExecutorClass**: Implementation class for SeriesSlots. +14. **DiskSpaceWarningThreshold**: Disk space warning threshold (in percentage). +15. **TimestampPrecision**: Timestamp precision. + +**Example**: + +```SQL +IoTDB> SHOW VARIABLES; +``` + +**Result**: + +```Plain ++----------------------------------+-----------------------------------------------------------------+ +| Variable| Value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 1.6 Viewing the Cluster ID + +**Description**: Returns the ID of the current cluster. + +**Syntax**: + +```SQL +showClusterIdStatement + : SHOW (CLUSTERID | CLUSTER_ID) + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CLUSTER_ID; +``` + +**Result**: + +```Plain ++------------------------------------+ +| ClusterId| ++------------------------------------+ +|40163007-9ec1-4455-aa36-8055d740fcda| ++------------------------------------+ +``` + +### 1.7 Viewing the Timestamp of the Connected DataNode + +**Description**: Returns the current timestamp of the DataNode process directly connected to the client. + +**Syntax**: + +```SQL +showCurrentTimestampStatement + : SHOW CURRENT_TIMESTAMP + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_TIMESTAMP; +``` + +**Result**: + +```Plain ++-----------------------------+ +| CurrentTimestamp| ++-----------------------------+ +|2025-02-17T11:11:52.987+08:00| ++-----------------------------+ +``` + +### 1.8 Viewing Executing Queries + +**Description**: Displays information about all currently executing queries. + +> For more details on how to use system tables, please refer to [System Tables](../Reference/System-Tables_timecho.md) + +**Syntax**: + +```SQL +showQueriesStatement + : SHOW (QUERIES | QUERY PROCESSLIST) + (WHERE where=booleanExpression)? + (ORDER BY sortItem (',' sortItem)*)? + limitOffsetClause + ; +``` + +**Parameters**: + +1. **WHERE Clause**: Filters the result set based on specified conditions. +2. **ORDER BY Clause**: Sorts the result set based on specified columns. +3. **limitOffsetClause**: Limits the number of rows returned. + 1. Format: `LIMIT , `. + +**Columns in QUERIES Table**: + +- **query_id**: Unique ID of the query. +- **start_time**: Timestamp when the query started. +- **datanode_id**: ID of the DataNode executing the query. +- **elapsed_time**: Time elapsed since the query started (in seconds). +- **statement**: The SQL statement being executed. +- **user**: The user who initiated the query. + +**Example**: + +```SQL +IoTDB> SHOW QUERIES WHERE elapsed_time > 30; +``` + +**Result**: + +```Plain ++-----------------------+-----------------------------+-----------+------------+------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +``` + + +### 1.9 Viewing Region Information + +**Description**: Displays regions' information of the current cluster. + +**Syntax**: + +```SQL +showRegionsStatement + : SHOW REGIONS + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW REGIONS +``` + +**Result**: + +```SQL ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | +| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| +| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +``` + + +## 2. Status Setting + +### 2.1 Setting the Connected Model + +**Description**: Sets the current SQL dialect model to `Tree` or `Table` which can be used in both tree and table models. + +**Syntax**: + +```SQL +SET SQL_DIALECT = (TABLE | TREE); +``` + +**Example**: + +```SQL +IoTDB> SET SQL_DIALECT=TABLE; +IoTDB> SHOW CURRENT_SQL_DIALECT; +``` + +**Result**: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 2.2 Updating Configuration Items + +**Description**: Updates configuration items. Changes take effect immediately without restarting if the items support hot modification. + +**Syntax**: + +```SQL +setConfigurationStatement + : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? + ; + +propertyAssignments + : property (',' property)* + ; + +property + : identifier EQ propertyValue + ; + +propertyValue + : DEFAULT + | expression + ; +``` + +**Parameters**: + +1. **propertyAssignments**: A list of properties to update. + 1. Format: `property (',' property)*`. + 2. Values: + - `DEFAULT`: Resets the configuration to its default value. + - `expression`: A specific value (must be a string). +2. **ON INTEGER_VALUE** **(Optional):** Specifies the node ID to update. + 1. If not specified or set to a negative value, updates all ConfigNodes and DataNodes. + +**Example**: + +```SQL +IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; +``` + +### 2.3 Loading Manually Modified Configuration Files + +**Description**: Loads manually modified configuration files and hot-loads the changes. Configuration items that support hot modification take effect immediately. + +**Syntax**: + +```SQL +loadConfigurationStatement + : LOAD CONFIGURATION localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode** **(Optional):** + 1. Specifies the scope of configuration loading. + 2. Default: `CLUSTER`. + 3. Values: + - `LOCAL`: Loads configuration only on the DataNode directly connected to the client. + - `CLUSTER`: Loads configuration on all DataNodes in the cluster. + +**Example**: + +```SQL +IoTDB> LOAD CONFIGURATION ON LOCAL; +``` + +### 2.4 Setting the System Status + +**Description**: Sets the system status to either `READONLY` or `RUNNING`. + +**Syntax**: + +```SQL +setSystemStatusStatement + : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **RUNNING |** **READONLY**: + 1. **RUNNING**: Sets the system to running mode, allowing both read and write operations. + 2. **READONLY**: Sets the system to read-only mode, allowing only read operations and prohibiting writes. +2. **localOrClusterMode** **(Optional):** + 1. **LOCAL**: Applies the status change only to the DataNode directly connected to the client. + 2. **CLUSTER**: Applies the status change to all DataNodes in the cluster. + 3. **Default**: `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> SET SYSTEM TO READONLY ON CLUSTER; +``` + +## 3. Data Management + +### 3.1 Flushing Data from Memory to Disk + +**Description**: Flushes data from the memory table to disk. + +**Syntax**: + +```SQL +flushStatement + : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? + ; + +booleanValue + : TRUE | FALSE + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **identifier** **(Optional):** + 1. Specifies the name of the database to flush. + 2. If not specified, all databases are flushed. + 3. **Multiple Databases**: Multiple database names can be specified, separated by commas (e.g., `FLUSH test_db1, test_db2`). +2. **booleanValue** **(****Optional****)**: + 1. Specifies the type of data to flush. + 2. **TRUE**: Flushes only the sequential memory table. + 3. **FALSE**: Flushes only the unsequential MemTable. + 4. **Default**: Flushes both sequential and unsequential memory tables. +3. **localOrClusterMode** **(****Optional****)**: + 1. **ON LOCAL**: Flushes only the memory tables on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Flushes memory tables on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> FLUSH test_db TRUE ON LOCAL; +``` + +### 3.2 Clearing Cache on DataNode + +**Description**: Clears a specific type of cache on DataNode. + +**Syntax**: + +```SQL +clearCacheStatement + : CLEAR clearCacheOptions? CACHE localOrClusterMode? + ; + +clearCacheOptions + : ATTRIBUTE + | QUERY + | ALL + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **clearCacheOptions(Optional)**: + 1. Specifies the type of cache to clear. + 2. **ATTRIBUTE**: Clears device attribute cache. + 3. **QUERY**: Clears query cache in the storage engine. + 4. **ALL**: Clears all caches, including device attribute cache, query cache, and schema cache in the tree model. + 5. **Default**: `QUERY`. +2. **localOrClusterMode(Optional)**: + 1. **ON LOCAL**: Clears cache only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Clears cache on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> CLEAR ALL CACHE ON LOCAL; +``` + +## 4. Data Repair + +### 4.1 Starting Background Scan and Repair of TsFiles + +**Description**: Starts a background task to scan and repair TsFiles, fixing issues such as timestamp disorder within data files. + +**Syntax**: + +```SQL +startRepairDataStatement + : START REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode(Optional)**: + 1. **ON LOCAL**: Executes the repair task only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Executes the repair task on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> START REPAIR DATA ON CLUSTER; +``` + +### 4.2 Pausing Background TsFile Repair Task + +**Description**: Pauses the background repair task. The paused task can be resumed by executing the `START REPAIR DATA` command again. + +**Syntax**: + +```SQL +stopRepairDataStatement + : STOP REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode** **(Optional):** + 1. **ON LOCAL**: Executes the pause command only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Executes the pause command on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> STOP REPAIR DATA ON CLUSTER; +``` + +## 5. Query Termination + +### 5.1 Terminating Queries + +**Description**: Terminates one or more running queries. + +**Syntax**: + +```SQL +killQueryStatement + : KILL (QUERY queryId=string | ALL QUERIES) + ; +``` + +**Parameters**: + +1. **QUERY** **queryId:** Specifies the ID of the query to terminate. + +- To obtain the `queryId`, use the `SHOW QUERIES` command. + +2. **ALL QUERIES:** Terminates all currently running queries. + +**Example**: + +Terminate a specific query: + +```SQL +IoTDB> KILL QUERY 20250108_101015_00000_1; +``` + +Terminate all queries: + +```SQL +IoTDB> KILL ALL QUERIES; +``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/User-Manual/Tree-to-Table_apache.md b/src/UserGuide/Master/Table/User-Manual/Tree-to-Table_apache.md new file mode 100644 index 000000000..b9b1d06b9 --- /dev/null +++ b/src/UserGuide/Master/Table/User-Manual/Tree-to-Table_apache.md @@ -0,0 +1,582 @@ + + +# Tree-to-Table Mapping + +## 1. Functional Overview + +IoTDB introduces a tree-to-table function, which enables the creation of table views from existing tree-model data. This allows querying via table views, achieving collaborative processing of both tree and table models for the same dataset: + +* During the data writing phase, the tree-model syntax is used, supporting flexible data ingestion and expansion. +* During the data analysis phase, the table-model syntax is adopted, allowing complex data analysis through standard SQL queries. + +![](/img/tree-to-table-en-1.png) + +> * This feature supports from version V2.0.5. +> * Table views are read-only, so data cannot be written through them. + + ## 2. Feature Description +### 2.1 Creating a Table View +#### 2.1.1 Syntax Definition + +```SQL +-- create (or replace) view on tree +CREATE + [OR REPLACE] + VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) + [comment] + [RESTRICT] + [WITH properties] + AS prefixPath + +viewColumnDefinition + : column_name [dataType] TAG [comment] # tagColumn + | column_name [dataType] TIME [comment] # timeColumn + | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn + ; + +comment + : COMMENT string + ; +``` + +> Note: Columns only support tags, fields, or time; attributes are not supported. + +#### 2.1.2 Syntax Explanation +1. **`prefixPath`** + +Corresponds to the path in the tree model. The last level of the path must be `**`, and no other levels can contain `*`or `**`. This path determines the subtree corresponding to the VIEW. + +2. **`view_name`** + +The name of the view, which follows the same rules as a table name (for specific constraints, refer to [Create Table](../Basic-Concept/Table-Management_apache.md#\_1-1-create-a-table)), e.g., `db.view`. + +3. **`viewColumnDefinition`** + +* `TAG`: Each TAG column corresponds, in order, to the path nodes at the levels following the `prefixPath`. +* `FIELD`: A FIELD column corresponds to a measurement (leaf node) in the tree model. + * If a FIELD column is specified, the column name uses the declared `column_name`. + * If `original_measurement`is declared, it maps directly to that measurement in the tree model. Otherwise, the lowercase `column_name`is used as the measurement name for mapping. + * Mapping multiple FIELD columns to the same measurement name in the tree model is not supported. + * If the `dataType`for a FIELD column is not specified, the system defaults to the data type of the mapped measurement in the tree model. + * If a device in the tree model does not contain certain declared FIELD columns, or if their data types are inconsistent with the declared FIELD columns, the value for that FIELD column will always be `NULL`when querying that device. + * If no FIELD columns are specified, the system automatically scans for all measurements under the `prefixPath`subtree (including all ordinary sequence measurements and measurements defined in any templates whose mounted paths overlap with the `prefixPath`) during creation. The column names will use the measurement names from the tree model. + * The tree model cannot have measurements with the same name (case-insensitive) but different data types. + +4. **`WITH properties`** + +Currently, only TTL is supported. It indicates that data older than TTL (in milliseconds) will not be displayed in query results, i.e., effectively `WHERE time > now() - TTL`. If a TTL is also set in the tree model, the query uses the smaller value of the two. + +> Note: The table view's TTL does not affect the actual TTL of the devices in the tree model. When data reaches the TTL set in the tree model, it will be physically deleted by the system. + +5. **`OR REPLACE`** + +A table and a view cannot have the same name. If a table with the same name already exists during creation, an error will be reported. If a view with the same name already exists, it will be replaced. + +6. **`RESTRICT`** + +This constrains the number of levels of the tree model devices that are matched (starting from the level below the `prefixPath`). If the `RESTRICT`keyword is present, only devices whose level count exactly equals the number of TAG columns are matched. Otherwise, devices whose level count is less than or equal to the number of TAG columns are matched. The default behavior is non-RESTRICT, meaning devices with a level count less than or equal to the number of TAG columns are matched. + +#### 2.1.3 Usage Example +1. Tree Model and Table View Schema + +![](/img/tree-to-table-en-2.png) + +2. Creating the Table View + +* Creation Statement: + +```SQL +CREATE OR REPLACE VIEW viewdb."wind_turbine" + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +with (ttl=604800000) +AS root.db.** +``` + +* Detailed Explanation + +This statement creates a view named `viewdb.wind_turbine`(an error will occur if `viewdb`does not exist). If the view already exists, it will be replaced. + +* It creates a table view for the time series mounted under the tree model path `root.db.**`. +* It has two `TAG` columns, `wind_turbine_group `and `wind_turbine_number`, so the table view will only include devices from the 3rd level of the original tree model. +* It has two `FIELD`columns, `voltage` and `current`. Here, these `FIELD` columns correspond to measurement names in the tree model that are also `voltage` and `current`, and only select time series of type `DOUBLE`. + +**Renaming measurement requirement:** + +If the measurement name in the tree model is `current_new`, but you want the corresponding `FIELD` column name in the table view to be `current`, the SQL should be changed as follows: + +```SQL +CREATE OR REPLACE VIEW viewdb."wind_turbine" + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD FROM current_new + ) +with (ttl=604800000) +AS root.db.** +``` + +### 2.2 Modifying a Table View +#### 2.2.1 Syntax Definition + +The ALTER VIEW function supports modifying the view name, adding columns, renaming columns, deleting columns, setting the view's TTL property, and adding comments via COMMENT. + +```SQL +-- Rename view +ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier + +-- Add a column to the view +ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition +viewColumnDefinition + : column_name [dataType] TAG # tagColumn + | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn + +-- Rename a column in the view +ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName + +-- Delete a column from the view +ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName + +-- Modify the view's TTL +ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments + +-- Add comments +COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView +COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn +``` + +#### 2.2.2 Syntax Explanation +1. The `SET PROPERTIES`operation currently only supports configuring the TTL property for the table view. +2. The `DROP COLUMN`function only supports deleting FIELD columns; TAG columns cannot be deleted. +3. Modifying the comment will overwrite the original comment. If set to `null`, the previous comment will be erased. +#### 2.2.3 Usage Examples + +```SQL +-- Rename view +ALTER VIEW IF EXISTS tableview1 RENAME TO tableview + +-- Add a column to the view +ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field + +-- Rename a column in the view +ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp + +-- Delete a column from the view +ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp + +-- Modify the view's TTL +ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 + +-- Add comments +COMMENT ON VIEW tableview IS 'Tree to Table' +COMMENT ON COLUMN tableview.status is Null +``` + +### 2.3 Deleting a Table View +#### 2.3.1 Syntax Definition + +```SQL +DROP VIEW [IF EXISTS] viewName +``` + +#### 2.3.2 Usage Example + +```SQL +DROP VIEW IF EXISTS tableview +``` + +### 2.4 Viewing Table Views +#### 2.4.1 **`Show Tables`** +1. Syntax Definition + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +2. Syntax Explanation + +The `SHOW TABLES (DETAILS)`statement displays the type information of tables or views through the `TABLE_TYPE`field in the result set: + +| Type | `TABLE_TYPE`Field Value | +| -------------------------------------------- | ----------------------------- | +| Ordinary Table(Table) | `BASE TABLE` | +| Tree-to-Table View (Tree View) | `VIEW FROM TREE` | +| System Table(Iinformation\_schema.Tables) | `SYSTEM VIEW` | + +3. Usage Examples + +```SQL +IoTDB> show tables details from database1 ++-----------+-----------+------+---------------+--------------+ +| TableName| TTL(ms)|Status| Comment| TableType| ++-----------+-----------+------+---------------+--------------+ +| tableview| INF| USING| Tree to Table |VIEW FROM TREE| +| table1|31536000000| USING| null| BASE TABLE| +| table2|31536000000| USING| null| BASE TABLE| ++-----------+-----------+------+---------------+--------------+ + +IoTDB> show tables details from information_schema ++--------------+-------+------+-------+-----------+ +| TableName|TTL(ms)|Status|Comment| TableType| ++--------------+-------+------+-------+-----------+ +| columns| INF| USING| null|SYSTEM VIEW| +| config_nodes| INF| USING| null|SYSTEM VIEW| +|configurations| INF| USING| null|SYSTEM VIEW| +| data_nodes| INF| USING| null|SYSTEM VIEW| +| databases| INF| USING| null|SYSTEM VIEW| +| functions| INF| USING| null|SYSTEM VIEW| +| keywords| INF| USING| null|SYSTEM VIEW| +| models| INF| USING| null|SYSTEM VIEW| +| nodes| INF| USING| null|SYSTEM VIEW| +| pipe_plugins| INF| USING| null|SYSTEM VIEW| +| pipes| INF| USING| null|SYSTEM VIEW| +| queries| INF| USING| null|SYSTEM VIEW| +| regions| INF| USING| null|SYSTEM VIEW| +| subscriptions| INF| USING| null|SYSTEM VIEW| +| tables| INF| USING| null|SYSTEM VIEW| +| topics| INF| USING| null|SYSTEM VIEW| +| views| INF| USING| null|SYSTEM VIEW| ++--------------+-------+------+-------+-----------+ +``` + +#### 2.4.2 **`Show Create Table/View`** +1. Syntax Definition + +```SQL +SHOW CREATE TABLE|VIEW viewname; +``` + +2. Syntax Explanation + +* The `SHOW CREATE TABLE`statement can be used to display the complete creation information for ordinary tables or views. +* The `SHOW CREATE VIEW`statement can only be used to display the complete creation information for views. +* Neither statement can be used to display system tables. + +3. Usage Examples + +```SQL +IoTDB> show create table tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +IoTDB> show create view tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +``` + +### 2.5 Query Differences Between Non-aligned and Aligned Devices + +Queries on tree-to-table views may yield different results compared to equivalent tree model `ALIGN BY DEVICE`queries when dealing with null values in aligned and non-aligned devices. + +* Aligned Devices + * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. + * Table View Query Behavior:Consistent with the table model, rows where all selected fields are null are retained. +* Non-aligned Devices + * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. + * Table View Query Behavior:Consistent with the tree model, rows where all selected fields are null are not retained. +* Explanation Example + * Aligned + + ```SQL + -- Write data in tree model (aligned) + CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) + + -- Create VIEW statement + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- Query + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + | null| + +-------+ + Total line number = 2 + ``` + + * Non-aligned + + ```SQL + -- Write data in tree model (non-aligned) + CREATE TIMESERIES root.db.battery.b1.voltage INT32 + CREATE TIMESERIES root.db.battery.b1.current FLOAT + INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) + + -- Create VIEW statement + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- Query + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + +-------+ + Total line number = 1 + + -- Can only ensure all rows are retrieved if the query specifies all FIELD columns, or only non-FIELD columns + IoTDB> select voltage,current from view1 + +-------+-------+ + |voltage|current| + +-------+-------+ + | 1| 1.0| + | null| 1.0| + +-------+-------+ + Total line number = 2 + + IoTDB> select battery_id from view1 + +-----------+ + |battery_id| + +-----------+ + | b1| + | b1| + +-----------+ + Total line number = 2 + + -- If the query involves only some FIELD columns, the final number of rows depends on the number of rows after aligning the specified FIELD columns by timestamp. + IoTDB> select time,voltage from view1 + +-----------------------------+-------+ + | time|voltage| + +-----------------------------+-------+ + |1970-01-01T08:00:00.001+08:00| 1| + +-----------------------------+-------+ + Total line number = 1 + ``` + +## 3. Scenario Examples +### 3.1 Managing Multiple Device Types in the Original Tree Model + +* The scenario involves managing different types of devices, each with its own hierarchical path and set of measurements. +* During Data Writing: Create branches under the database node according to device type. Each device type can have a different measurement structure. +* During Querying: Create a separate table for each device type. Each table will have different tags and sets of measurements. + +![](/img/tree-to-table-en-3.png) + +**SQL for Creating a Table View:** + +```SQL +-- Wind Turbine Table +CREATE VIEW viewdb.wind_turbine + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +AS root.db.wind_turbine.** + +-- Motor Table +CREATE VIEW viewdb.motor + ( motor_group String TAG, + motor_number String TAG, + power FLOAT FIELD, + electricity FLOAT FIELD, + temperature FLOAT FIELD + ) +AS root.db.motor.** +``` + +### 3.2 Original Tree Model Contains Only Measurements, No Devices + +This scenario occurs in systems like station monitoring where each measurement has a unique identifier but cannot be mapped to specific physical devices. + +> Wide Table Form + +![](/img/tree-to-table-en-4.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine + (DCS_PIT_02105A DOUBLE FIELD, + DCS_PIT_02105B DOUBLE FIELD, + DCS_PIT_02105C DOUBLE FIELD, + ... + DCS_XI_02716A DOUBLE FIELD + ) +AS root.db.** +``` + +### 3.3 Original Tree Model Where a Device Has Both Sub-devices and Measurements + +This scenario is common in energy storage systems where each hierarchical level requires monitoring of parameters like voltage and current. + +* Writing Phase: Model according to physical monitoring points at each hierarchical level +* Querying Phase: Create multiple tables based on device categories to manage information at each structural level + +![](/img/tree-to-table-en-5.png) + +**SQL for Creating a Table View:** + +```SQL +-- Battery Compartment +CREATE VIEW viewdb.battery_compartment + (station String TAG, + batter_compartment String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- Battery Stack +CREATE VIEW viewdb.battery_stack + (station String TAG, + batter_compartment String TAG, + battery_stack String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- Battery Cluster +CREATE VIEW viewdb.battery_cluster + (station String TAG, + batter_compartment String TAG, + battery_stackString TAG, + battery_cluster String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS 'root.db.**' + +-- Battery Ceil +CREATE VIEW viewdb.battery_ceil + (station String TAG, + batter_compartment String TAG, + battery_cluster String TAG, + battery_cluster String TAG, + battery_ceil String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** +``` + +### 3.4 Original Tree Model Where a Device Has Only One Measurement Under It + +> Narrow Table Form + +#### 3.4.1 All Measurements Have the Same Data Type + +![](/img/tree-to-table-en-6.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** +``` + +#### 3.4.2 Measurements Have Different Data Types +##### 3.4.2.1 Create a Narrow Table View for Each Data Type of Measurement + +**Advantage: ​**The number of table views is constant, only related to the data types in the system. + +**Disadvantage: ​**When querying the value of a specific measurement, its data type must be known in advance to determine which table view to query. + +![](/img/tree-to-table-en-7.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine_float + ( + sensor_id STRING TAG, + value FLOAT FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_double + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int32 + ( + sensor_id STRING TAG, + value INT32 FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int64 + ( + sensor_id STRING TAG, + value INT64 FIELD + ) +AS root.db.** + +... +``` + +##### 3.4.2.2 Create a Table for Each Measurement + +**Advantage: ​**When querying the value of a specific measurement, there's no need to first check its data type to determine which table to query, making the process simple and convenient. + +**Disadvantage: ​**When there are a large number of measurements, it will introduce too many table views, requiring the writing of a large number of view creation statements. + +![](/img/tree-to-table-en-8.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.DCS_PIT_02105A + ( + value FLOAT FIELD + ) +AS root.db.DCS_PIT_02105A.** + +CREATE VIEW viewdb.DCS_PIT_02105B + ( + value DOUBLE FIELD + ) +AS root.db.DCS_PIT_02105B.** + +CREATE VIEW viewdb.DCS_XI_02716A + ( + value INT64 FIELD + ) +AS root.db.DCS_XI_02716A.** + +...... +``` diff --git a/src/UserGuide/Master/Table/User-Manual/Tree-to-Table_timecho.md b/src/UserGuide/Master/Table/User-Manual/Tree-to-Table_timecho.md new file mode 100644 index 000000000..d855bd5e3 --- /dev/null +++ b/src/UserGuide/Master/Table/User-Manual/Tree-to-Table_timecho.md @@ -0,0 +1,582 @@ + + +# Tree-to-Table Mapping + +## 1. Functional Overview + +IoTDB introduces a tree-to-table function, which enables the creation of table views from existing tree-model data. This allows querying via table views, achieving collaborative processing of both tree and table models for the same dataset: + +* During the data writing phase, the tree-model syntax is used, supporting flexible data ingestion and expansion. +* During the data analysis phase, the table-model syntax is adopted, allowing complex data analysis through standard SQL queries. + +![](/img/tree-to-table-en-1.png) + +> * This feature supports from version V2.0.5. +> * Table views are read-only, so data cannot be written through them. + + ## 2. Feature Description +### 2.1 Creating a Table View +#### 2.1.1 Syntax Definition + +```SQL +-- create (or replace) view on tree +CREATE + [OR REPLACE] + VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) + [comment] + [RESTRICT] + [WITH properties] + AS prefixPath + +viewColumnDefinition + : column_name [dataType] TAG [comment] # tagColumn + | column_name [dataType] TIME [comment] # timeColumn + | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn + ; + +comment + : COMMENT string + ; +``` + +> Note: Columns only support tags, fields, or time; attributes are not supported. + +#### 2.1.2 Syntax Explanation +1. **`prefixPath`** + +Corresponds to the path in the tree model. The last level of the path must be `**`, and no other levels can contain `*`or `**`. This path determines the subtree corresponding to the VIEW. + +2. **`view_name`** + +The name of the view, which follows the same rules as a table name (for specific constraints, refer to [Create Table](../Basic-Concept/Table-Management_timecho.md#\_1-1-create-a-table)), e.g., `db.view`. + +3. **`viewColumnDefinition`** + +* `TAG`: Each TAG column corresponds, in order, to the path nodes at the levels following the `prefixPath`. +* `FIELD`: A FIELD column corresponds to a measurement (leaf node) in the tree model. + * If a FIELD column is specified, the column name uses the declared `column_name`. + * If `original_measurement`is declared, it maps directly to that measurement in the tree model. Otherwise, the lowercase `column_name`is used as the measurement name for mapping. + * Mapping multiple FIELD columns to the same measurement name in the tree model is not supported. + * If the `dataType`for a FIELD column is not specified, the system defaults to the data type of the mapped measurement in the tree model. + * If a device in the tree model does not contain certain declared FIELD columns, or if their data types are inconsistent with the declared FIELD columns, the value for that FIELD column will always be `NULL`when querying that device. + * If no FIELD columns are specified, the system automatically scans for all measurements under the `prefixPath`subtree (including all ordinary sequence measurements and measurements defined in any templates whose mounted paths overlap with the `prefixPath`) during creation. The column names will use the measurement names from the tree model. + * The tree model cannot have measurements with the same name (case-insensitive) but different data types. + +4. **`WITH properties`** + +Currently, only TTL is supported. It indicates that data older than TTL (in milliseconds) will not be displayed in query results, i.e., effectively `WHERE time > now() - TTL`. If a TTL is also set in the tree model, the query uses the smaller value of the two. + +> Note: The table view's TTL does not affect the actual TTL of the devices in the tree model. When data reaches the TTL set in the tree model, it will be physically deleted by the system. + +5. **`OR REPLACE`** + +A table and a view cannot have the same name. If a table with the same name already exists during creation, an error will be reported. If a view with the same name already exists, it will be replaced. + +6. **`RESTRICT`** + +This constrains the number of levels of the tree model devices that are matched (starting from the level below the `prefixPath`). If the `RESTRICT`keyword is present, only devices whose level count exactly equals the number of TAG columns are matched. Otherwise, devices whose level count is less than or equal to the number of TAG columns are matched. The default behavior is non-RESTRICT, meaning devices with a level count less than or equal to the number of TAG columns are matched. + +#### 2.1.3 Usage Example +1. Tree Model and Table View Schema + +![](/img/tree-to-table-en-2.png) + +2. Creating the Table View + +* Creation Statement: + +```SQL +CREATE OR REPLACE VIEW viewdb."wind_turbine" + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +with (ttl=604800000) +AS root.db.** +``` + +* Detailed Explanation + +This statement creates a view named `viewdb.wind_turbine`(an error will occur if `viewdb`does not exist). If the view already exists, it will be replaced. + +* It creates a table view for the time series mounted under the tree model path `root.db.**`. +* It has two `TAG` columns, `wind_turbine_group `and `wind_turbine_number`, so the table view will only include devices from the 3rd level of the original tree model. +* It has two `FIELD`columns, `voltage` and `current`. Here, these `FIELD` columns correspond to measurement names in the tree model that are also `voltage` and `current`, and only select time series of type `DOUBLE`. + +**Renaming measurement requirement:** + +If the measurement name in the tree model is `current_new`, but you want the corresponding `FIELD` column name in the table view to be `current`, the SQL should be changed as follows: + +```SQL +CREATE OR REPLACE VIEW viewdb."wind_turbine" + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD FROM current_new + ) +with (ttl=604800000) +AS root.db.** +``` + +### 2.2 Modifying a Table View +#### 2.2.1 Syntax Definition + +The ALTER VIEW function supports modifying the view name, adding columns, renaming columns, deleting columns, setting the view's TTL property, and adding comments via COMMENT. + +```SQL +-- Rename view +ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier + +-- Add a column to the view +ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition +viewColumnDefinition + : column_name [dataType] TAG # tagColumn + | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn + +-- Rename a column in the view +ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName + +-- Delete a column from the view +ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName + +-- Modify the view's TTL +ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments + +-- Add comments +COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView +COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn +``` + +#### 2.2.2 Syntax Explanation +1. The `SET PROPERTIES`operation currently only supports configuring the TTL property for the table view. +2. The `DROP COLUMN`function only supports deleting FIELD columns; TAG columns cannot be deleted. +3. Modifying the comment will overwrite the original comment. If set to `null`, the previous comment will be erased. +#### 2.2.3 Usage Examples + +```SQL +-- Rename view +ALTER VIEW IF EXISTS tableview1 RENAME TO tableview + +-- Add a column to the view +ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field + +-- Rename a column in the view +ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp + +-- Delete a column from the view +ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp + +-- Modify the view's TTL +ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 + +-- Add comments +COMMENT ON VIEW tableview IS 'Tree to Table' +COMMENT ON COLUMN tableview.status is Null +``` + +### 2.3 Deleting a Table View +#### 2.3.1 Syntax Definition + +```SQL +DROP VIEW [IF EXISTS] viewName +``` + +#### 2.3.2 Usage Example + +```SQL +DROP VIEW IF EXISTS tableview +``` + +### 2.4 Viewing Table Views +#### 2.4.1 **`Show Tables`** +1. Syntax Definition + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +2. Syntax Explanation + +The `SHOW TABLES (DETAILS)`statement displays the type information of tables or views through the `TABLE_TYPE`field in the result set: + +| Type | `TABLE_TYPE`Field Value | +| -------------------------------------------- | ----------------------------- | +| Ordinary Table(Table) | `BASE TABLE` | +| Tree-to-Table View (Tree View) | `VIEW FROM TREE` | +| System Table(Iinformation\_schema.Tables) | `SYSTEM VIEW` | + +3. Usage Examples + +```SQL +IoTDB> show tables details from database1 ++-----------+-----------+------+---------------+--------------+ +| TableName| TTL(ms)|Status| Comment| TableType| ++-----------+-----------+------+---------------+--------------+ +| tableview| INF| USING| Tree to Table |VIEW FROM TREE| +| table1|31536000000| USING| null| BASE TABLE| +| table2|31536000000| USING| null| BASE TABLE| ++-----------+-----------+------+---------------+--------------+ + +IoTDB> show tables details from information_schema ++--------------+-------+------+-------+-----------+ +| TableName|TTL(ms)|Status|Comment| TableType| ++--------------+-------+------+-------+-----------+ +| columns| INF| USING| null|SYSTEM VIEW| +| config_nodes| INF| USING| null|SYSTEM VIEW| +|configurations| INF| USING| null|SYSTEM VIEW| +| data_nodes| INF| USING| null|SYSTEM VIEW| +| databases| INF| USING| null|SYSTEM VIEW| +| functions| INF| USING| null|SYSTEM VIEW| +| keywords| INF| USING| null|SYSTEM VIEW| +| models| INF| USING| null|SYSTEM VIEW| +| nodes| INF| USING| null|SYSTEM VIEW| +| pipe_plugins| INF| USING| null|SYSTEM VIEW| +| pipes| INF| USING| null|SYSTEM VIEW| +| queries| INF| USING| null|SYSTEM VIEW| +| regions| INF| USING| null|SYSTEM VIEW| +| subscriptions| INF| USING| null|SYSTEM VIEW| +| tables| INF| USING| null|SYSTEM VIEW| +| topics| INF| USING| null|SYSTEM VIEW| +| views| INF| USING| null|SYSTEM VIEW| ++--------------+-------+------+-------+-----------+ +``` + +#### 2.4.2 **`Show Create Table/View`** +1. Syntax Definition + +```SQL +SHOW CREATE TABLE|VIEW viewname; +``` + +2. Syntax Explanation + +* The `SHOW CREATE TABLE`statement can be used to display the complete creation information for ordinary tables or views. +* The `SHOW CREATE VIEW`statement can only be used to display the complete creation information for views. +* Neither statement can be used to display system tables. + +3. Usage Examples + +```SQL +IoTDB> show create table tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +IoTDB> show create view tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +``` + +### 2.5 Query Differences Between Non-aligned and Aligned Devices + +Queries on tree-to-table views may yield different results compared to equivalent tree model `ALIGN BY DEVICE`queries when dealing with null values in aligned and non-aligned devices. + +* Aligned Devices + * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. + * Table View Query Behavior:Consistent with the table model, rows where all selected fields are null are retained. +* Non-aligned Devices + * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. + * Table View Query Behavior:Consistent with the tree model, rows where all selected fields are null are not retained. +* Explanation Example + * Aligned + + ```SQL + -- Write data in tree model (aligned) + CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) + + -- Create VIEW statement + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- Query + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + | null| + +-------+ + Total line number = 2 + ``` + + * Non-aligned + + ```SQL + -- Write data in tree model (non-aligned) + CREATE TIMESERIES root.db.battery.b1.voltage INT32 + CREATE TIMESERIES root.db.battery.b1.current FLOAT + INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) + + -- Create VIEW statement + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- Query + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + +-------+ + Total line number = 1 + + -- Can only ensure all rows are retrieved if the query specifies all FIELD columns, or only non-FIELD columns + IoTDB> select voltage,current from view1 + +-------+-------+ + |voltage|current| + +-------+-------+ + | 1| 1.0| + | null| 1.0| + +-------+-------+ + Total line number = 2 + + IoTDB> select battery_id from view1 + +-----------+ + |battery_id| + +-----------+ + | b1| + | b1| + +-----------+ + Total line number = 2 + + -- If the query involves only some FIELD columns, the final number of rows depends on the number of rows after aligning the specified FIELD columns by timestamp. + IoTDB> select time,voltage from view1 + +-----------------------------+-------+ + | time|voltage| + +-----------------------------+-------+ + |1970-01-01T08:00:00.001+08:00| 1| + +-----------------------------+-------+ + Total line number = 1 + ``` + +## 3. Scenario Examples +### 3.1 Managing Multiple Device Types in the Original Tree Model + +* The scenario involves managing different types of devices, each with its own hierarchical path and set of measurements. +* During Data Writing: Create branches under the database node according to device type. Each device type can have a different measurement structure. +* During Querying: Create a separate table for each device type. Each table will have different tags and sets of measurements. + +![](/img/tree-to-table-en-3.png) + +**SQL for Creating a Table View:** + +```SQL +-- Wind Turbine Table +CREATE VIEW viewdb.wind_turbine + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +AS root.db.wind_turbine.** + +-- Motor Table +CREATE VIEW viewdb.motor + ( motor_group String TAG, + motor_number String TAG, + power FLOAT FIELD, + electricity FLOAT FIELD, + temperature FLOAT FIELD + ) +AS root.db.motor.** +``` + +### 3.2 Original Tree Model Contains Only Measurements, No Devices + +This scenario occurs in systems like station monitoring where each measurement has a unique identifier but cannot be mapped to specific physical devices. + +> Wide Table Form + +![](/img/tree-to-table-en-4.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine + (DCS_PIT_02105A DOUBLE FIELD, + DCS_PIT_02105B DOUBLE FIELD, + DCS_PIT_02105C DOUBLE FIELD, + ... + DCS_XI_02716A DOUBLE FIELD + ) +AS root.db.** +``` + +### 3.3 Original Tree Model Where a Device Has Both Sub-devices and Measurements + +This scenario is common in energy storage systems where each hierarchical level requires monitoring of parameters like voltage and current. + +* Writing Phase: Model according to physical monitoring points at each hierarchical level +* Querying Phase: Create multiple tables based on device categories to manage information at each structural level + +![](/img/tree-to-table-en-5.png) + +**SQL for Creating a Table View:** + +```SQL +-- Battery Compartment +CREATE VIEW viewdb.battery_compartment + (station String TAG, + batter_compartment String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- Battery Stack +CREATE VIEW viewdb.battery_stack + (station String TAG, + batter_compartment String TAG, + battery_stack String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- Battery Cluster +CREATE VIEW viewdb.battery_cluster + (station String TAG, + batter_compartment String TAG, + battery_stackString TAG, + battery_cluster String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS 'root.db.**' + +-- Battery Ceil +CREATE VIEW viewdb.battery_ceil + (station String TAG, + batter_compartment String TAG, + battery_cluster String TAG, + battery_cluster String TAG, + battery_ceil String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** +``` + +### 3.4 Original Tree Model Where a Device Has Only One Measurement Under It + +> Narrow Table Form + +#### 3.4.1 All Measurements Have the Same Data Type + +![](/img/tree-to-table-en-6.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** +``` + +#### 3.4.2 Measurements Have Different Data Types +##### 3.4.2.1 Create a Narrow Table View for Each Data Type of Measurement + +**Advantage: ​**The number of table views is constant, only related to the data types in the system. + +**Disadvantage: ​**When querying the value of a specific measurement, its data type must be known in advance to determine which table view to query. + +![](/img/tree-to-table-en-7.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine_float + ( + sensor_id STRING TAG, + value FLOAT FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_double + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int32 + ( + sensor_id STRING TAG, + value INT32 FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int64 + ( + sensor_id STRING TAG, + value INT64 FIELD + ) +AS root.db.** + +... +``` + +##### 3.4.2.2 Create a Table for Each Measurement + +**Advantage: ​**When querying the value of a specific measurement, there's no need to first check its data type to determine which table to query, making the process simple and convenient. + +**Disadvantage: ​**When there are a large number of measurements, it will introduce too many table views, requiring the writing of a large number of view creation statements. + +![](/img/tree-to-table-en-8.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.DCS_PIT_02105A + ( + value FLOAT FIELD + ) +AS root.db.DCS_PIT_02105A.** + +CREATE VIEW viewdb.DCS_PIT_02105B + ( + value DOUBLE FIELD + ) +AS root.db.DCS_PIT_02105B.** + +CREATE VIEW viewdb.DCS_XI_02716A + ( + value INT64 FIELD + ) +AS root.db.DCS_XI_02716A.** + +...... +``` diff --git a/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md new file mode 100644 index 000000000..a59ce22ae --- /dev/null +++ b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md @@ -0,0 +1,189 @@ + + +# Database Management + +## 1. Database Management + +### 1.1 Create a Database + +This command is used to create a database. + +**Syntax:** + +```SQL + CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +**Note: ** + +1. ``: The name of the database, with the following characteristics: + - Case-insensitive. After creation, it will be displayed uniformly in lowercase. + - Can include commas (`,`), underscores (`_`), numbers, letters, and Chinese characters. + - Maximum length is 64 characters. + - Names with special characters or Chinese characters must be enclosed in double quotes (`""`). + +2. `WITH properties`: Property names are case-insensitive. For more details, refer to the case sensitivity rules [case-sensitivity](../SQL-Manual/Identifier.md#2-case-sensitivity)。Configurable properties include: + +| Property | Description | Default Value | +| ----------------------- | ------------------------------------------------------------ | -------------------- | +| TTL | Automatic data expiration time, in milliseconds | `INF` | +| TIME_PARTITION_INTERVAL | Time partition interval for the database, in milliseconds | `604800000` (7 days) | +| SCHEMA_REGION_GROUP_NUM | Number of metadata replica groups; generally does not require modification | `1` | +| DATA_REGION_GROUP_NUM | Number of data replica groups; generally does not require modification | `2` | + +**Examples:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +// Sets TTL to 1 year. +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 Use a Database + +Specify the current database as the namespace for table operations. + +**Syntax:** + +```SQL +USE +``` + +**Example:** + +```SQL +USE database1 +``` + +### 1.3 View the Current Database + +Displays the name of the currently connected database. If no USE statement has been executed, the default is `null`. + +**Syntax:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**Example:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 View All Databases + +Displays all databases and their properties. + +**Syntax:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +**Columns Explained:** + + +| Column Name | Description | +| ----------------------- | ------------------------------------------------------------ | +| database | Name of the database. | +| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management.md#14-update-tables) . | +| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | +| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | +| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | +| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | + +**Examples:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 Update a Database + +Used to modify some attributes in the database. + +**Syntax:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**Note:** + +1. The `ALTER DATABASE` operation currently only supports modifications to the database's `SCHEMA_REGION_GROUP_NUM`, `DATA_REGION_GROUP_NUM`, and `TTL` attributes. + +**Example:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 Delete a Database + +Deletes the specified database and all associated tables and data. + +**Syntax:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**Note:** + +1. A database currently in use can still be dropped. +2. Deleting a database removes all its tables and stored data. + +**Example:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` diff --git a/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md new file mode 100644 index 000000000..a59ce22ae --- /dev/null +++ b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md @@ -0,0 +1,189 @@ + + +# Database Management + +## 1. Database Management + +### 1.1 Create a Database + +This command is used to create a database. + +**Syntax:** + +```SQL + CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +**Note: ** + +1. ``: The name of the database, with the following characteristics: + - Case-insensitive. After creation, it will be displayed uniformly in lowercase. + - Can include commas (`,`), underscores (`_`), numbers, letters, and Chinese characters. + - Maximum length is 64 characters. + - Names with special characters or Chinese characters must be enclosed in double quotes (`""`). + +2. `WITH properties`: Property names are case-insensitive. For more details, refer to the case sensitivity rules [case-sensitivity](../SQL-Manual/Identifier.md#2-case-sensitivity)。Configurable properties include: + +| Property | Description | Default Value | +| ----------------------- | ------------------------------------------------------------ | -------------------- | +| TTL | Automatic data expiration time, in milliseconds | `INF` | +| TIME_PARTITION_INTERVAL | Time partition interval for the database, in milliseconds | `604800000` (7 days) | +| SCHEMA_REGION_GROUP_NUM | Number of metadata replica groups; generally does not require modification | `1` | +| DATA_REGION_GROUP_NUM | Number of data replica groups; generally does not require modification | `2` | + +**Examples:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +// Sets TTL to 1 year. +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 Use a Database + +Specify the current database as the namespace for table operations. + +**Syntax:** + +```SQL +USE +``` + +**Example:** + +```SQL +USE database1 +``` + +### 1.3 View the Current Database + +Displays the name of the currently connected database. If no USE statement has been executed, the default is `null`. + +**Syntax:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**Example:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 View All Databases + +Displays all databases and their properties. + +**Syntax:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +**Columns Explained:** + + +| Column Name | Description | +| ----------------------- | ------------------------------------------------------------ | +| database | Name of the database. | +| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management.md#14-update-tables) . | +| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | +| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | +| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | +| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | + +**Examples:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 Update a Database + +Used to modify some attributes in the database. + +**Syntax:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**Note:** + +1. The `ALTER DATABASE` operation currently only supports modifications to the database's `SCHEMA_REGION_GROUP_NUM`, `DATA_REGION_GROUP_NUM`, and `TTL` attributes. + +**Example:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 Delete a Database + +Deletes the specified database and all associated tables and data. + +**Syntax:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**Note:** + +1. A database currently in use can still be dropped. +2. Deleting a database removes all its tables and stored data. + +**Example:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` diff --git a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md new file mode 100644 index 000000000..7cc533f63 --- /dev/null +++ b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md @@ -0,0 +1,145 @@ + + +# TTL Delete Data + +## 1. Overview + +Time-to-Live (TTL) is a mechanism for defining the lifespan of data in a database. In IoTDB, TTL allows setting table-level expiration policies, enabling the system to automatically delete outdated data periodically. This helps manage disk space efficiently, maintain high query performance, and reduce memory usage. + +TTL values are specified in milliseconds, and once data exceeds its defined lifespan, it becomes unavailable for queries and cannot be written to. However, the physical deletion of expired data occurs later during the compaction process. Note that changes to TTL settings can briefly impact the accessibility of data. + +**Notes:** + +1. TTL defines the expiration time of data in milliseconds, independent of the time precision configuration file. +2. Modifying TTL settings can cause temporary variations in data accessibility. +3. The system eventually removes expired data, though this process may involve some delay.。 +4. The TTL expiration check is based on the data point timestamp, not the write time. + +## 2. Set TTL + +In the table model, IoTDB’s TTL operates at the granularity of individual tables. You can set TTL directly on a table or at the database level. When TTL is configured at the database level, it serves as the default for new tables created within the database. However, each table can still have its own independent TTL settings. + +**Note:** Modifying the database-level TTL does not retroactively affect the TTL settings of existing tables. + +### 2.1 Set TTL for Tables + +If TTL is specified when creating a table using SQL, the table’s TTL takes precedence. Refer to [Table-Management](../Basic-Concept/Table-Management.md)for details. + +Example 1: Setting TTL during table creation: + +```SQL +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600) +``` + +Example 2: Changing TTL for an existing table: + +```SQL +ALTER TABLE tableB SET PROPERTIES TTL=3600; +``` + +**Example 3:** If TTL is not specified or set to the default value, it will inherit the database's TTL. By default, the database TTL is `'INF'` (infinite): + +```SQL +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT) +CREATE TABLE test3 ("site" string id, "temperature" int32) +ALTER TABLE tableB set properties TTL=DEFAULT +``` + +### 2.2 Set TTL for Databases + +Tables without explicit TTL settings inherit the TTL of their database. Refer to [Database-Management](../Basic-Concept/Database-Management.md)for details. + +Example 4: A database with TTL=3600000 creates tables inheriting this TTL: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) +``` + +Example 5: A database without a TTL setting creates tables without TTL: + +```SQL +CREATE DATABASE db +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) +``` + +Example 6: Setting a table with no TTL explicitly (TTL=INF) in a database with a configured TTL: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') +``` + +## 3. Remove TTL + +To cancel a TTL setting, modify the table's TTL to 'INF'. Note that IoTDB does not currently support modifying the TTL of a database. + +```SQL +ALTER TABLE tableB set properties TTL='INF' +``` + +## 4. View TTL Information + +Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for databases and tables. Refer to [Database-Management](../Basic-Concept/Database-Management.md)、 [Table-Management](../Basic-Concept/Table-Management.md)for details. + +> Note: TTL settings in tree-model will also be shown. + +Example Output: + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 1| 3| 100000| +| test2| 300| 1| 1| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +|test_prop| 300| 1| 3| 100000|TABLE| +| test2| 300| 1| 1| 604800000| TREE| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +IoTDB> show tables ++---------+-------+ +|TableName|TTL(ms)| ++---------+-------+ +| grass| 1000| +| bamboo| 300| +| flower| INF| ++---------+-------+ + +IoTDB> show tables details ++---------+-------+----------+ +|TableName|TTL(ms)| Status| ++---------+-------+----------+ +| bean| 300|PRE_CREATE| +| grass| 1000| USING| +| bamboo| 300| USING| +| flower| INF| USING| ++---------+-------+----------+ +``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md new file mode 100644 index 000000000..7cc533f63 --- /dev/null +++ b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md @@ -0,0 +1,145 @@ + + +# TTL Delete Data + +## 1. Overview + +Time-to-Live (TTL) is a mechanism for defining the lifespan of data in a database. In IoTDB, TTL allows setting table-level expiration policies, enabling the system to automatically delete outdated data periodically. This helps manage disk space efficiently, maintain high query performance, and reduce memory usage. + +TTL values are specified in milliseconds, and once data exceeds its defined lifespan, it becomes unavailable for queries and cannot be written to. However, the physical deletion of expired data occurs later during the compaction process. Note that changes to TTL settings can briefly impact the accessibility of data. + +**Notes:** + +1. TTL defines the expiration time of data in milliseconds, independent of the time precision configuration file. +2. Modifying TTL settings can cause temporary variations in data accessibility. +3. The system eventually removes expired data, though this process may involve some delay.。 +4. The TTL expiration check is based on the data point timestamp, not the write time. + +## 2. Set TTL + +In the table model, IoTDB’s TTL operates at the granularity of individual tables. You can set TTL directly on a table or at the database level. When TTL is configured at the database level, it serves as the default for new tables created within the database. However, each table can still have its own independent TTL settings. + +**Note:** Modifying the database-level TTL does not retroactively affect the TTL settings of existing tables. + +### 2.1 Set TTL for Tables + +If TTL is specified when creating a table using SQL, the table’s TTL takes precedence. Refer to [Table-Management](../Basic-Concept/Table-Management.md)for details. + +Example 1: Setting TTL during table creation: + +```SQL +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600) +``` + +Example 2: Changing TTL for an existing table: + +```SQL +ALTER TABLE tableB SET PROPERTIES TTL=3600; +``` + +**Example 3:** If TTL is not specified or set to the default value, it will inherit the database's TTL. By default, the database TTL is `'INF'` (infinite): + +```SQL +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT) +CREATE TABLE test3 ("site" string id, "temperature" int32) +ALTER TABLE tableB set properties TTL=DEFAULT +``` + +### 2.2 Set TTL for Databases + +Tables without explicit TTL settings inherit the TTL of their database. Refer to [Database-Management](../Basic-Concept/Database-Management.md)for details. + +Example 4: A database with TTL=3600000 creates tables inheriting this TTL: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) +``` + +Example 5: A database without a TTL setting creates tables without TTL: + +```SQL +CREATE DATABASE db +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) +``` + +Example 6: Setting a table with no TTL explicitly (TTL=INF) in a database with a configured TTL: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') +``` + +## 3. Remove TTL + +To cancel a TTL setting, modify the table's TTL to 'INF'. Note that IoTDB does not currently support modifying the TTL of a database. + +```SQL +ALTER TABLE tableB set properties TTL='INF' +``` + +## 4. View TTL Information + +Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for databases and tables. Refer to [Database-Management](../Basic-Concept/Database-Management.md)、 [Table-Management](../Basic-Concept/Table-Management.md)for details. + +> Note: TTL settings in tree-model will also be shown. + +Example Output: + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 1| 3| 100000| +| test2| 300| 1| 1| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +|test_prop| 300| 1| 3| 100000|TABLE| +| test2| 300| 1| 1| 604800000| TREE| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +IoTDB> show tables ++---------+-------+ +|TableName|TTL(ms)| ++---------+-------+ +| grass| 1000| +| bamboo| 300| +| flower| INF| ++---------+-------+ + +IoTDB> show tables details ++---------+-------+----------+ +|TableName|TTL(ms)| Status| ++---------+-------+----------+ +| bean| 300|PRE_CREATE| +| grass| 1000| USING| +| bamboo| 300| USING| +| flower| INF| USING| ++---------+-------+----------+ +``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md b/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md index d97e7e580..c78cf2091 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md @@ -21,6 +21,10 @@ # Table Management +Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: +* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. +* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. + ## 1. Table Management ### 1.1 Create a Table diff --git a/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md new file mode 100644 index 000000000..c78cf2091 --- /dev/null +++ b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md @@ -0,0 +1,309 @@ + + +# Table Management + +Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: +* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. +* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. + +## 1. Table Management + +### 1.1 Create a Table + +#### 1.1.1 Manually create a table with CREATE + +Manually create a table within the current or specified database.The format is "database name. table name". + +**Syntax:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +**Note:** + +1. If the time column (`TIME`) is not specified, IoTDB automatically adds one. Other columns can be added using the `enable_auto_create_schema` configuration or session interface commands. +2. Column categories default to `FIELD` if not specified. `TAG` and `ATTRIBUTE` columns must be of type `STRING`. +3. Table `TTL` defaults to the database `TTL`. You can omit this property or set it to `default` if the default value is used. +4. ``: + 1. Case-insensitive. After creation, it will be displayed uniformly in lowercase. + 2. Can include special characters such as `~!`"`%`, etc. + 3. Names with special or Chinese characters must be enclosed in double quotes (`""`). + 4. Outer double quotes are not retained in the final table name. For example: `"a""b"` becomes `a"b`. + 5. Note: In SQL, table or column names with special characters or Chinese characters must be wrapped in double quotes. However, in the native API, do not add extra quotes—otherwise, the quotation marks will become part of the name itself. +5. **`columnDefinition`**: Column names share the same characteristics as table names and can include special characters such as `.`. +6. COMMENT adds comments to the table. + +**Examples:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "Site" STRING TAG, + "Temperature" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +#### 1.1.2 Automatically Create Tables via SESSION + +Tables can be created automatically when inserting data via session. + +**Examples:** + +```Java +try (ITableSession session = + new TableSessionBuilder() + .nodeUrls(Collections.singletonList("127.0.0.1:6667")) + .username("root") + .password("root") + .build()) { + + session.executeNonQueryStatement("CREATE DATABASE db1"); + session.executeNonQueryStatement("use db1"); + + // Insert data without manually creating the table + List columnNameList = + Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); + List dataTypeList = + Arrays.asList( + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.FLOAT, + TSDataType.DOUBLE); + List columnTypeList = + new ArrayList<>( + Arrays.asList( + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.ATTRIBUTE, + ColumnCategory.FIELD, + ColumnCategory.FIELD)); + Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); + for (long timestamp = 0; timestamp < 100; timestamp++) { + int rowIndex = tablet.getRowSize(); + tablet.addTimestamp(rowIndex, timestamp); + tablet.addValue("region_id", rowIndex, "1"); + tablet.addValue("plant_id", rowIndex, "5"); + tablet.addValue("device_id", rowIndex, "3"); + tablet.addValue("model", rowIndex, "A"); + tablet.addValue("temperature", rowIndex, 37.6F); + tablet.addValue("humidity", rowIndex, 111.1); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + session.insert(tablet); + tablet.reset(); + } + } + if (tablet.getRowSize() != 0) { + session.insert(tablet); + tablet.reset(); + } +} +``` + +After the code execution is complete, you can use the following statement to verify that the table has been successfully created, including details about the time column, tag columns, attribute columns, and field columns. + +```SQL +IoTDB> desc table1 ++-----------+---------+-----------+-------+ +| ColumnName| DataType| Category|Comment| ++-----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| region_id| STRING| TAG| null| +| plant_id| STRING| TAG| null| +| device_id| STRING| TAG| null| +| model| STRING| ATTRIBUTE| null| +|temperature| FLOAT| FIELD| null| +| humidity| DOUBLE| FIELD| null| ++-----------+---------+-----------+-------+ +``` + +### 1.2 View Tables + +Used to view all tables and their properties in the current or a specified database. + +**Syntax:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**Note:** + +1. If the `FROM` or `IN` clause is specified, the command lists all tables in the specified database. +2. If neither `FROM` nor `IN` is specified, the command lists all tables in the currently selected database. If no database is selected (`USE` statement not executed), an error is returned. +3. When the `DETAILS` option is used, the command shows the current state of each table: + 1. `USING`: The table is available and operational. + 2. `PRE_CREATE`: The table is in the process of being created or the creation has failed; the table is not available. + 3. `PRE_DELETE`: The table is in the process of being deleted or the deletion has failed; the table will remain permanently unavailable. + +**Examples:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 1.3 View Table Columns + +Used to view column names, data types, categories, and states of a table. + +**Syntax:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**Note:** If the `DETAILS` option is specified, detailed state information of the columns is displayed: + +- `USING`: The column is in normal use. +- `PRE_DELETE`: The column is being deleted or the deletion has failed; it is permanently unavailable. + + + +**Examples:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 1.4 Update Tables + +Used to update a table, including adding or deleting columns and configuring table properties. + +**Syntax:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**Note::** + +1. The `SET PROPERTIES` operation currently only supports configuring the `TTL` property of a table +2. The delete column function only supports deleting the ATTRIBUTE and FILD columns, and the TAG column does not support deletion. +3. The modified comment will overwrite the original comment. If null is specified, the previous comment will be erased. + +**Example:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 1.5 Delete Tables + +Used to delete a table. + +**Syntax:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md new file mode 100644 index 000000000..c78cf2091 --- /dev/null +++ b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md @@ -0,0 +1,309 @@ + + +# Table Management + +Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: +* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. +* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. + +## 1. Table Management + +### 1.1 Create a Table + +#### 1.1.1 Manually create a table with CREATE + +Manually create a table within the current or specified database.The format is "database name. table name". + +**Syntax:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +**Note:** + +1. If the time column (`TIME`) is not specified, IoTDB automatically adds one. Other columns can be added using the `enable_auto_create_schema` configuration or session interface commands. +2. Column categories default to `FIELD` if not specified. `TAG` and `ATTRIBUTE` columns must be of type `STRING`. +3. Table `TTL` defaults to the database `TTL`. You can omit this property or set it to `default` if the default value is used. +4. ``: + 1. Case-insensitive. After creation, it will be displayed uniformly in lowercase. + 2. Can include special characters such as `~!`"`%`, etc. + 3. Names with special or Chinese characters must be enclosed in double quotes (`""`). + 4. Outer double quotes are not retained in the final table name. For example: `"a""b"` becomes `a"b`. + 5. Note: In SQL, table or column names with special characters or Chinese characters must be wrapped in double quotes. However, in the native API, do not add extra quotes—otherwise, the quotation marks will become part of the name itself. +5. **`columnDefinition`**: Column names share the same characteristics as table names and can include special characters such as `.`. +6. COMMENT adds comments to the table. + +**Examples:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "Site" STRING TAG, + "Temperature" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +#### 1.1.2 Automatically Create Tables via SESSION + +Tables can be created automatically when inserting data via session. + +**Examples:** + +```Java +try (ITableSession session = + new TableSessionBuilder() + .nodeUrls(Collections.singletonList("127.0.0.1:6667")) + .username("root") + .password("root") + .build()) { + + session.executeNonQueryStatement("CREATE DATABASE db1"); + session.executeNonQueryStatement("use db1"); + + // Insert data without manually creating the table + List columnNameList = + Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); + List dataTypeList = + Arrays.asList( + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.FLOAT, + TSDataType.DOUBLE); + List columnTypeList = + new ArrayList<>( + Arrays.asList( + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.ATTRIBUTE, + ColumnCategory.FIELD, + ColumnCategory.FIELD)); + Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); + for (long timestamp = 0; timestamp < 100; timestamp++) { + int rowIndex = tablet.getRowSize(); + tablet.addTimestamp(rowIndex, timestamp); + tablet.addValue("region_id", rowIndex, "1"); + tablet.addValue("plant_id", rowIndex, "5"); + tablet.addValue("device_id", rowIndex, "3"); + tablet.addValue("model", rowIndex, "A"); + tablet.addValue("temperature", rowIndex, 37.6F); + tablet.addValue("humidity", rowIndex, 111.1); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + session.insert(tablet); + tablet.reset(); + } + } + if (tablet.getRowSize() != 0) { + session.insert(tablet); + tablet.reset(); + } +} +``` + +After the code execution is complete, you can use the following statement to verify that the table has been successfully created, including details about the time column, tag columns, attribute columns, and field columns. + +```SQL +IoTDB> desc table1 ++-----------+---------+-----------+-------+ +| ColumnName| DataType| Category|Comment| ++-----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| region_id| STRING| TAG| null| +| plant_id| STRING| TAG| null| +| device_id| STRING| TAG| null| +| model| STRING| ATTRIBUTE| null| +|temperature| FLOAT| FIELD| null| +| humidity| DOUBLE| FIELD| null| ++-----------+---------+-----------+-------+ +``` + +### 1.2 View Tables + +Used to view all tables and their properties in the current or a specified database. + +**Syntax:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**Note:** + +1. If the `FROM` or `IN` clause is specified, the command lists all tables in the specified database. +2. If neither `FROM` nor `IN` is specified, the command lists all tables in the currently selected database. If no database is selected (`USE` statement not executed), an error is returned. +3. When the `DETAILS` option is used, the command shows the current state of each table: + 1. `USING`: The table is available and operational. + 2. `PRE_CREATE`: The table is in the process of being created or the creation has failed; the table is not available. + 3. `PRE_DELETE`: The table is in the process of being deleted or the deletion has failed; the table will remain permanently unavailable. + +**Examples:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 1.3 View Table Columns + +Used to view column names, data types, categories, and states of a table. + +**Syntax:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**Note:** If the `DETAILS` option is specified, detailed state information of the columns is displayed: + +- `USING`: The column is in normal use. +- `PRE_DELETE`: The column is being deleted or the deletion has failed; it is permanently unavailable. + + + +**Examples:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 1.4 Update Tables + +Used to update a table, including adding or deleting columns and configuring table properties. + +**Syntax:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**Note::** + +1. The `SET PROPERTIES` operation currently only supports configuring the `TTL` property of a table +2. The delete column function only supports deleting the ATTRIBUTE and FILD columns, and the TAG column does not support deletion. +3. The modified comment will overwrite the original comment. If null is specified, the previous comment will be erased. + +**Example:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 1.5 Delete Tables + +Used to delete a table. + +**Syntax:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/Reference/System-Tables_apache.md b/src/UserGuide/latest-Table/Reference/System-Tables_apache.md new file mode 100644 index 000000000..3d7c27e4a --- /dev/null +++ b/src/UserGuide/latest-Table/Reference/System-Tables_apache.md @@ -0,0 +1,600 @@ + + +# System Tables + +IoTDB has a built-in system database called `INFORMATION_SCHEMA`, which contains a series of system tables for storing IoTDB runtime information (such as currently executing SQL statements, etc.). Currently, the `INFORMATION_SCHEMA` database only supports read operations. + +## 1. System Database + +* ​**Name**​: `INFORMATION_SCHEMA` +* ​**Commands**​: Read-only, only supports `Show databases (DETAILS)` / `Show Tables (DETAILS)` / `Use`. Other operations will result in an error: `"The database 'information_schema' can only be queried."` +* ​**Attributes**​:` TTL=INF`, other attributes default to `null ` +* ​**SQL Example**​: + +```sql +IoTDB> show databases ++------------------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++------------------+-------+-----------------------+---------------------+---------------------+ +|information_schema| INF| null| null| null| ++------------------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show tables from information_schema ++--------------+-------+ +| TableName|TTL(ms)| ++--------------+-------+ +| columns| INF| +| config_nodes| INF| +|configurations| INF| +| data_nodes| INF| +| databases| INF| +| functions| INF| +| keywords| INF| +| models| INF| +| nodes| INF| +| pipe_plugins| INF| +| pipes| INF| +| queries| INF| +| regions| INF| +| subscriptions| INF| +| tables| INF| +| topics| INF| +| views| INF| ++--------------+-------+ +``` + +## 2. System Tables + +* ​**Names**​: `DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES` (detailed descriptions in later sections) +* ​**Operations**​: Read-only, only supports `SELECT`, `COUNT/SHOW DEVICES`, `DESC`. Any modifications to table structure or content are not allowed and will result in an error: `"The database 'information_schema' can only be queried." ` +* ​**Column Names**​: System table column names are all lowercase by default and separated by underscores (`_`). + +### 2.1 DATABASES + +* Contains information about all databases in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| --------------------------------- | ----------- | ------------- | -------------------------------- | +| `database` | STRING | TAG | Database name | +| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | +| `schema_replication_factor` | INT32 | ATTRIBUTE | Schema replica count | +| `data_replication_factor` | INT32 | ATTRIBUTE | Data replica count | +| `time_partition_interval` | INT64 | ATTRIBUTE | Time partition interval | +| `schema_region_group_num` | INT32 | ATTRIBUTE | Number of schema region groups | +| `data_region_group_num` | INT32 | ATTRIBUTE | Number of data region groups | + +* The query results only display the collection of databases for which you have any permission on the database itself or any table within the database. +* Query Example: + +```sql +IoTDB> select * from information_schema.databases ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +|information_schema| INF| null| null| null| null| null| +| database1| INF| 1| 1| 604800000| 0| 0| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +``` + +### 2.2 TABLES + +* Contains information about all tables in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------ | ----------- | ------------- | --------------------- | +| `database` | STRING | TAG | Database name | +| `table_name` | STRING | TAG | Table name | +| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | +| `status` | STRING | ATTRIBUTE | Status | +| `comment` | STRING | ATTRIBUTE | Description/comment | + +* Note: Possible values for `status`: `USING`, `PRE_CREATE`, `PRE_DELETE`. For details, refer to the [View Tables](../Basic-Concept/Table-Management.md#12-view-tables) in Table Management documentation +* The query results only display the collection of tables for which you have any permission. +* Query Example: + +```sql +IoTDB> select * from information_schema.tables ++------------------+--------------+-----------+------+-------+-----------+ +| database| table_name| ttl(ms)|status|comment| table_type| ++------------------+--------------+-----------+------+-------+-----------+ +|information_schema| databases| INF| USING| null|SYSTEM VIEW| +|information_schema| models| INF| USING| null|SYSTEM VIEW| +|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| +|information_schema| regions| INF| USING| null|SYSTEM VIEW| +|information_schema| functions| INF| USING| null|SYSTEM VIEW| +|information_schema| keywords| INF| USING| null|SYSTEM VIEW| +|information_schema| columns| INF| USING| null|SYSTEM VIEW| +|information_schema| topics| INF| USING| null|SYSTEM VIEW| +|information_schema|configurations| INF| USING| null|SYSTEM VIEW| +|information_schema| queries| INF| USING| null|SYSTEM VIEW| +|information_schema| tables| INF| USING| null|SYSTEM VIEW| +|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| +|information_schema| nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| pipes| INF| USING| null|SYSTEM VIEW| +|information_schema| views| INF| USING| null|SYSTEM VIEW| +|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| +| database1| table1|31536000000| USING| null| BASE TABLE| ++------------------+--------------+-----------+------+-------+-----------+ +``` + +### 2.3 REGIONS + +* Contains information about all regions in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------------- | ----------- | ------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `region_id` | INT32 | TAG | Region ID | +| `datanode_id` | INT32 | TAG | DataNode ID | +| `type` | STRING | ATTRIBUTE | Type (`SchemaRegion`/`DataRegion`) | +| `status` | STRING | ATTRIBUTE | Status (`Running`,`Unknown`, etc.) | +| `database` | STRING | ATTRIBUTE | Database name | +| `series_slot_num` | INT32 | ATTRIBUTE | Number of series slots | +| `time_slot_num` | INT64 | ATTRIBUTE | Number of time slots | +| `rpc_address` | STRING | ATTRIBUTE | RPC address | +| `rpc_port` | INT32 | ATTRIBUTE | RPC port | +| `internal_address` | STRING | ATTRIBUTE | Internal communication address | +| `role` | STRING | ATTRIBUTE | Role (`Leader`/`Follower`) | +| `create_time` | TIMESTAMP | ATTRIBUTE | Creation time | +| `tsfile_size_bytes` | INT64 | ATTRIBUTE | - For​**DataRegion with statistics ​**​: Total file size of TsFiles.
- For**DataRegion without statistics**(Unknown):`-1`.
- For​**SchemaRegion**​:`null`. | + +* Only administrators are allowed to perform query operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.regions ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| +| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| +| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +``` + +### 2.4 QUERIES + +* Contains information about all currently executing queries in the cluster. Can also be queried using the `SHOW QUERIES` syntax. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| -------------------- | ----------- | ------------- | ------------------------------------------------------------ | +| `query_id` | STRING | TAG | Query ID | +| `start_time` | TIMESTAMP | ATTRIBUTE | Query start timestamp (precision matches system precision) | +| `datanode_id` | INT32 | ATTRIBUTE | DataNode ID that initiated the query | +| `elapsed_time` | FLOAT | ATTRIBUTE | Query execution duration (in seconds) | +| `statement` | STRING | ATTRIBUTE | SQL statement of the query | +| `user` | STRING | ATTRIBUTE | User who initiated the query | + +* For regular users, the query results only display the queries executed by themselves; for administrators, all queries are displayed. +* Query Example: + +```SQL +IoTDB> select * from information_schema.queries ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +``` + +### 2.5 COLUMNS + +* Contains information about all columns in tables across the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------- | ----------- | ------------- | -------------------- | +| `database` | STRING | TAG | Database name | +| `table_name` | STRING | TAG | Table name | +| `column_name` | STRING | TAG | Column name | +| `datatype` | STRING | ATTRIBUTE | Column data type | +| `category` | STRING | ATTRIBUTE | Column category | +| `status` | STRING | ATTRIBUTE | Column status | +| `comment` | STRING | ATTRIBUTE | Column description | + +Notes: +* Possible values for `status`: `USING`, `PRE_DELETE`. For details, refer to [Viewing Table Columns](../Basic-Concept/Table-Management.html#13-view-table-columns) in Table Management documentation. +* The query results only display the column information of tables for which you have any permission. + +* Query Example: + +```SQL +IoTDB> select * from information_schema.columns where database = 'database1' ++---------+----------+------------+---------+---------+------+-------+ +| database|table_name| column_name| datatype| category|status|comment| ++---------+----------+------------+---------+---------+------+-------+ +|database1| table1| time|TIMESTAMP| TIME| USING| null| +|database1| table1| region| STRING| TAG| USING| null| +|database1| table1| plant_id| STRING| TAG| USING| null| +|database1| table1| device_id| STRING| TAG| USING| null| +|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| +|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| +|database1| table1| temperature| FLOAT| FIELD| USING| null| +|database1| table1| humidity| FLOAT| FIELD| USING| null| +|database1| table1| status| BOOLEAN| FIELD| USING| null| +|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| ++---------+----------+------------+---------+---------+------+-------+ +``` + +### 2.6 PIPES + +* Contains information about all pipes in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ----------------------------------- | ----------- | ------------- | ---------------------------------------------------------- | +| `id` | STRING | TAG | Pipe name | +| `creation_time` | TIMESTAMP | ATTRIBUTE | Creation time | +| `state` | STRING | ATTRIBUTE | Pipe status (`RUNNING`/`STOPPED`) | +| `pipe_source` | STRING | ATTRIBUTE | Source plugin parameters | +| `pipe_processor` | STRING | ATTRIBUTE | Processor plugin parameters | +| `pipe_sink` | STRING | ATTRIBUTE | Sink plugin parameters | +| `exception_message` | STRING | ATTRIBUTE | Exception message | +| `remaining_event_count` | INT64 | ATTRIBUTE | Remaining event count (`-1`if Unknown) | +| `estimated_remaining_seconds` | DOUBLE | ATTRIBUTE | Estimated remaining time in seconds (`-1`if Unknown) | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +select * from information_schema.pipes ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +``` + +### 2.7 PIPE\_PLUGINS + +* Contains information about all PIPE plugins in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------- | ----------- | ------------- | ----------------------------------------------------- | +| `plugin_name` | STRING | TAG | Plugin name | +| `plugin_type` | STRING | ATTRIBUTE | Plugin type (`Builtin`/`External`) | +| `class_name` | STRING | ATTRIBUTE | Plugin's main class name | +| `plugin_jar` | STRING | ATTRIBUTE | Plugin's JAR file name (`null`for builtin type) | + +* Query Example: + +```SQL +IoTDB> select * from information_schema.pipe_plugins ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +| plugin_name|plugin_type| class_name|plugin_jar| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| +| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| +| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| +| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| +| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| +| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +``` + +### 2.8 SUBSCRIPTIONS + +* Contains information about all data subscriptions in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ---------------------------- | ----------- | ------------- | ------------------------- | +| `topic_name` | STRING | TAG | Subscription topic name | +| `consumer_group_name` | STRING | TAG | Consumer group name | +| `subscribed_consumers` | STRING | ATTRIBUTE | Subscribed consumers | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' ++----------+-------------------+--------------------------------+ +|topic_name|consumer_group_name| subscribed_consumers| ++----------+-------------------+--------------------------------+ +| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| ++----------+-------------------+--------------------------------+ +``` + +### 2.9 TOPICS + +* Contains information about all data subscription topics in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| --------------------- | ----------- | ------------- | -------------------------------- | +| `topic_name` | STRING | TAG | Subscription topic name | +| `topic_configs` | STRING | ATTRIBUTE | Topic configuration parameters | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.topics ++----------+----------------------------------------------------------------+ +|topic_name| topic_configs| ++----------+----------------------------------------------------------------+ +| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| ++----------+----------------------------------------------------------------+ +``` + +### 2.10 VIEWS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all table views in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------ | ----------- | ----------------- | --------------------------------- | +| database | STRING | TAG | Database name | +| table\_name | STRING | TAG | View name | +| view\_definition | STRING | ATTRIBUTE | SQL statement for view creation | + +* The query results only display the collection of views for which you have any permission. +* Query example: + +```SQL +IoTDB> select * from information_schema.views ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +| database|table_name| view_definition| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +``` + + +### 2.11 MODELS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all models in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------------------------------------------------------------------------ | +| model\_id | STRING | TAG | Model name | +| model\_type | STRING | ATTRIBUTE | Model type (Forecast, Anomaly Detection, Custom) | +| state | STRING | ATTRIBUTE | Model status (Available/Unavailable) | +| configs | STRING | ATTRIBUTE | String format of model hyperparameters, consistent with the output of the `show` command | +| notes | STRING | ATTRIBUTE | Model description\* Built-in model: Built-in model in IoTDB\* User-defined model: Custom model | + +* Query example: + +```SQL +-- Find all built-in forecast models +IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' ++---------------------+-----------------+------+-------+-----------------------+ +| model_id| model_type| state|configs| notes| ++---------------------+-----------------+------+-------+-----------------------+ +| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| ++---------------------+-----------------+------+-------+-----------------------+ +``` + + +### 2.12 FUNCTIONS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all functions in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------ | ----------- | ----------------- | -------------------------------------------------------------------------- | +| function\_name | STRING | TAG | Function name | +| function\_type | STRING | ATTRIBUTE | Function type (Built-in/User-defined, Scalar/Aggregation/Table Function) | +| class\_name(udf) | STRING | ATTRIBUTE | Class name if it is a UDF, otherwise null (tentative) | +| state | STRING | ATTRIBUTE | Availability status | + +* Query example: + +```SQL +IoTDB> select * from information_schema.functions where function_type='built-in table function' ++--------------+-----------------------+---------------+---------+ +|function_name | function_type|class_name(udf)| state| ++--------------+-----------------------+---------------+---------+ +| CUMULATE|built-in table function| null|AVAILABLE| +| SESSION|built-in table function| null|AVAILABLE| +| HOP|built-in table function| null|AVAILABLE| +| TUMBLE|built-in table function| null|AVAILABLE| +| FORECAST|built-in table function| null|AVAILABLE| +| VARIATION|built-in table function| null|AVAILABLE| +| CAPACITY|built-in table function| null|AVAILABLE| ++--------------+-----------------------+---------------+---------+ +``` + + +### 2.13 CONFIGURATIONS Table + +> This system table is available starting from version V2.0.5. + +* Contains all configuration properties of the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------ | +| variable | STRING | TAG | Configuration property name | +| value | STRING | ATTRIBUTE | Configuration property value | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.configurations ++----------------------------------+-----------------------------------------------------------------+ +| variable| value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + + +### 2.14 KEYWORDS Table + +> This system table is available starting from version V2.0.5. + +* Contains all keywords in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------------------------- | +| word | STRING | TAG | Keyword | +| reserved | INT32 | ATTRIBUTE | Whether it is a reserved word (1 = Yes, 0 = No) | + +* Query example: + +```SQL +IoTDB> select * from information_schema.keywords limit 10 ++----------+--------+ +| word|reserved| ++----------+--------+ +| ABSENT| 0| +|ACTIVATION| 1| +| ACTIVATE| 1| +| ADD| 0| +| ADMIN| 0| +| AFTER| 0| +| AINODES| 1| +| ALL| 0| +| ALTER| 1| +| ANALYZE| 0| ++----------+--------+ +``` + + +### 2.15 NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all nodes in the database cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| -------------------------------------------- | ----------- | ----------------- | ---------------------- | +| node\_id | INT32 | TAG | Node ID | +| node\_type | STRING | ATTRIBUTE | Node type | +| status | STRING | ATTRIBUTE | Node status | +| internal\_address | STRING | ATTRIBUTE | Internal RPC address | +| internal\_port | INT32 | ATTRIBUTE | Internal port | +| version | STRING | ATTRIBUTE | Version number | +| build\_info | STRING | ATTRIBUTE | Commit ID | +| activate\_status (Enterprise Edition only) | STRING | ATTRIBUTE | Activation status | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.nodes ++-------+----------+-------+----------------+-------------+-------+----------+ +|node_id| node_type| status|internal_address|internal_port|version|build_info| ++-------+----------+-------+----------------+-------------+-------+----------+ +| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| +| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| ++-------+----------+-------+----------------+-------------+-------+----------+ +``` + + +### 2.16 CONFIG\_NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all ConfigNodes in the cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------------- | ----------- | ----------------- | --------------------------- | +| node\_id | INT32 | TAG | Node ID | +| config\_consensus\_port | INT32 | ATTRIBUTE | ConfigNode consensus port | +| role | STRING | ATTRIBUTE | ConfigNode role | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.config_nodes ++-------+---------------------+------+ +|node_id|config_consensus_port| role| ++-------+---------------------+------+ +| 0| 10720|Leader| ++-------+---------------------+------+ +``` + + +### 2.17 DATA\_NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all DataNodes in the cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------------- | ----------- | ----------------- | ----------------------------- | +| node\_id | INT32 | TAG | Node ID | +| data\_region\_num | INT32 | ATTRIBUTE | Number of DataRegions | +| schema\_region\_num | INT32 | ATTRIBUTE | Number of SchemaRegions | +| rpc\_address | STRING | ATTRIBUTE | RPC address | +| rpc\_port | INT32 | ATTRIBUTE | RPC port | +| mpp\_port | INT32 | ATTRIBUTE | MPP communication port | +| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion consensus port | +| schema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion consensus port | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.data_nodes ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +``` + +## 3. Permission Description + +* GRANT/REVOKE operations are not supported for the `information_schema` database or any of its tables. +* All users can view `information_schema` database details via the `SHOW DATABASES` statement. +* All users can list system tables via `SHOW TABLES FROM information_schema`. +* All users can inspect system table structures using the `DESC` statement. diff --git a/src/UserGuide/latest-Table/Reference/System-Tables_timecho.md b/src/UserGuide/latest-Table/Reference/System-Tables_timecho.md new file mode 100644 index 000000000..3d7c27e4a --- /dev/null +++ b/src/UserGuide/latest-Table/Reference/System-Tables_timecho.md @@ -0,0 +1,600 @@ + + +# System Tables + +IoTDB has a built-in system database called `INFORMATION_SCHEMA`, which contains a series of system tables for storing IoTDB runtime information (such as currently executing SQL statements, etc.). Currently, the `INFORMATION_SCHEMA` database only supports read operations. + +## 1. System Database + +* ​**Name**​: `INFORMATION_SCHEMA` +* ​**Commands**​: Read-only, only supports `Show databases (DETAILS)` / `Show Tables (DETAILS)` / `Use`. Other operations will result in an error: `"The database 'information_schema' can only be queried."` +* ​**Attributes**​:` TTL=INF`, other attributes default to `null ` +* ​**SQL Example**​: + +```sql +IoTDB> show databases ++------------------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++------------------+-------+-----------------------+---------------------+---------------------+ +|information_schema| INF| null| null| null| ++------------------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show tables from information_schema ++--------------+-------+ +| TableName|TTL(ms)| ++--------------+-------+ +| columns| INF| +| config_nodes| INF| +|configurations| INF| +| data_nodes| INF| +| databases| INF| +| functions| INF| +| keywords| INF| +| models| INF| +| nodes| INF| +| pipe_plugins| INF| +| pipes| INF| +| queries| INF| +| regions| INF| +| subscriptions| INF| +| tables| INF| +| topics| INF| +| views| INF| ++--------------+-------+ +``` + +## 2. System Tables + +* ​**Names**​: `DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES` (detailed descriptions in later sections) +* ​**Operations**​: Read-only, only supports `SELECT`, `COUNT/SHOW DEVICES`, `DESC`. Any modifications to table structure or content are not allowed and will result in an error: `"The database 'information_schema' can only be queried." ` +* ​**Column Names**​: System table column names are all lowercase by default and separated by underscores (`_`). + +### 2.1 DATABASES + +* Contains information about all databases in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| --------------------------------- | ----------- | ------------- | -------------------------------- | +| `database` | STRING | TAG | Database name | +| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | +| `schema_replication_factor` | INT32 | ATTRIBUTE | Schema replica count | +| `data_replication_factor` | INT32 | ATTRIBUTE | Data replica count | +| `time_partition_interval` | INT64 | ATTRIBUTE | Time partition interval | +| `schema_region_group_num` | INT32 | ATTRIBUTE | Number of schema region groups | +| `data_region_group_num` | INT32 | ATTRIBUTE | Number of data region groups | + +* The query results only display the collection of databases for which you have any permission on the database itself or any table within the database. +* Query Example: + +```sql +IoTDB> select * from information_schema.databases ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +|information_schema| INF| null| null| null| null| null| +| database1| INF| 1| 1| 604800000| 0| 0| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +``` + +### 2.2 TABLES + +* Contains information about all tables in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------ | ----------- | ------------- | --------------------- | +| `database` | STRING | TAG | Database name | +| `table_name` | STRING | TAG | Table name | +| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | +| `status` | STRING | ATTRIBUTE | Status | +| `comment` | STRING | ATTRIBUTE | Description/comment | + +* Note: Possible values for `status`: `USING`, `PRE_CREATE`, `PRE_DELETE`. For details, refer to the [View Tables](../Basic-Concept/Table-Management.md#12-view-tables) in Table Management documentation +* The query results only display the collection of tables for which you have any permission. +* Query Example: + +```sql +IoTDB> select * from information_schema.tables ++------------------+--------------+-----------+------+-------+-----------+ +| database| table_name| ttl(ms)|status|comment| table_type| ++------------------+--------------+-----------+------+-------+-----------+ +|information_schema| databases| INF| USING| null|SYSTEM VIEW| +|information_schema| models| INF| USING| null|SYSTEM VIEW| +|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| +|information_schema| regions| INF| USING| null|SYSTEM VIEW| +|information_schema| functions| INF| USING| null|SYSTEM VIEW| +|information_schema| keywords| INF| USING| null|SYSTEM VIEW| +|information_schema| columns| INF| USING| null|SYSTEM VIEW| +|information_schema| topics| INF| USING| null|SYSTEM VIEW| +|information_schema|configurations| INF| USING| null|SYSTEM VIEW| +|information_schema| queries| INF| USING| null|SYSTEM VIEW| +|information_schema| tables| INF| USING| null|SYSTEM VIEW| +|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| +|information_schema| nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| pipes| INF| USING| null|SYSTEM VIEW| +|information_schema| views| INF| USING| null|SYSTEM VIEW| +|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| +| database1| table1|31536000000| USING| null| BASE TABLE| ++------------------+--------------+-----------+------+-------+-----------+ +``` + +### 2.3 REGIONS + +* Contains information about all regions in the cluster. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------------- | ----------- | ------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `region_id` | INT32 | TAG | Region ID | +| `datanode_id` | INT32 | TAG | DataNode ID | +| `type` | STRING | ATTRIBUTE | Type (`SchemaRegion`/`DataRegion`) | +| `status` | STRING | ATTRIBUTE | Status (`Running`,`Unknown`, etc.) | +| `database` | STRING | ATTRIBUTE | Database name | +| `series_slot_num` | INT32 | ATTRIBUTE | Number of series slots | +| `time_slot_num` | INT64 | ATTRIBUTE | Number of time slots | +| `rpc_address` | STRING | ATTRIBUTE | RPC address | +| `rpc_port` | INT32 | ATTRIBUTE | RPC port | +| `internal_address` | STRING | ATTRIBUTE | Internal communication address | +| `role` | STRING | ATTRIBUTE | Role (`Leader`/`Follower`) | +| `create_time` | TIMESTAMP | ATTRIBUTE | Creation time | +| `tsfile_size_bytes` | INT64 | ATTRIBUTE | - For​**DataRegion with statistics ​**​: Total file size of TsFiles.
- For**DataRegion without statistics**(Unknown):`-1`.
- For​**SchemaRegion**​:`null`. | + +* Only administrators are allowed to perform query operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.regions ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| +| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| +| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +``` + +### 2.4 QUERIES + +* Contains information about all currently executing queries in the cluster. Can also be queried using the `SHOW QUERIES` syntax. +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| -------------------- | ----------- | ------------- | ------------------------------------------------------------ | +| `query_id` | STRING | TAG | Query ID | +| `start_time` | TIMESTAMP | ATTRIBUTE | Query start timestamp (precision matches system precision) | +| `datanode_id` | INT32 | ATTRIBUTE | DataNode ID that initiated the query | +| `elapsed_time` | FLOAT | ATTRIBUTE | Query execution duration (in seconds) | +| `statement` | STRING | ATTRIBUTE | SQL statement of the query | +| `user` | STRING | ATTRIBUTE | User who initiated the query | + +* For regular users, the query results only display the queries executed by themselves; for administrators, all queries are displayed. +* Query Example: + +```SQL +IoTDB> select * from information_schema.queries ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +``` + +### 2.5 COLUMNS + +* Contains information about all columns in tables across the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------- | ----------- | ------------- | -------------------- | +| `database` | STRING | TAG | Database name | +| `table_name` | STRING | TAG | Table name | +| `column_name` | STRING | TAG | Column name | +| `datatype` | STRING | ATTRIBUTE | Column data type | +| `category` | STRING | ATTRIBUTE | Column category | +| `status` | STRING | ATTRIBUTE | Column status | +| `comment` | STRING | ATTRIBUTE | Column description | + +Notes: +* Possible values for `status`: `USING`, `PRE_DELETE`. For details, refer to [Viewing Table Columns](../Basic-Concept/Table-Management.html#13-view-table-columns) in Table Management documentation. +* The query results only display the column information of tables for which you have any permission. + +* Query Example: + +```SQL +IoTDB> select * from information_schema.columns where database = 'database1' ++---------+----------+------------+---------+---------+------+-------+ +| database|table_name| column_name| datatype| category|status|comment| ++---------+----------+------------+---------+---------+------+-------+ +|database1| table1| time|TIMESTAMP| TIME| USING| null| +|database1| table1| region| STRING| TAG| USING| null| +|database1| table1| plant_id| STRING| TAG| USING| null| +|database1| table1| device_id| STRING| TAG| USING| null| +|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| +|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| +|database1| table1| temperature| FLOAT| FIELD| USING| null| +|database1| table1| humidity| FLOAT| FIELD| USING| null| +|database1| table1| status| BOOLEAN| FIELD| USING| null| +|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| ++---------+----------+------------+---------+---------+------+-------+ +``` + +### 2.6 PIPES + +* Contains information about all pipes in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ----------------------------------- | ----------- | ------------- | ---------------------------------------------------------- | +| `id` | STRING | TAG | Pipe name | +| `creation_time` | TIMESTAMP | ATTRIBUTE | Creation time | +| `state` | STRING | ATTRIBUTE | Pipe status (`RUNNING`/`STOPPED`) | +| `pipe_source` | STRING | ATTRIBUTE | Source plugin parameters | +| `pipe_processor` | STRING | ATTRIBUTE | Processor plugin parameters | +| `pipe_sink` | STRING | ATTRIBUTE | Sink plugin parameters | +| `exception_message` | STRING | ATTRIBUTE | Exception message | +| `remaining_event_count` | INT64 | ATTRIBUTE | Remaining event count (`-1`if Unknown) | +| `estimated_remaining_seconds` | DOUBLE | ATTRIBUTE | Estimated remaining time in seconds (`-1`if Unknown) | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +select * from information_schema.pipes ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +``` + +### 2.7 PIPE\_PLUGINS + +* Contains information about all PIPE plugins in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ------------------- | ----------- | ------------- | ----------------------------------------------------- | +| `plugin_name` | STRING | TAG | Plugin name | +| `plugin_type` | STRING | ATTRIBUTE | Plugin type (`Builtin`/`External`) | +| `class_name` | STRING | ATTRIBUTE | Plugin's main class name | +| `plugin_jar` | STRING | ATTRIBUTE | Plugin's JAR file name (`null`for builtin type) | + +* Query Example: + +```SQL +IoTDB> select * from information_schema.pipe_plugins ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +| plugin_name|plugin_type| class_name|plugin_jar| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| +| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| +| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| +| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| +| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| +| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +``` + +### 2.8 SUBSCRIPTIONS + +* Contains information about all data subscriptions in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| ---------------------------- | ----------- | ------------- | ------------------------- | +| `topic_name` | STRING | TAG | Subscription topic name | +| `consumer_group_name` | STRING | TAG | Consumer group name | +| `subscribed_consumers` | STRING | ATTRIBUTE | Subscribed consumers | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' ++----------+-------------------+--------------------------------+ +|topic_name|consumer_group_name| subscribed_consumers| ++----------+-------------------+--------------------------------+ +| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| ++----------+-------------------+--------------------------------+ +``` + +### 2.9 TOPICS + +* Contains information about all data subscription topics in the cluster +* Table structure is as follows: + +| Column Name | Data Type | Column Type | Description | +| --------------------- | ----------- | ------------- | -------------------------------- | +| `topic_name` | STRING | TAG | Subscription topic name | +| `topic_configs` | STRING | ATTRIBUTE | Topic configuration parameters | + +* Only administrators are allowed to perform operations. +* Query Example: + +```SQL +IoTDB> select * from information_schema.topics ++----------+----------------------------------------------------------------+ +|topic_name| topic_configs| ++----------+----------------------------------------------------------------+ +| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| ++----------+----------------------------------------------------------------+ +``` + +### 2.10 VIEWS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all table views in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------ | ----------- | ----------------- | --------------------------------- | +| database | STRING | TAG | Database name | +| table\_name | STRING | TAG | View name | +| view\_definition | STRING | ATTRIBUTE | SQL statement for view creation | + +* The query results only display the collection of views for which you have any permission. +* Query example: + +```SQL +IoTDB> select * from information_schema.views ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +| database|table_name| view_definition| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +``` + + +### 2.11 MODELS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all models in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------------------------------------------------------------------------ | +| model\_id | STRING | TAG | Model name | +| model\_type | STRING | ATTRIBUTE | Model type (Forecast, Anomaly Detection, Custom) | +| state | STRING | ATTRIBUTE | Model status (Available/Unavailable) | +| configs | STRING | ATTRIBUTE | String format of model hyperparameters, consistent with the output of the `show` command | +| notes | STRING | ATTRIBUTE | Model description\* Built-in model: Built-in model in IoTDB\* User-defined model: Custom model | + +* Query example: + +```SQL +-- Find all built-in forecast models +IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' ++---------------------+-----------------+------+-------+-----------------------+ +| model_id| model_type| state|configs| notes| ++---------------------+-----------------+------+-------+-----------------------+ +| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| ++---------------------+-----------------+------+-------+-----------------------+ +``` + + +### 2.12 FUNCTIONS Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all functions in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------ | ----------- | ----------------- | -------------------------------------------------------------------------- | +| function\_name | STRING | TAG | Function name | +| function\_type | STRING | ATTRIBUTE | Function type (Built-in/User-defined, Scalar/Aggregation/Table Function) | +| class\_name(udf) | STRING | ATTRIBUTE | Class name if it is a UDF, otherwise null (tentative) | +| state | STRING | ATTRIBUTE | Availability status | + +* Query example: + +```SQL +IoTDB> select * from information_schema.functions where function_type='built-in table function' ++--------------+-----------------------+---------------+---------+ +|function_name | function_type|class_name(udf)| state| ++--------------+-----------------------+---------------+---------+ +| CUMULATE|built-in table function| null|AVAILABLE| +| SESSION|built-in table function| null|AVAILABLE| +| HOP|built-in table function| null|AVAILABLE| +| TUMBLE|built-in table function| null|AVAILABLE| +| FORECAST|built-in table function| null|AVAILABLE| +| VARIATION|built-in table function| null|AVAILABLE| +| CAPACITY|built-in table function| null|AVAILABLE| ++--------------+-----------------------+---------------+---------+ +``` + + +### 2.13 CONFIGURATIONS Table + +> This system table is available starting from version V2.0.5. + +* Contains all configuration properties of the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------ | +| variable | STRING | TAG | Configuration property name | +| value | STRING | ATTRIBUTE | Configuration property value | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.configurations ++----------------------------------+-----------------------------------------------------------------+ +| variable| value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + + +### 2.14 KEYWORDS Table + +> This system table is available starting from version V2.0.5. + +* Contains all keywords in the database. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------- | ----------- | ----------------- | ------------------------------------------------- | +| word | STRING | TAG | Keyword | +| reserved | INT32 | ATTRIBUTE | Whether it is a reserved word (1 = Yes, 0 = No) | + +* Query example: + +```SQL +IoTDB> select * from information_schema.keywords limit 10 ++----------+--------+ +| word|reserved| ++----------+--------+ +| ABSENT| 0| +|ACTIVATION| 1| +| ACTIVATE| 1| +| ADD| 0| +| ADMIN| 0| +| AFTER| 0| +| AINODES| 1| +| ALL| 0| +| ALTER| 1| +| ANALYZE| 0| ++----------+--------+ +``` + + +### 2.15 NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all nodes in the database cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| -------------------------------------------- | ----------- | ----------------- | ---------------------- | +| node\_id | INT32 | TAG | Node ID | +| node\_type | STRING | ATTRIBUTE | Node type | +| status | STRING | ATTRIBUTE | Node status | +| internal\_address | STRING | ATTRIBUTE | Internal RPC address | +| internal\_port | INT32 | ATTRIBUTE | Internal port | +| version | STRING | ATTRIBUTE | Version number | +| build\_info | STRING | ATTRIBUTE | Commit ID | +| activate\_status (Enterprise Edition only) | STRING | ATTRIBUTE | Activation status | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.nodes ++-------+----------+-------+----------------+-------------+-------+----------+ +|node_id| node_type| status|internal_address|internal_port|version|build_info| ++-------+----------+-------+----------------+-------------+-------+----------+ +| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| +| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| ++-------+----------+-------+----------------+-------------+-------+----------+ +``` + + +### 2.16 CONFIG\_NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all ConfigNodes in the cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------------- | ----------- | ----------------- | --------------------------- | +| node\_id | INT32 | TAG | Node ID | +| config\_consensus\_port | INT32 | ATTRIBUTE | ConfigNode consensus port | +| role | STRING | ATTRIBUTE | ConfigNode role | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.config_nodes ++-------+---------------------+------+ +|node_id|config_consensus_port| role| ++-------+---------------------+------+ +| 0| 10720|Leader| ++-------+---------------------+------+ +``` + + +### 2.17 DATA\_NODES Table + +> This system table is available starting from version V2.0.5. + +* Contains information about all DataNodes in the cluster. +* The table structure is as follows: + +| Column Name | Data Type | Column Category | Description | +| ------------------------- | ----------- | ----------------- | ----------------------------- | +| node\_id | INT32 | TAG | Node ID | +| data\_region\_num | INT32 | ATTRIBUTE | Number of DataRegions | +| schema\_region\_num | INT32 | ATTRIBUTE | Number of SchemaRegions | +| rpc\_address | STRING | ATTRIBUTE | RPC address | +| rpc\_port | INT32 | ATTRIBUTE | RPC port | +| mpp\_port | INT32 | ATTRIBUTE | MPP communication port | +| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion consensus port | +| schema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion consensus port | + +* Only administrators are allowed to perform operations on this table. +* Query example: + +```SQL +IoTDB> select * from information_schema.data_nodes ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +``` + +## 3. Permission Description + +* GRANT/REVOKE operations are not supported for the `information_schema` database or any of its tables. +* All users can view `information_schema` database details via the `SHOW DATABASES` statement. +* All users can list system tables via `SHOW TABLES FROM information_schema`. +* All users can inspect system table structures using the `DESC` statement. diff --git a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md new file mode 100644 index 000000000..c09789283 --- /dev/null +++ b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md @@ -0,0 +1,304 @@ + + +# Metadata Operations + +## 1. Database Management + +### 1.1 Create Database + +**Syntax:** + +```SQL +CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-1-create-a-database) + +**Examples:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +-- Create database with 1-year TTL +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 Use Database + +**Syntax:** + +```SQL +USE +``` + +**Examples:** + +```SQL +USE database1 +``` + +### 1.3 View Current Database + +**Syntax:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**Examples:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 List All Databases + +**Syntax:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-4-view-all-databases) + +**Examples:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 Modify Database + +**Syntax:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**Examples:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 Drop Database + +**Syntax:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` + +## 2. Table Management + +### 2.1 Create Table + +**Syntax:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +[Detailed syntax reference](../Basic-Concept/Table-Management.md#_1-1-create-a-table) + +**Examples:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status BOOLEAN FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE IF NOT EXISTS table2 (); + +CREATE TABLE tableC ( + "plant" STRING TAG, + "temperature" INT32 FIELD COMMENT 'temperature' +) WITH (TTL=DEFAULT); +``` + +### 2.2 List Tables + +**Syntax:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**Examples:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 2.3 Describe Table Columns + +**Syntax:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**Examples:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 2.4 Modify Table + +**Syntax:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**Examples:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 2.5 Drop Table + +**Syntax:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` + + diff --git a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md new file mode 100644 index 000000000..c09789283 --- /dev/null +++ b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md @@ -0,0 +1,304 @@ + + +# Metadata Operations + +## 1. Database Management + +### 1.1 Create Database + +**Syntax:** + +```SQL +CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-1-create-a-database) + +**Examples:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +-- Create database with 1-year TTL +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 Use Database + +**Syntax:** + +```SQL +USE +``` + +**Examples:** + +```SQL +USE database1 +``` + +### 1.3 View Current Database + +**Syntax:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**Examples:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 List All Databases + +**Syntax:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-4-view-all-databases) + +**Examples:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 Modify Database + +**Syntax:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**Examples:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 Drop Database + +**Syntax:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` + +## 2. Table Management + +### 2.1 Create Table + +**Syntax:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +[Detailed syntax reference](../Basic-Concept/Table-Management.md#_1-1-create-a-table) + +**Examples:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status BOOLEAN FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE IF NOT EXISTS table2 (); + +CREATE TABLE tableC ( + "plant" STRING TAG, + "temperature" INT32 FIELD COMMENT 'temperature' +) WITH (TTL=DEFAULT); +``` + +### 2.2 List Tables + +**Syntax:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**Examples:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 2.3 Describe Table Columns + +**Syntax:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**Examples:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 2.4 Modify Table + +**Syntax:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**Examples:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 2.5 Drop Table + +**Syntax:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` + + diff --git a/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_apache.md b/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_apache.md new file mode 100644 index 000000000..f77af49ce --- /dev/null +++ b/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_apache.md @@ -0,0 +1,653 @@ + +# Maintenance Statement + +## 1. Status Checking + +### 1.1 Viewing the Connected Model + +**Description**: Returns the current SQL dialect model (`Tree` or `Table`). + +**Syntax**: + +```SQL +showCurrentSqlDialectStatement + : SHOW CURRENT_SQL_DIALECT + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_SQL_DIALECT; +``` + +**Result:** + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 1.2 Viewing the Logged-in Username + +**Description**: Returns the currently logged-in username. + +**Syntax**: + +```SQL +showCurrentUserStatement + : SHOW CURRENT_USER + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_USER; +``` + +**Result**: + +```Plain ++-----------+ +|CurrentUser| ++-----------+ +| root| ++-----------+ +``` + +### 1.3 Viewing the Connected Database Name + +**Description**: Returns the name of the currently connected database. If no `USE` statement has been executed, it returns `null`. + +**Syntax**: + +```SQL +showCurrentDatabaseStatement + : SHOW CURRENT_DATABASE + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_DATABASE; +IoTDB> USE test; +IoTDB> SHOW CURRENT_DATABASE; +``` + +**Result**: + +```Plain ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ ++---------------+ +|CurrentDatabase| ++---------------+ +| test| ++---------------+ +``` + +### 1.4 Viewing the Cluster Version + +**Description**: Returns the current cluster version. + +**Syntax**: + +```SQL +showVersionStatement + : SHOW VERSION + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW VERSION; +``` + +**Result**: + +```Plain ++-------+---------+ +|Version|BuildInfo| ++-------+---------+ +|2.0.1.2| 1ca4008| ++-------+---------+ +``` + +### 1.5 Viewing Cluster Key Parameters + +**Description**: Returns key parameters of the current cluster. + +**Syntax**: + +```SQL +showVariablesStatement + : SHOW VARIABLES + ; +``` + +Key Parameters: + +1. **ClusterName**: The name of the current cluster. +2. **DataReplicationFactor**: Number of data replicas per DataRegion. +3. **SchemaReplicationFactor**: Number of schema replicas per SchemaRegion. +4. **DataRegionConsensusProtocolClass**: Consensus protocol class for DataRegions. +5. **SchemaRegionConsensusProtocolClass**: Consensus protocol class for SchemaRegions. +6. **ConfigNodeConsensusProtocolClass**: Consensus protocol class for ConfigNodes. +7. **TimePartitionOrigin**: The starting timestamp of database time partitions. +8. **TimePartitionInterval**: The interval of database time partitions (in milliseconds). +9. **ReadConsistencyLevel**: The consistency level for read operations. +10. **SchemaRegionPerDataNode**: Number of SchemaRegions per DataNode. +11. **DataRegionPerDataNode**: Number of DataRegions per DataNode. +12. **SeriesSlotNum**: Number of SeriesSlots per DataRegion. +13. **SeriesSlotExecutorClass**: Implementation class for SeriesSlots. +14. **DiskSpaceWarningThreshold**: Disk space warning threshold (in percentage). +15. **TimestampPrecision**: Timestamp precision. + +**Example**: + +```SQL +IoTDB> SHOW VARIABLES; +``` + +**Result**: + +```Plain ++----------------------------------+-----------------------------------------------------------------+ +| Variable| Value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 1.6 Viewing the Cluster ID + +**Description**: Returns the ID of the current cluster. + +**Syntax**: + +```SQL +showClusterIdStatement + : SHOW (CLUSTERID | CLUSTER_ID) + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CLUSTER_ID; +``` + +**Result**: + +```Plain ++------------------------------------+ +| ClusterId| ++------------------------------------+ +|40163007-9ec1-4455-aa36-8055d740fcda| ++------------------------------------+ +``` + +### 1.7 Viewing the Timestamp of the Connected DataNode + +**Description**: Returns the current timestamp of the DataNode process directly connected to the client. + +**Syntax**: + +```SQL +showCurrentTimestampStatement + : SHOW CURRENT_TIMESTAMP + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_TIMESTAMP; +``` + +**Result**: + +```Plain ++-----------------------------+ +| CurrentTimestamp| ++-----------------------------+ +|2025-02-17T11:11:52.987+08:00| ++-----------------------------+ +``` + +### 1.8 Viewing Executing Queries + +**Description**: Displays information about all currently executing queries. + +> For more details on how to use system tables, please refer to [System Tables](../Reference/System-Tables.md) + +**Syntax**: + +```SQL +showQueriesStatement + : SHOW (QUERIES | QUERY PROCESSLIST) + (WHERE where=booleanExpression)? + (ORDER BY sortItem (',' sortItem)*)? + limitOffsetClause + ; +``` + +**Parameters**: + +1. **WHERE Clause**: Filters the result set based on specified conditions. +2. **ORDER BY Clause**: Sorts the result set based on specified columns. +3. **limitOffsetClause**: Limits the number of rows returned. + 1. Format: `LIMIT , `. + +**Columns in QUERIES Table**: + +- **query_id**: Unique ID of the query. +- **start_time**: Timestamp when the query started. +- **datanode_id**: ID of the DataNode executing the query. +- **elapsed_time**: Time elapsed since the query started (in seconds). +- **statement**: The SQL statement being executed. +- **user**: The user who initiated the query. + +**Example**: + +```SQL +IoTDB> SHOW QUERIES WHERE elapsed_time > 30; +``` + +**Result**: + +```Plain ++-----------------------+-----------------------------+-----------+------------+------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +``` + + +### 1.9 Viewing Region Information + +**Description**: Displays regions' information of the current cluster. + +**Syntax**: + +```SQL +showRegionsStatement + : SHOW REGIONS + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW REGIONS +``` + +**Result**: + +```SQL ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | +| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| +| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +``` + + +## 2. Status Setting + +### 2.1 Setting the Connected Model + +**Description**: Sets the current SQL dialect model to `Tree` or `Table` which can be used in both tree and table models. + +**Syntax**: + +```SQL +SET SQL_DIALECT = (TABLE | TREE); +``` + +**Example**: + +```SQL +IoTDB> SET SQL_DIALECT=TABLE; +IoTDB> SHOW CURRENT_SQL_DIALECT; +``` + +**Result**: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 2.2 Updating Configuration Items + +**Description**: Updates configuration items. Changes take effect immediately without restarting if the items support hot modification. + +**Syntax**: + +```SQL +setConfigurationStatement + : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? + ; + +propertyAssignments + : property (',' property)* + ; + +property + : identifier EQ propertyValue + ; + +propertyValue + : DEFAULT + | expression + ; +``` + +**Parameters**: + +1. **propertyAssignments**: A list of properties to update. + 1. Format: `property (',' property)*`. + 2. Values: + - `DEFAULT`: Resets the configuration to its default value. + - `expression`: A specific value (must be a string). +2. **ON INTEGER_VALUE** **(Optional):** Specifies the node ID to update. + 1. If not specified or set to a negative value, updates all ConfigNodes and DataNodes. + +**Example**: + +```SQL +IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; +``` + +### 2.3 Loading Manually Modified Configuration Files + +**Description**: Loads manually modified configuration files and hot-loads the changes. Configuration items that support hot modification take effect immediately. + +**Syntax**: + +```SQL +loadConfigurationStatement + : LOAD CONFIGURATION localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode** **(Optional):** + 1. Specifies the scope of configuration loading. + 2. Default: `CLUSTER`. + 3. Values: + - `LOCAL`: Loads configuration only on the DataNode directly connected to the client. + - `CLUSTER`: Loads configuration on all DataNodes in the cluster. + +**Example**: + +```SQL +IoTDB> LOAD CONFIGURATION ON LOCAL; +``` + +### 2.4 Setting the System Status + +**Description**: Sets the system status to either `READONLY` or `RUNNING`. + +**Syntax**: + +```SQL +setSystemStatusStatement + : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **RUNNING |** **READONLY**: + 1. **RUNNING**: Sets the system to running mode, allowing both read and write operations. + 2. **READONLY**: Sets the system to read-only mode, allowing only read operations and prohibiting writes. +2. **localOrClusterMode** **(Optional):** + 1. **LOCAL**: Applies the status change only to the DataNode directly connected to the client. + 2. **CLUSTER**: Applies the status change to all DataNodes in the cluster. + 3. **Default**: `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> SET SYSTEM TO READONLY ON CLUSTER; +``` + +## 3. Data Management + +### 3.1 Flushing Data from Memory to Disk + +**Description**: Flushes data from the memory table to disk. + +**Syntax**: + +```SQL +flushStatement + : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? + ; + +booleanValue + : TRUE | FALSE + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **identifier** **(Optional):** + 1. Specifies the name of the database to flush. + 2. If not specified, all databases are flushed. + 3. **Multiple Databases**: Multiple database names can be specified, separated by commas (e.g., `FLUSH test_db1, test_db2`). +2. **booleanValue** **(****Optional****)**: + 1. Specifies the type of data to flush. + 2. **TRUE**: Flushes only the sequential memory table. + 3. **FALSE**: Flushes only the unsequential MemTable. + 4. **Default**: Flushes both sequential and unsequential memory tables. +3. **localOrClusterMode** **(****Optional****)**: + 1. **ON LOCAL**: Flushes only the memory tables on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Flushes memory tables on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> FLUSH test_db TRUE ON LOCAL; +``` + +### 3.2 Clearing Cache on DataNode + +**Description**: Clears a specific type of cache on DataNode. + +**Syntax**: + +```SQL +clearCacheStatement + : CLEAR clearCacheOptions? CACHE localOrClusterMode? + ; + +clearCacheOptions + : ATTRIBUTE + | QUERY + | ALL + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **clearCacheOptions(Optional)**: + 1. Specifies the type of cache to clear. + 2. **ATTRIBUTE**: Clears device attribute cache. + 3. **QUERY**: Clears query cache in the storage engine. + 4. **ALL**: Clears all caches, including device attribute cache, query cache, and schema cache in the tree model. + 5. **Default**: `QUERY`. +2. **localOrClusterMode(Optional)**: + 1. **ON LOCAL**: Clears cache only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Clears cache on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> CLEAR ALL CACHE ON LOCAL; +``` + +## 4. Data Repair + +### 4.1 Starting Background Scan and Repair of TsFiles + +**Description**: Starts a background task to scan and repair TsFiles, fixing issues such as timestamp disorder within data files. + +**Syntax**: + +```SQL +startRepairDataStatement + : START REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode(Optional)**: + 1. **ON LOCAL**: Executes the repair task only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Executes the repair task on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> START REPAIR DATA ON CLUSTER; +``` + +### 4.2 Pausing Background TsFile Repair Task + +**Description**: Pauses the background repair task. The paused task can be resumed by executing the `START REPAIR DATA` command again. + +**Syntax**: + +```SQL +stopRepairDataStatement + : STOP REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode** **(Optional):** + 1. **ON LOCAL**: Executes the pause command only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Executes the pause command on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> STOP REPAIR DATA ON CLUSTER; +``` + +## 5. Query Termination + +### 5.1 Terminating Queries + +**Description**: Terminates one or more running queries. + +**Syntax**: + +```SQL +killQueryStatement + : KILL (QUERY queryId=string | ALL QUERIES) + ; +``` + +**Parameters**: + +1. **QUERY** **queryId:** Specifies the ID of the query to terminate. + +- To obtain the `queryId`, use the `SHOW QUERIES` command. + +2. **ALL QUERIES:** Terminates all currently running queries. + +**Example**: + +Terminate a specific query: + +```SQL +IoTDB> KILL QUERY 20250108_101015_00000_1; +``` + +Terminate all queries: + +```SQL +IoTDB> KILL ALL QUERIES; +``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_timecho.md b/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_timecho.md new file mode 100644 index 000000000..f77af49ce --- /dev/null +++ b/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_timecho.md @@ -0,0 +1,653 @@ + +# Maintenance Statement + +## 1. Status Checking + +### 1.1 Viewing the Connected Model + +**Description**: Returns the current SQL dialect model (`Tree` or `Table`). + +**Syntax**: + +```SQL +showCurrentSqlDialectStatement + : SHOW CURRENT_SQL_DIALECT + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_SQL_DIALECT; +``` + +**Result:** + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 1.2 Viewing the Logged-in Username + +**Description**: Returns the currently logged-in username. + +**Syntax**: + +```SQL +showCurrentUserStatement + : SHOW CURRENT_USER + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_USER; +``` + +**Result**: + +```Plain ++-----------+ +|CurrentUser| ++-----------+ +| root| ++-----------+ +``` + +### 1.3 Viewing the Connected Database Name + +**Description**: Returns the name of the currently connected database. If no `USE` statement has been executed, it returns `null`. + +**Syntax**: + +```SQL +showCurrentDatabaseStatement + : SHOW CURRENT_DATABASE + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_DATABASE; +IoTDB> USE test; +IoTDB> SHOW CURRENT_DATABASE; +``` + +**Result**: + +```Plain ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ ++---------------+ +|CurrentDatabase| ++---------------+ +| test| ++---------------+ +``` + +### 1.4 Viewing the Cluster Version + +**Description**: Returns the current cluster version. + +**Syntax**: + +```SQL +showVersionStatement + : SHOW VERSION + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW VERSION; +``` + +**Result**: + +```Plain ++-------+---------+ +|Version|BuildInfo| ++-------+---------+ +|2.0.1.2| 1ca4008| ++-------+---------+ +``` + +### 1.5 Viewing Cluster Key Parameters + +**Description**: Returns key parameters of the current cluster. + +**Syntax**: + +```SQL +showVariablesStatement + : SHOW VARIABLES + ; +``` + +Key Parameters: + +1. **ClusterName**: The name of the current cluster. +2. **DataReplicationFactor**: Number of data replicas per DataRegion. +3. **SchemaReplicationFactor**: Number of schema replicas per SchemaRegion. +4. **DataRegionConsensusProtocolClass**: Consensus protocol class for DataRegions. +5. **SchemaRegionConsensusProtocolClass**: Consensus protocol class for SchemaRegions. +6. **ConfigNodeConsensusProtocolClass**: Consensus protocol class for ConfigNodes. +7. **TimePartitionOrigin**: The starting timestamp of database time partitions. +8. **TimePartitionInterval**: The interval of database time partitions (in milliseconds). +9. **ReadConsistencyLevel**: The consistency level for read operations. +10. **SchemaRegionPerDataNode**: Number of SchemaRegions per DataNode. +11. **DataRegionPerDataNode**: Number of DataRegions per DataNode. +12. **SeriesSlotNum**: Number of SeriesSlots per DataRegion. +13. **SeriesSlotExecutorClass**: Implementation class for SeriesSlots. +14. **DiskSpaceWarningThreshold**: Disk space warning threshold (in percentage). +15. **TimestampPrecision**: Timestamp precision. + +**Example**: + +```SQL +IoTDB> SHOW VARIABLES; +``` + +**Result**: + +```Plain ++----------------------------------+-----------------------------------------------------------------+ +| Variable| Value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 1.6 Viewing the Cluster ID + +**Description**: Returns the ID of the current cluster. + +**Syntax**: + +```SQL +showClusterIdStatement + : SHOW (CLUSTERID | CLUSTER_ID) + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CLUSTER_ID; +``` + +**Result**: + +```Plain ++------------------------------------+ +| ClusterId| ++------------------------------------+ +|40163007-9ec1-4455-aa36-8055d740fcda| ++------------------------------------+ +``` + +### 1.7 Viewing the Timestamp of the Connected DataNode + +**Description**: Returns the current timestamp of the DataNode process directly connected to the client. + +**Syntax**: + +```SQL +showCurrentTimestampStatement + : SHOW CURRENT_TIMESTAMP + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW CURRENT_TIMESTAMP; +``` + +**Result**: + +```Plain ++-----------------------------+ +| CurrentTimestamp| ++-----------------------------+ +|2025-02-17T11:11:52.987+08:00| ++-----------------------------+ +``` + +### 1.8 Viewing Executing Queries + +**Description**: Displays information about all currently executing queries. + +> For more details on how to use system tables, please refer to [System Tables](../Reference/System-Tables.md) + +**Syntax**: + +```SQL +showQueriesStatement + : SHOW (QUERIES | QUERY PROCESSLIST) + (WHERE where=booleanExpression)? + (ORDER BY sortItem (',' sortItem)*)? + limitOffsetClause + ; +``` + +**Parameters**: + +1. **WHERE Clause**: Filters the result set based on specified conditions. +2. **ORDER BY Clause**: Sorts the result set based on specified columns. +3. **limitOffsetClause**: Limits the number of rows returned. + 1. Format: `LIMIT , `. + +**Columns in QUERIES Table**: + +- **query_id**: Unique ID of the query. +- **start_time**: Timestamp when the query started. +- **datanode_id**: ID of the DataNode executing the query. +- **elapsed_time**: Time elapsed since the query started (in seconds). +- **statement**: The SQL statement being executed. +- **user**: The user who initiated the query. + +**Example**: + +```SQL +IoTDB> SHOW QUERIES WHERE elapsed_time > 30; +``` + +**Result**: + +```Plain ++-----------------------+-----------------------------+-----------+------------+------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +``` + + +### 1.9 Viewing Region Information + +**Description**: Displays regions' information of the current cluster. + +**Syntax**: + +```SQL +showRegionsStatement + : SHOW REGIONS + ; +``` + +**Example**: + +```SQL +IoTDB> SHOW REGIONS +``` + +**Result**: + +```SQL ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | +| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| +| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +``` + + +## 2. Status Setting + +### 2.1 Setting the Connected Model + +**Description**: Sets the current SQL dialect model to `Tree` or `Table` which can be used in both tree and table models. + +**Syntax**: + +```SQL +SET SQL_DIALECT = (TABLE | TREE); +``` + +**Example**: + +```SQL +IoTDB> SET SQL_DIALECT=TABLE; +IoTDB> SHOW CURRENT_SQL_DIALECT; +``` + +**Result**: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 2.2 Updating Configuration Items + +**Description**: Updates configuration items. Changes take effect immediately without restarting if the items support hot modification. + +**Syntax**: + +```SQL +setConfigurationStatement + : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? + ; + +propertyAssignments + : property (',' property)* + ; + +property + : identifier EQ propertyValue + ; + +propertyValue + : DEFAULT + | expression + ; +``` + +**Parameters**: + +1. **propertyAssignments**: A list of properties to update. + 1. Format: `property (',' property)*`. + 2. Values: + - `DEFAULT`: Resets the configuration to its default value. + - `expression`: A specific value (must be a string). +2. **ON INTEGER_VALUE** **(Optional):** Specifies the node ID to update. + 1. If not specified or set to a negative value, updates all ConfigNodes and DataNodes. + +**Example**: + +```SQL +IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; +``` + +### 2.3 Loading Manually Modified Configuration Files + +**Description**: Loads manually modified configuration files and hot-loads the changes. Configuration items that support hot modification take effect immediately. + +**Syntax**: + +```SQL +loadConfigurationStatement + : LOAD CONFIGURATION localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode** **(Optional):** + 1. Specifies the scope of configuration loading. + 2. Default: `CLUSTER`. + 3. Values: + - `LOCAL`: Loads configuration only on the DataNode directly connected to the client. + - `CLUSTER`: Loads configuration on all DataNodes in the cluster. + +**Example**: + +```SQL +IoTDB> LOAD CONFIGURATION ON LOCAL; +``` + +### 2.4 Setting the System Status + +**Description**: Sets the system status to either `READONLY` or `RUNNING`. + +**Syntax**: + +```SQL +setSystemStatusStatement + : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **RUNNING |** **READONLY**: + 1. **RUNNING**: Sets the system to running mode, allowing both read and write operations. + 2. **READONLY**: Sets the system to read-only mode, allowing only read operations and prohibiting writes. +2. **localOrClusterMode** **(Optional):** + 1. **LOCAL**: Applies the status change only to the DataNode directly connected to the client. + 2. **CLUSTER**: Applies the status change to all DataNodes in the cluster. + 3. **Default**: `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> SET SYSTEM TO READONLY ON CLUSTER; +``` + +## 3. Data Management + +### 3.1 Flushing Data from Memory to Disk + +**Description**: Flushes data from the memory table to disk. + +**Syntax**: + +```SQL +flushStatement + : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? + ; + +booleanValue + : TRUE | FALSE + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **identifier** **(Optional):** + 1. Specifies the name of the database to flush. + 2. If not specified, all databases are flushed. + 3. **Multiple Databases**: Multiple database names can be specified, separated by commas (e.g., `FLUSH test_db1, test_db2`). +2. **booleanValue** **(****Optional****)**: + 1. Specifies the type of data to flush. + 2. **TRUE**: Flushes only the sequential memory table. + 3. **FALSE**: Flushes only the unsequential MemTable. + 4. **Default**: Flushes both sequential and unsequential memory tables. +3. **localOrClusterMode** **(****Optional****)**: + 1. **ON LOCAL**: Flushes only the memory tables on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Flushes memory tables on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> FLUSH test_db TRUE ON LOCAL; +``` + +### 3.2 Clearing Cache on DataNode + +**Description**: Clears a specific type of cache on DataNode. + +**Syntax**: + +```SQL +clearCacheStatement + : CLEAR clearCacheOptions? CACHE localOrClusterMode? + ; + +clearCacheOptions + : ATTRIBUTE + | QUERY + | ALL + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **clearCacheOptions(Optional)**: + 1. Specifies the type of cache to clear. + 2. **ATTRIBUTE**: Clears device attribute cache. + 3. **QUERY**: Clears query cache in the storage engine. + 4. **ALL**: Clears all caches, including device attribute cache, query cache, and schema cache in the tree model. + 5. **Default**: `QUERY`. +2. **localOrClusterMode(Optional)**: + 1. **ON LOCAL**: Clears cache only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Clears cache on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> CLEAR ALL CACHE ON LOCAL; +``` + +## 4. Data Repair + +### 4.1 Starting Background Scan and Repair of TsFiles + +**Description**: Starts a background task to scan and repair TsFiles, fixing issues such as timestamp disorder within data files. + +**Syntax**: + +```SQL +startRepairDataStatement + : START REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode(Optional)**: + 1. **ON LOCAL**: Executes the repair task only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Executes the repair task on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> START REPAIR DATA ON CLUSTER; +``` + +### 4.2 Pausing Background TsFile Repair Task + +**Description**: Pauses the background repair task. The paused task can be resumed by executing the `START REPAIR DATA` command again. + +**Syntax**: + +```SQL +stopRepairDataStatement + : STOP REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**Parameters**: + +1. **localOrClusterMode** **(Optional):** + 1. **ON LOCAL**: Executes the pause command only on the DataNode directly connected to the client. + 2. **ON CLUSTER**: Executes the pause command on all DataNodes in the cluster. + 3. **Default:** `ON CLUSTER`. + +**Example**: + +```SQL +IoTDB> STOP REPAIR DATA ON CLUSTER; +``` + +## 5. Query Termination + +### 5.1 Terminating Queries + +**Description**: Terminates one or more running queries. + +**Syntax**: + +```SQL +killQueryStatement + : KILL (QUERY queryId=string | ALL QUERIES) + ; +``` + +**Parameters**: + +1. **QUERY** **queryId:** Specifies the ID of the query to terminate. + +- To obtain the `queryId`, use the `SHOW QUERIES` command. + +2. **ALL QUERIES:** Terminates all currently running queries. + +**Example**: + +Terminate a specific query: + +```SQL +IoTDB> KILL QUERY 20250108_101015_00000_1; +``` + +Terminate all queries: + +```SQL +IoTDB> KILL ALL QUERIES; +``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md b/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md new file mode 100644 index 000000000..c05049f06 --- /dev/null +++ b/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md @@ -0,0 +1,582 @@ + + +# Tree-to-Table Mapping + +## 1. Functional Overview + +IoTDB introduces a tree-to-table function, which enables the creation of table views from existing tree-model data. This allows querying via table views, achieving collaborative processing of both tree and table models for the same dataset: + +* During the data writing phase, the tree-model syntax is used, supporting flexible data ingestion and expansion. +* During the data analysis phase, the table-model syntax is adopted, allowing complex data analysis through standard SQL queries. + +![](/img/tree-to-table-en-1.png) + +> * This feature supports from version V2.0.5. +> * Table views are read-only, so data cannot be written through them. + + ## 2. Feature Description +### 2.1 Creating a Table View +#### 2.1.1 Syntax Definition + +```SQL +-- create (or replace) view on tree +CREATE + [OR REPLACE] + VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) + [comment] + [RESTRICT] + [WITH properties] + AS prefixPath + +viewColumnDefinition + : column_name [dataType] TAG [comment] # tagColumn + | column_name [dataType] TIME [comment] # timeColumn + | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn + ; + +comment + : COMMENT string + ; +``` + +> Note: Columns only support tags, fields, or time; attributes are not supported. + +#### 2.1.2 Syntax Explanation +1. **`prefixPath`** + +Corresponds to the path in the tree model. The last level of the path must be `**`, and no other levels can contain `*`or `**`. This path determines the subtree corresponding to the VIEW. + +2. **`view_name`** + +The name of the view, which follows the same rules as a table name (for specific constraints, refer to [Create Table](../Basic-Concept/Table-Management.md#\_1-1-create-a-table)), e.g., `db.view`. + +3. **`viewColumnDefinition`** + +* `TAG`: Each TAG column corresponds, in order, to the path nodes at the levels following the `prefixPath`. +* `FIELD`: A FIELD column corresponds to a measurement (leaf node) in the tree model. + * If a FIELD column is specified, the column name uses the declared `column_name`. + * If `original_measurement`is declared, it maps directly to that measurement in the tree model. Otherwise, the lowercase `column_name`is used as the measurement name for mapping. + * Mapping multiple FIELD columns to the same measurement name in the tree model is not supported. + * If the `dataType`for a FIELD column is not specified, the system defaults to the data type of the mapped measurement in the tree model. + * If a device in the tree model does not contain certain declared FIELD columns, or if their data types are inconsistent with the declared FIELD columns, the value for that FIELD column will always be `NULL`when querying that device. + * If no FIELD columns are specified, the system automatically scans for all measurements under the `prefixPath`subtree (including all ordinary sequence measurements and measurements defined in any templates whose mounted paths overlap with the `prefixPath`) during creation. The column names will use the measurement names from the tree model. + * The tree model cannot have measurements with the same name (case-insensitive) but different data types. + +4. **`WITH properties`** + +Currently, only TTL is supported. It indicates that data older than TTL (in milliseconds) will not be displayed in query results, i.e., effectively `WHERE time > now() - TTL`. If a TTL is also set in the tree model, the query uses the smaller value of the two. + +> Note: The table view's TTL does not affect the actual TTL of the devices in the tree model. When data reaches the TTL set in the tree model, it will be physically deleted by the system. + +5. **`OR REPLACE`** + +A table and a view cannot have the same name. If a table with the same name already exists during creation, an error will be reported. If a view with the same name already exists, it will be replaced. + +6. **`RESTRICT`** + +This constrains the number of levels of the tree model devices that are matched (starting from the level below the `prefixPath`). If the `RESTRICT`keyword is present, only devices whose level count exactly equals the number of TAG columns are matched. Otherwise, devices whose level count is less than or equal to the number of TAG columns are matched. The default behavior is non-RESTRICT, meaning devices with a level count less than or equal to the number of TAG columns are matched. + +#### 2.1.3 Usage Example +1. Tree Model and Table View Schema + +![](/img/tree-to-table-en-2.png) + +2. Creating the Table View + +* Creation Statement: + +```SQL +CREATE OR REPLACE VIEW viewdb."wind_turbine" + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +with (ttl=604800000) +AS root.db.** +``` + +* Detailed Explanation + +This statement creates a view named `viewdb.wind_turbine`(an error will occur if `viewdb`does not exist). If the view already exists, it will be replaced. + +* It creates a table view for the time series mounted under the tree model path `root.db.**`. +* It has two `TAG` columns, `wind_turbine_group `and `wind_turbine_number`, so the table view will only include devices from the 3rd level of the original tree model. +* It has two `FIELD`columns, `voltage` and `current`. Here, these `FIELD` columns correspond to measurement names in the tree model that are also `voltage` and `current`, and only select time series of type `DOUBLE`. + +**Renaming measurement requirement:** + +If the measurement name in the tree model is `current_new`, but you want the corresponding `FIELD` column name in the table view to be `current`, the SQL should be changed as follows: + +```SQL +CREATE OR REPLACE VIEW viewdb."wind_turbine" + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD FROM current_new + ) +with (ttl=604800000) +AS root.db.** +``` + +### 2.2 Modifying a Table View +#### 2.2.1 Syntax Definition + +The ALTER VIEW function supports modifying the view name, adding columns, renaming columns, deleting columns, setting the view's TTL property, and adding comments via COMMENT. + +```SQL +-- Rename view +ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier + +-- Add a column to the view +ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition +viewColumnDefinition + : column_name [dataType] TAG # tagColumn + | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn + +-- Rename a column in the view +ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName + +-- Delete a column from the view +ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName + +-- Modify the view's TTL +ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments + +-- Add comments +COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView +COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn +``` + +#### 2.2.2 Syntax Explanation +1. The `SET PROPERTIES`operation currently only supports configuring the TTL property for the table view. +2. The `DROP COLUMN`function only supports deleting FIELD columns; TAG columns cannot be deleted. +3. Modifying the comment will overwrite the original comment. If set to `null`, the previous comment will be erased. +#### 2.2.3 Usage Examples + +```SQL +-- Rename view +ALTER VIEW IF EXISTS tableview1 RENAME TO tableview + +-- Add a column to the view +ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field + +-- Rename a column in the view +ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp + +-- Delete a column from the view +ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp + +-- Modify the view's TTL +ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 + +-- Add comments +COMMENT ON VIEW tableview IS 'Tree to Table' +COMMENT ON COLUMN tableview.status is Null +``` + +### 2.3 Deleting a Table View +#### 2.3.1 Syntax Definition + +```SQL +DROP VIEW [IF EXISTS] viewName +``` + +#### 2.3.2 Usage Example + +```SQL +DROP VIEW IF EXISTS tableview +``` + +### 2.4 Viewing Table Views +#### 2.4.1 **`Show Tables`** +1. Syntax Definition + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +2. Syntax Explanation + +The `SHOW TABLES (DETAILS)`statement displays the type information of tables or views through the `TABLE_TYPE`field in the result set: + +| Type | `TABLE_TYPE`Field Value | +| -------------------------------------------- | ----------------------------- | +| Ordinary Table(Table) | `BASE TABLE` | +| Tree-to-Table View (Tree View) | `VIEW FROM TREE` | +| System Table(Iinformation\_schema.Tables) | `SYSTEM VIEW` | + +3. Usage Examples + +```SQL +IoTDB> show tables details from database1 ++-----------+-----------+------+---------------+--------------+ +| TableName| TTL(ms)|Status| Comment| TableType| ++-----------+-----------+------+---------------+--------------+ +| tableview| INF| USING| Tree to Table |VIEW FROM TREE| +| table1|31536000000| USING| null| BASE TABLE| +| table2|31536000000| USING| null| BASE TABLE| ++-----------+-----------+------+---------------+--------------+ + +IoTDB> show tables details from information_schema ++--------------+-------+------+-------+-----------+ +| TableName|TTL(ms)|Status|Comment| TableType| ++--------------+-------+------+-------+-----------+ +| columns| INF| USING| null|SYSTEM VIEW| +| config_nodes| INF| USING| null|SYSTEM VIEW| +|configurations| INF| USING| null|SYSTEM VIEW| +| data_nodes| INF| USING| null|SYSTEM VIEW| +| databases| INF| USING| null|SYSTEM VIEW| +| functions| INF| USING| null|SYSTEM VIEW| +| keywords| INF| USING| null|SYSTEM VIEW| +| models| INF| USING| null|SYSTEM VIEW| +| nodes| INF| USING| null|SYSTEM VIEW| +| pipe_plugins| INF| USING| null|SYSTEM VIEW| +| pipes| INF| USING| null|SYSTEM VIEW| +| queries| INF| USING| null|SYSTEM VIEW| +| regions| INF| USING| null|SYSTEM VIEW| +| subscriptions| INF| USING| null|SYSTEM VIEW| +| tables| INF| USING| null|SYSTEM VIEW| +| topics| INF| USING| null|SYSTEM VIEW| +| views| INF| USING| null|SYSTEM VIEW| ++--------------+-------+------+-------+-----------+ +``` + +#### 2.4.2 **`Show Create Table/View`** +1. Syntax Definition + +```SQL +SHOW CREATE TABLE|VIEW viewname; +``` + +2. Syntax Explanation + +* The `SHOW CREATE TABLE`statement can be used to display the complete creation information for ordinary tables or views. +* The `SHOW CREATE VIEW`statement can only be used to display the complete creation information for views. +* Neither statement can be used to display system tables. + +3. Usage Examples + +```SQL +IoTDB> show create table tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +IoTDB> show create view tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +``` + +### 2.5 Query Differences Between Non-aligned and Aligned Devices + +Queries on tree-to-table views may yield different results compared to equivalent tree model `ALIGN BY DEVICE`queries when dealing with null values in aligned and non-aligned devices. + +* Aligned Devices + * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. + * Table View Query Behavior:Consistent with the table model, rows where all selected fields are null are retained. +* Non-aligned Devices + * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. + * Table View Query Behavior:Consistent with the tree model, rows where all selected fields are null are not retained. +* Explanation Example + * Aligned + + ```SQL + -- Write data in tree model (aligned) + CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) + + -- Create VIEW statement + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- Query + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + | null| + +-------+ + Total line number = 2 + ``` + + * Non-aligned + + ```SQL + -- Write data in tree model (non-aligned) + CREATE TIMESERIES root.db.battery.b1.voltage INT32 + CREATE TIMESERIES root.db.battery.b1.current FLOAT + INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) + + -- Create VIEW statement + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- Query + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + +-------+ + Total line number = 1 + + -- Can only ensure all rows are retrieved if the query specifies all FIELD columns, or only non-FIELD columns + IoTDB> select voltage,current from view1 + +-------+-------+ + |voltage|current| + +-------+-------+ + | 1| 1.0| + | null| 1.0| + +-------+-------+ + Total line number = 2 + + IoTDB> select battery_id from view1 + +-----------+ + |battery_id| + +-----------+ + | b1| + | b1| + +-----------+ + Total line number = 2 + + -- If the query involves only some FIELD columns, the final number of rows depends on the number of rows after aligning the specified FIELD columns by timestamp. + IoTDB> select time,voltage from view1 + +-----------------------------+-------+ + | time|voltage| + +-----------------------------+-------+ + |1970-01-01T08:00:00.001+08:00| 1| + +-----------------------------+-------+ + Total line number = 1 + ``` + +## 3. Scenario Examples +### 3.1 Managing Multiple Device Types in the Original Tree Model + +* The scenario involves managing different types of devices, each with its own hierarchical path and set of measurements. +* During Data Writing: Create branches under the database node according to device type. Each device type can have a different measurement structure. +* During Querying: Create a separate table for each device type. Each table will have different tags and sets of measurements. + +![](/img/tree-to-table-en-3.png) + +**SQL for Creating a Table View:** + +```SQL +-- Wind Turbine Table +CREATE VIEW viewdb.wind_turbine + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +AS root.db.wind_turbine.** + +-- Motor Table +CREATE VIEW viewdb.motor + ( motor_group String TAG, + motor_number String TAG, + power FLOAT FIELD, + electricity FLOAT FIELD, + temperature FLOAT FIELD + ) +AS root.db.motor.** +``` + +### 3.2 Original Tree Model Contains Only Measurements, No Devices + +This scenario occurs in systems like station monitoring where each measurement has a unique identifier but cannot be mapped to specific physical devices. + +> Wide Table Form + +![](/img/tree-to-table-en-4.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine + (DCS_PIT_02105A DOUBLE FIELD, + DCS_PIT_02105B DOUBLE FIELD, + DCS_PIT_02105C DOUBLE FIELD, + ... + DCS_XI_02716A DOUBLE FIELD + ) +AS root.db.** +``` + +### 3.3 Original Tree Model Where a Device Has Both Sub-devices and Measurements + +This scenario is common in energy storage systems where each hierarchical level requires monitoring of parameters like voltage and current. + +* Writing Phase: Model according to physical monitoring points at each hierarchical level +* Querying Phase: Create multiple tables based on device categories to manage information at each structural level + +![](/img/tree-to-table-en-5.png) + +**SQL for Creating a Table View:** + +```SQL +-- Battery Compartment +CREATE VIEW viewdb.battery_compartment + (station String TAG, + batter_compartment String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- Battery Stack +CREATE VIEW viewdb.battery_stack + (station String TAG, + batter_compartment String TAG, + battery_stack String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- Battery Cluster +CREATE VIEW viewdb.battery_cluster + (station String TAG, + batter_compartment String TAG, + battery_stackString TAG, + battery_cluster String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS 'root.db.**' + +-- Battery Ceil +CREATE VIEW viewdb.battery_ceil + (station String TAG, + batter_compartment String TAG, + battery_cluster String TAG, + battery_cluster String TAG, + battery_ceil String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** +``` + +### 3.4 Original Tree Model Where a Device Has Only One Measurement Under It + +> Narrow Table Form + +#### 3.4.1 All Measurements Have the Same Data Type + +![](/img/tree-to-table-en-6.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** +``` + +#### 3.4.2 Measurements Have Different Data Types +##### 3.4.2.1 Create a Narrow Table View for Each Data Type of Measurement + +**Advantage: ​**The number of table views is constant, only related to the data types in the system. + +**Disadvantage: ​**When querying the value of a specific measurement, its data type must be known in advance to determine which table view to query. + +![](/img/tree-to-table-en-7.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine_float + ( + sensor_id STRING TAG, + value FLOAT FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_double + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int32 + ( + sensor_id STRING TAG, + value INT32 FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int64 + ( + sensor_id STRING TAG, + value INT64 FIELD + ) +AS root.db.** + +... +``` + +##### 3.4.2.2 Create a Table for Each Measurement + +**Advantage: ​**When querying the value of a specific measurement, there's no need to first check its data type to determine which table to query, making the process simple and convenient. + +**Disadvantage: ​**When there are a large number of measurements, it will introduce too many table views, requiring the writing of a large number of view creation statements. + +![](/img/tree-to-table-en-8.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.DCS_PIT_02105A + ( + value FLOAT FIELD + ) +AS root.db.DCS_PIT_02105A.** + +CREATE VIEW viewdb.DCS_PIT_02105B + ( + value DOUBLE FIELD + ) +AS root.db.DCS_PIT_02105B.** + +CREATE VIEW viewdb.DCS_XI_02716A + ( + value INT64 FIELD + ) +AS root.db.DCS_XI_02716A.** + +...... +``` diff --git a/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md b/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md new file mode 100644 index 000000000..c05049f06 --- /dev/null +++ b/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md @@ -0,0 +1,582 @@ + + +# Tree-to-Table Mapping + +## 1. Functional Overview + +IoTDB introduces a tree-to-table function, which enables the creation of table views from existing tree-model data. This allows querying via table views, achieving collaborative processing of both tree and table models for the same dataset: + +* During the data writing phase, the tree-model syntax is used, supporting flexible data ingestion and expansion. +* During the data analysis phase, the table-model syntax is adopted, allowing complex data analysis through standard SQL queries. + +![](/img/tree-to-table-en-1.png) + +> * This feature supports from version V2.0.5. +> * Table views are read-only, so data cannot be written through them. + + ## 2. Feature Description +### 2.1 Creating a Table View +#### 2.1.1 Syntax Definition + +```SQL +-- create (or replace) view on tree +CREATE + [OR REPLACE] + VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) + [comment] + [RESTRICT] + [WITH properties] + AS prefixPath + +viewColumnDefinition + : column_name [dataType] TAG [comment] # tagColumn + | column_name [dataType] TIME [comment] # timeColumn + | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn + ; + +comment + : COMMENT string + ; +``` + +> Note: Columns only support tags, fields, or time; attributes are not supported. + +#### 2.1.2 Syntax Explanation +1. **`prefixPath`** + +Corresponds to the path in the tree model. The last level of the path must be `**`, and no other levels can contain `*`or `**`. This path determines the subtree corresponding to the VIEW. + +2. **`view_name`** + +The name of the view, which follows the same rules as a table name (for specific constraints, refer to [Create Table](../Basic-Concept/Table-Management.md#\_1-1-create-a-table)), e.g., `db.view`. + +3. **`viewColumnDefinition`** + +* `TAG`: Each TAG column corresponds, in order, to the path nodes at the levels following the `prefixPath`. +* `FIELD`: A FIELD column corresponds to a measurement (leaf node) in the tree model. + * If a FIELD column is specified, the column name uses the declared `column_name`. + * If `original_measurement`is declared, it maps directly to that measurement in the tree model. Otherwise, the lowercase `column_name`is used as the measurement name for mapping. + * Mapping multiple FIELD columns to the same measurement name in the tree model is not supported. + * If the `dataType`for a FIELD column is not specified, the system defaults to the data type of the mapped measurement in the tree model. + * If a device in the tree model does not contain certain declared FIELD columns, or if their data types are inconsistent with the declared FIELD columns, the value for that FIELD column will always be `NULL`when querying that device. + * If no FIELD columns are specified, the system automatically scans for all measurements under the `prefixPath`subtree (including all ordinary sequence measurements and measurements defined in any templates whose mounted paths overlap with the `prefixPath`) during creation. The column names will use the measurement names from the tree model. + * The tree model cannot have measurements with the same name (case-insensitive) but different data types. + +4. **`WITH properties`** + +Currently, only TTL is supported. It indicates that data older than TTL (in milliseconds) will not be displayed in query results, i.e., effectively `WHERE time > now() - TTL`. If a TTL is also set in the tree model, the query uses the smaller value of the two. + +> Note: The table view's TTL does not affect the actual TTL of the devices in the tree model. When data reaches the TTL set in the tree model, it will be physically deleted by the system. + +5. **`OR REPLACE`** + +A table and a view cannot have the same name. If a table with the same name already exists during creation, an error will be reported. If a view with the same name already exists, it will be replaced. + +6. **`RESTRICT`** + +This constrains the number of levels of the tree model devices that are matched (starting from the level below the `prefixPath`). If the `RESTRICT`keyword is present, only devices whose level count exactly equals the number of TAG columns are matched. Otherwise, devices whose level count is less than or equal to the number of TAG columns are matched. The default behavior is non-RESTRICT, meaning devices with a level count less than or equal to the number of TAG columns are matched. + +#### 2.1.3 Usage Example +1. Tree Model and Table View Schema + +![](/img/tree-to-table-en-2.png) + +2. Creating the Table View + +* Creation Statement: + +```SQL +CREATE OR REPLACE VIEW viewdb."wind_turbine" + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +with (ttl=604800000) +AS root.db.** +``` + +* Detailed Explanation + +This statement creates a view named `viewdb.wind_turbine`(an error will occur if `viewdb`does not exist). If the view already exists, it will be replaced. + +* It creates a table view for the time series mounted under the tree model path `root.db.**`. +* It has two `TAG` columns, `wind_turbine_group `and `wind_turbine_number`, so the table view will only include devices from the 3rd level of the original tree model. +* It has two `FIELD`columns, `voltage` and `current`. Here, these `FIELD` columns correspond to measurement names in the tree model that are also `voltage` and `current`, and only select time series of type `DOUBLE`. + +**Renaming measurement requirement:** + +If the measurement name in the tree model is `current_new`, but you want the corresponding `FIELD` column name in the table view to be `current`, the SQL should be changed as follows: + +```SQL +CREATE OR REPLACE VIEW viewdb."wind_turbine" + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD FROM current_new + ) +with (ttl=604800000) +AS root.db.** +``` + +### 2.2 Modifying a Table View +#### 2.2.1 Syntax Definition + +The ALTER VIEW function supports modifying the view name, adding columns, renaming columns, deleting columns, setting the view's TTL property, and adding comments via COMMENT. + +```SQL +-- Rename view +ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier + +-- Add a column to the view +ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition +viewColumnDefinition + : column_name [dataType] TAG # tagColumn + | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn + +-- Rename a column in the view +ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName + +-- Delete a column from the view +ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName + +-- Modify the view's TTL +ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments + +-- Add comments +COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView +COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn +``` + +#### 2.2.2 Syntax Explanation +1. The `SET PROPERTIES`operation currently only supports configuring the TTL property for the table view. +2. The `DROP COLUMN`function only supports deleting FIELD columns; TAG columns cannot be deleted. +3. Modifying the comment will overwrite the original comment. If set to `null`, the previous comment will be erased. +#### 2.2.3 Usage Examples + +```SQL +-- Rename view +ALTER VIEW IF EXISTS tableview1 RENAME TO tableview + +-- Add a column to the view +ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field + +-- Rename a column in the view +ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp + +-- Delete a column from the view +ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp + +-- Modify the view's TTL +ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 + +-- Add comments +COMMENT ON VIEW tableview IS 'Tree to Table' +COMMENT ON COLUMN tableview.status is Null +``` + +### 2.3 Deleting a Table View +#### 2.3.1 Syntax Definition + +```SQL +DROP VIEW [IF EXISTS] viewName +``` + +#### 2.3.2 Usage Example + +```SQL +DROP VIEW IF EXISTS tableview +``` + +### 2.4 Viewing Table Views +#### 2.4.1 **`Show Tables`** +1. Syntax Definition + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +2. Syntax Explanation + +The `SHOW TABLES (DETAILS)`statement displays the type information of tables or views through the `TABLE_TYPE`field in the result set: + +| Type | `TABLE_TYPE`Field Value | +| -------------------------------------------- | ----------------------------- | +| Ordinary Table(Table) | `BASE TABLE` | +| Tree-to-Table View (Tree View) | `VIEW FROM TREE` | +| System Table(Iinformation\_schema.Tables) | `SYSTEM VIEW` | + +3. Usage Examples + +```SQL +IoTDB> show tables details from database1 ++-----------+-----------+------+---------------+--------------+ +| TableName| TTL(ms)|Status| Comment| TableType| ++-----------+-----------+------+---------------+--------------+ +| tableview| INF| USING| Tree to Table |VIEW FROM TREE| +| table1|31536000000| USING| null| BASE TABLE| +| table2|31536000000| USING| null| BASE TABLE| ++-----------+-----------+------+---------------+--------------+ + +IoTDB> show tables details from information_schema ++--------------+-------+------+-------+-----------+ +| TableName|TTL(ms)|Status|Comment| TableType| ++--------------+-------+------+-------+-----------+ +| columns| INF| USING| null|SYSTEM VIEW| +| config_nodes| INF| USING| null|SYSTEM VIEW| +|configurations| INF| USING| null|SYSTEM VIEW| +| data_nodes| INF| USING| null|SYSTEM VIEW| +| databases| INF| USING| null|SYSTEM VIEW| +| functions| INF| USING| null|SYSTEM VIEW| +| keywords| INF| USING| null|SYSTEM VIEW| +| models| INF| USING| null|SYSTEM VIEW| +| nodes| INF| USING| null|SYSTEM VIEW| +| pipe_plugins| INF| USING| null|SYSTEM VIEW| +| pipes| INF| USING| null|SYSTEM VIEW| +| queries| INF| USING| null|SYSTEM VIEW| +| regions| INF| USING| null|SYSTEM VIEW| +| subscriptions| INF| USING| null|SYSTEM VIEW| +| tables| INF| USING| null|SYSTEM VIEW| +| topics| INF| USING| null|SYSTEM VIEW| +| views| INF| USING| null|SYSTEM VIEW| ++--------------+-------+------+-------+-----------+ +``` + +#### 2.4.2 **`Show Create Table/View`** +1. Syntax Definition + +```SQL +SHOW CREATE TABLE|VIEW viewname; +``` + +2. Syntax Explanation + +* The `SHOW CREATE TABLE`statement can be used to display the complete creation information for ordinary tables or views. +* The `SHOW CREATE VIEW`statement can only be used to display the complete creation information for views. +* Neither statement can be used to display system tables. + +3. Usage Examples + +```SQL +IoTDB> show create table tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +IoTDB> show create view tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +``` + +### 2.5 Query Differences Between Non-aligned and Aligned Devices + +Queries on tree-to-table views may yield different results compared to equivalent tree model `ALIGN BY DEVICE`queries when dealing with null values in aligned and non-aligned devices. + +* Aligned Devices + * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. + * Table View Query Behavior:Consistent with the table model, rows where all selected fields are null are retained. +* Non-aligned Devices + * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. + * Table View Query Behavior:Consistent with the tree model, rows where all selected fields are null are not retained. +* Explanation Example + * Aligned + + ```SQL + -- Write data in tree model (aligned) + CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) + + -- Create VIEW statement + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- Query + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + | null| + +-------+ + Total line number = 2 + ``` + + * Non-aligned + + ```SQL + -- Write data in tree model (non-aligned) + CREATE TIMESERIES root.db.battery.b1.voltage INT32 + CREATE TIMESERIES root.db.battery.b1.current FLOAT + INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) + + -- Create VIEW statement + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- Query + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + +-------+ + Total line number = 1 + + -- Can only ensure all rows are retrieved if the query specifies all FIELD columns, or only non-FIELD columns + IoTDB> select voltage,current from view1 + +-------+-------+ + |voltage|current| + +-------+-------+ + | 1| 1.0| + | null| 1.0| + +-------+-------+ + Total line number = 2 + + IoTDB> select battery_id from view1 + +-----------+ + |battery_id| + +-----------+ + | b1| + | b1| + +-----------+ + Total line number = 2 + + -- If the query involves only some FIELD columns, the final number of rows depends on the number of rows after aligning the specified FIELD columns by timestamp. + IoTDB> select time,voltage from view1 + +-----------------------------+-------+ + | time|voltage| + +-----------------------------+-------+ + |1970-01-01T08:00:00.001+08:00| 1| + +-----------------------------+-------+ + Total line number = 1 + ``` + +## 3. Scenario Examples +### 3.1 Managing Multiple Device Types in the Original Tree Model + +* The scenario involves managing different types of devices, each with its own hierarchical path and set of measurements. +* During Data Writing: Create branches under the database node according to device type. Each device type can have a different measurement structure. +* During Querying: Create a separate table for each device type. Each table will have different tags and sets of measurements. + +![](/img/tree-to-table-en-3.png) + +**SQL for Creating a Table View:** + +```SQL +-- Wind Turbine Table +CREATE VIEW viewdb.wind_turbine + (wind_turbine_group String TAG, + wind_turbine_number String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +AS root.db.wind_turbine.** + +-- Motor Table +CREATE VIEW viewdb.motor + ( motor_group String TAG, + motor_number String TAG, + power FLOAT FIELD, + electricity FLOAT FIELD, + temperature FLOAT FIELD + ) +AS root.db.motor.** +``` + +### 3.2 Original Tree Model Contains Only Measurements, No Devices + +This scenario occurs in systems like station monitoring where each measurement has a unique identifier but cannot be mapped to specific physical devices. + +> Wide Table Form + +![](/img/tree-to-table-en-4.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine + (DCS_PIT_02105A DOUBLE FIELD, + DCS_PIT_02105B DOUBLE FIELD, + DCS_PIT_02105C DOUBLE FIELD, + ... + DCS_XI_02716A DOUBLE FIELD + ) +AS root.db.** +``` + +### 3.3 Original Tree Model Where a Device Has Both Sub-devices and Measurements + +This scenario is common in energy storage systems where each hierarchical level requires monitoring of parameters like voltage and current. + +* Writing Phase: Model according to physical monitoring points at each hierarchical level +* Querying Phase: Create multiple tables based on device categories to manage information at each structural level + +![](/img/tree-to-table-en-5.png) + +**SQL for Creating a Table View:** + +```SQL +-- Battery Compartment +CREATE VIEW viewdb.battery_compartment + (station String TAG, + batter_compartment String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- Battery Stack +CREATE VIEW viewdb.battery_stack + (station String TAG, + batter_compartment String TAG, + battery_stack String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- Battery Cluster +CREATE VIEW viewdb.battery_cluster + (station String TAG, + batter_compartment String TAG, + battery_stackString TAG, + battery_cluster String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS 'root.db.**' + +-- Battery Ceil +CREATE VIEW viewdb.battery_ceil + (station String TAG, + batter_compartment String TAG, + battery_cluster String TAG, + battery_cluster String TAG, + battery_ceil String TAG, + voltage DOUBLE FIELD, + current DOUBLE FIELD + ) +RESTRICT +AS root.db.** +``` + +### 3.4 Original Tree Model Where a Device Has Only One Measurement Under It + +> Narrow Table Form + +#### 3.4.1 All Measurements Have the Same Data Type + +![](/img/tree-to-table-en-6.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** +``` + +#### 3.4.2 Measurements Have Different Data Types +##### 3.4.2.1 Create a Narrow Table View for Each Data Type of Measurement + +**Advantage: ​**The number of table views is constant, only related to the data types in the system. + +**Disadvantage: ​**When querying the value of a specific measurement, its data type must be known in advance to determine which table view to query. + +![](/img/tree-to-table-en-7.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.machine_float + ( + sensor_id STRING TAG, + value FLOAT FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_double + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int32 + ( + sensor_id STRING TAG, + value INT32 FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int64 + ( + sensor_id STRING TAG, + value INT64 FIELD + ) +AS root.db.** + +... +``` + +##### 3.4.2.2 Create a Table for Each Measurement + +**Advantage: ​**When querying the value of a specific measurement, there's no need to first check its data type to determine which table to query, making the process simple and convenient. + +**Disadvantage: ​**When there are a large number of measurements, it will introduce too many table views, requiring the writing of a large number of view creation statements. + +![](/img/tree-to-table-en-8.png) + +**SQL for Creating a Table View:** + +```SQL +CREATE VIEW viewdb.DCS_PIT_02105A + ( + value FLOAT FIELD + ) +AS root.db.DCS_PIT_02105A.** + +CREATE VIEW viewdb.DCS_PIT_02105B + ( + value DOUBLE FIELD + ) +AS root.db.DCS_PIT_02105B.** + +CREATE VIEW viewdb.DCS_XI_02716A + ( + value INT64 FIELD + ) +AS root.db.DCS_XI_02716A.** + +...... +``` diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md new file mode 100644 index 000000000..eede4d4ca --- /dev/null +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md @@ -0,0 +1,191 @@ + + +# 数据库管理 + +## 1. 数据库管理 + +### 1.1 创建数据库 + +用于创建数据库。 + +**语法:** + +```SQL + CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +**说明:** + +1. 数据库名称,具有以下特性: + - 大小写不敏感,创建成功后,统一显示为小写 + - 名称的长度不得超过 64 个字符。 + - 名称中包含下划线(_)、数字(非开头)、英文字母可以直接创建 + - 名称中包含特殊字符(如`)、中文字符、数字开头时,必须用双引号 "" 括起来。 + +2. WITH properties 子句可配置如下属性: + +> 注:属性的大小写不敏感,有关详细信息[大小写敏感规则](../SQL-Manual/Identifier.md#大小写敏感性)。 + +| 属性 | 含义 | 默认值 | +| ------------------------- | ---------------------------------------- | --------- | +| `TTL` | 数据自动过期删除,单位 ms | INF | +| `TIME_PARTITION_INTERVAL` | 数据库的时间分区间隔,单位 ms | 604800000 | +| `SCHEMA_REGION_GROUP_NUM` | 数据库的元数据副本组数量,一般不需要修改 | 1 | +| `DATA_REGION_GROUP_NUM` | 数据库的数据副本组数量,一般不需要修改 | 2 | + +**示例:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +// 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 使用数据库 + +用于指定当前数据库作为表的命名空间。 + +**语法:** + +```SQL +USE +``` + +**示例:** + +```SQL +USE database1 +``` + +### 1.3 查看当前数据库 + +返回当前会话所连接的数据库名称,若未执行过 `use`语句指定数据库,则默认为 `null`。 + +**语法:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**示例:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 查看所有数据库 + +用于查看所有数据库和数据库的属性信息。 + +**语法:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +**语句返回列含义如下:** + +| 列名 | 含义 | +| ----------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| database | database名称。 | +| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management_apache.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management_apache.md#14-修改表) 来设置或更新表的TTL时间。 | +| SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | +| DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | +| TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | +| SchemaRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的元数据副本组数量,一般不需要修改 | +| DataRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的数据副本组数量,一般不需要修改 | + +**示例:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 修改数据库 + +用于修改数据库中的部分属性。 + +**语法:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**说明:** + +1. `ALTER DATABASE`操作目前仅支持对数据库的`SCHEMA_REGION_GROUP_NUM`、`DATA_REGION_GROUP_NUM`以及`TTL`属性进行修改。 + +**示例:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 删除数据库 + +用于删除数据库。 + +**语法:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**说明:** + +1. 数据库已被设置为当前使用(use)的数据库,仍然可以被删除(drop)。 +2. 删除数据库将导致所选数据库及其内所有表连同其存储的数据一并被删除。 + +**示例:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md new file mode 100644 index 000000000..0c5b5c5da --- /dev/null +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md @@ -0,0 +1,191 @@ + + +# 数据库管理 + +## 1. 数据库管理 + +### 1.1 创建数据库 + +用于创建数据库。 + +**语法:** + +```SQL + CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +**说明:** + +1. 数据库名称,具有以下特性: + - 大小写不敏感,创建成功后,统一显示为小写 + - 名称的长度不得超过 64 个字符。 + - 名称中包含下划线(_)、数字(非开头)、英文字母可以直接创建 + - 名称中包含特殊字符(如`)、中文字符、数字开头时,必须用双引号 "" 括起来。 + +2. WITH properties 子句可配置如下属性: + +> 注:属性的大小写不敏感,有关详细信息[大小写敏感规则](../SQL-Manual/Identifier.md#大小写敏感性)。 + +| 属性 | 含义 | 默认值 | +| ------------------------- | ---------------------------------------- | --------- | +| `TTL` | 数据自动过期删除,单位 ms | INF | +| `TIME_PARTITION_INTERVAL` | 数据库的时间分区间隔,单位 ms | 604800000 | +| `SCHEMA_REGION_GROUP_NUM` | 数据库的元数据副本组数量,一般不需要修改 | 1 | +| `DATA_REGION_GROUP_NUM` | 数据库的数据副本组数量,一般不需要修改 | 2 | + +**示例:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +// 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 使用数据库 + +用于指定当前数据库作为表的命名空间。 + +**语法:** + +```SQL +USE +``` + +**示例:** + +```SQL +USE database1 +``` + +### 1.3 查看当前数据库 + +返回当前会话所连接的数据库名称,若未执行过 `use`语句指定数据库,则默认为 `null`。 + +**语法:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**示例:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 查看所有数据库 + +用于查看所有数据库和数据库的属性信息。 + +**语法:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +**语句返回列含义如下:** + +| 列名 | 含义 | +| ----------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| database | database名称。 | +| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management_timecho.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management_timecho.md#14-修改表) 来设置或更新表的TTL时间。 | +| SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | +| DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | +| TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | +| SchemaRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的元数据副本组数量,一般不需要修改 | +| DataRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的数据副本组数量,一般不需要修改 | + +**示例:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 修改数据库 + +用于修改数据库中的部分属性。 + +**语法:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**说明:** + +1. `ALTER DATABASE`操作目前仅支持对数据库的`SCHEMA_REGION_GROUP_NUM`、`DATA_REGION_GROUP_NUM`以及`TTL`属性进行修改。 + +**示例:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 删除数据库 + +用于删除数据库。 + +**语法:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**说明:** + +1. 数据库已被设置为当前使用(use)的数据库,仍然可以被删除(drop)。 +2. 删除数据库将导致所选数据库及其内所有表连同其存储的数据一并被删除。 + +**示例:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md b/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md new file mode 100644 index 000000000..77b59ba13 --- /dev/null +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md @@ -0,0 +1,141 @@ + + +# 数据保留时间 + +## 1. 概览 + +IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系统自动定期删除旧数据,以有效控制磁盘空间并维护高性能查询和低内存占用。TTL默认以毫秒为单位,数据过期后不可查询且禁止写入,但物理删除会延迟至压缩时。需注意,TTL变更可能导致短暂数据可查询性变化。 + +**注意事项:** + +1. TTL设置为毫秒,不受配置文件时间精度影响。 +2. TTL变更可能影响数据的可查询性。 +3. 系统最终会移除过期数据,但存在延迟。 +4. TTL 判断数据是否过期依据的是数据点时间,非写入时间。 + +## 2. 设置 TTL + +在表模型中,IoTDB 的 TTL 是按照表的粒度生效的。可以直接在表上设置 TTL,或者在数据库级别设置 TTL。当在数据库级别设置了TTL时,在创建新表的过程中,系统会自动采用这个TTL值作为新表的默认设置,但每个表仍然可以独立地被设置或覆盖该值。 + +注意,如果数据库级别的TTL被修改,不会直接影响到已经存在的表的TTL设置。 + +### 2.1 为表设置 TTL + +如果在建表时通过sql语句设置了表的 TTL,则会以表的ttl为准。建表语句详情可见:[表管理](../Basic-Concept/Table-Management_apache.md) + +示例1:创建表时设置 TTL + +```SQL +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600) +``` + +示例2:更改表语句设置TTL: + +```SQL +ALTER TABLE tableB SET PROPERTIES TTL=3600; +``` + +示例3:不指定TTL或设为默认值,它将与数据库的TTL相同,默认情况下是'INF'(无穷大): + +```SQL +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT) +CREATE TABLE test3 ("场站" string id, "温度" int32) +ALTER TABLE tableB set properties TTL=DEFAULT +``` + +### 2.2 为数据库设置 TTL + +没有设置表的TTL,则会继承database的ttl。建数据库语句详情可见:[数据库管理](../Basic-Concept/Database-Management_apache.md) + +示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) +``` + +示例5:数据库不设置ttl,将生成一个没有ttl的表: + +```SQL +CREATE DATABASE db +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) +``` + +示例6:数据库设置了ttl,但想显式设置没有TTL的表,可以将TTL设置为'INF': + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') +``` + +## 3. 取消 TTL + +取消 TTL 设置,可以修改表的 TTL 设置为 'INF'。目前,IoTDB 不支持修改数据库的 TTL。 + +```SQL +ALTER TABLE tableB set properties TTL='INF' +``` + +## 4. 查看 TTL 信息 + +使用 "SHOW DATABASES" 和 "SHOW TABLES" 命令可以直接显示数据库和表的 TTL 详情。数据库和表管理语句详情可见:[数据库管理](../Basic-Concept/Database-Management_apache.md)、[表管理](../Basic-Concept/Table-Management_apache.md) + +> 注意,树模型数据库的TTL也将显示。 + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 1| 3| 100000| +| test2| 300| 1| 1| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +|test_prop| 300| 1| 3| 100000|TABLE| +| test2| 300| 1| 1| 604800000| TREE| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +IoTDB> show tables ++---------+-------+ +|TableName|TTL(ms)| ++---------+-------+ +| grass| 1000| +| bamboo| 300| +| flower| INF| ++---------+-------+ + +IoTDB> show tables details ++---------+-------+----------+ +|TableName|TTL(ms)| Status| ++---------+-------+----------+ +| bean| 300|PRE_CREATE| +| grass| 1000| USING| +| bamboo| 300| USING| +| flower| INF| USING| ++---------+-------+----------+ +``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md b/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md new file mode 100644 index 000000000..6c145ef83 --- /dev/null +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md @@ -0,0 +1,141 @@ + + +# 数据保留时间 + +## 1. 概览 + +IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系统自动定期删除旧数据,以有效控制磁盘空间并维护高性能查询和低内存占用。TTL默认以毫秒为单位,数据过期后不可查询且禁止写入,但物理删除会延迟至压缩时。需注意,TTL变更可能导致短暂数据可查询性变化。 + +**注意事项:** + +1. TTL设置为毫秒,不受配置文件时间精度影响。 +2. TTL变更可能影响数据的可查询性。 +3. 系统最终会移除过期数据,但存在延迟。 +4. TTL 判断数据是否过期依据的是数据点时间,非写入时间。 + +## 2. 设置 TTL + +在表模型中,IoTDB 的 TTL 是按照表的粒度生效的。可以直接在表上设置 TTL,或者在数据库级别设置 TTL。当在数据库级别设置了TTL时,在创建新表的过程中,系统会自动采用这个TTL值作为新表的默认设置,但每个表仍然可以独立地被设置或覆盖该值。 + +注意,如果数据库级别的TTL被修改,不会直接影响到已经存在的表的TTL设置。 + +### 2.1 为表设置 TTL + +如果在建表时通过sql语句设置了表的 TTL,则会以表的ttl为准。建表语句详情可见:[表管理](../Basic-Concept/Table-Management_timecho.md) + +示例1:创建表时设置 TTL + +```SQL +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600) +``` + +示例2:更改表语句设置TTL: + +```SQL +ALTER TABLE tableB SET PROPERTIES TTL=3600; +``` + +示例3:不指定TTL或设为默认值,它将与数据库的TTL相同,默认情况下是'INF'(无穷大): + +```SQL +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT) +CREATE TABLE test3 ("场站" string id, "温度" int32) +ALTER TABLE tableB set properties TTL=DEFAULT +``` + +### 2.2 为数据库设置 TTL + +没有设置表的TTL,则会继承database的ttl。建数据库语句详情可见:[数据库管理](../Basic-Concept/Database-Management_timecho.md) + +示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) +``` + +示例5:数据库不设置ttl,将生成一个没有ttl的表: + +```SQL +CREATE DATABASE db +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) +``` + +示例6:数据库设置了ttl,但想显式设置没有TTL的表,可以将TTL设置为'INF': + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') +``` + +## 3. 取消 TTL + +取消 TTL 设置,可以修改表的 TTL 设置为 'INF'。目前,IoTDB 不支持修改数据库的 TTL。 + +```SQL +ALTER TABLE tableB set properties TTL='INF' +``` + +## 4. 查看 TTL 信息 + +使用 "SHOW DATABASES" 和 "SHOW TABLES" 命令可以直接显示数据库和表的 TTL 详情。数据库和表管理语句详情可见:[数据库管理](../Basic-Concept/Database-Management_timecho.md)、[表管理](../Basic-Concept/Table-Management_timecho.md) + +> 注意,树模型数据库的TTL也将显示。 + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 1| 3| 100000| +| test2| 300| 1| 1| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +|test_prop| 300| 1| 3| 100000|TABLE| +| test2| 300| 1| 1| 604800000| TREE| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +IoTDB> show tables ++---------+-------+ +|TableName|TTL(ms)| ++---------+-------+ +| grass| 1000| +| bamboo| 300| +| flower| INF| ++---------+-------+ + +IoTDB> show tables details ++---------+-------+----------+ +|TableName|TTL(ms)| Status| ++---------+-------+----------+ +| bean| 300|PRE_CREATE| +| grass| 1000| USING| +| bamboo| 300| USING| +| flower| INF| USING| ++---------+-------+----------+ +``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management.md index 2e194df99..314991c13 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management.md @@ -21,6 +21,10 @@ # 表管理 +在开始使用表管理功能前,推荐您先了解以下相关预备知识,以便更好地理解和应用表管理功能: +* [时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md):了解时序数据的基本概念与特点,帮助建立建模基础。 +* [建模方案设计](../Background-knowledge/Data-Model-and-Terminology_timecho.md):掌握 IoTDB 时序模型及适用场景,为表管理提供设计基础。 + ## 1. 表管理 ### 1.1 创建表 @@ -69,7 +73,7 @@ comment - 大小写不敏感,创建成功后,统一显示为小写 - 名称可包含特殊字符,如 `~!`"%` 等 - 包含特殊字符或中文字符的表名创建时必须用双引号 "" 括起来。 - - 注意:SQL中特殊字符或中文表名需加双引号。原生API中无需额外添加,否则表名会包含引号字符。 + - 注意:SQL中特殊字符或中文表名需加双引号。原生API中无需额外添加,否则表名会包含引号字符。 - 当为表命名时,最外层的双引号(`""`)不会在实际创建的表名中出现。 - ```SQL diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md new file mode 100644 index 000000000..3c3dc8d6e --- /dev/null +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md @@ -0,0 +1,315 @@ + + +# 表管理 + +在开始使用表管理功能前,推荐您先了解以下相关预备知识,以便更好地理解和应用表管理功能: +* [时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md):了解时序数据的基本概念与特点,帮助建立建模基础。 +* [建模方案设计](../Background-knowledge/Data-Model-and-Terminology_apache.md):掌握 IoTDB 时序模型及适用场景,为表管理提供设计基础。 + +## 1. 表管理 + +### 1.1 创建表 + +#### 1.1.1 通过 Create 语句手动创建表 + +用于在当前数据库中创建表,也可以对任何指定数据库创建表,格式为“数据库名.表名”。 + +**语法:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +**说明:** + +1. 在创建表时,可以不指定时间列(TIME),IoTDB会自动添加该列。其他所有列可以通过在数据库配置时启用`enable_auto_create_schema`选项,或通过 session 接口自动创建或修改表的语句来添加。 +2. 列的类别可以省略,默认为`FIELD`。当列的类别为`TAG`或`ATTRIBUTE`时,数据类型需为`STRING`(可省略)。 +3. 表的TTL默认为其所在数据库的TTL。如果使用默认值,可以省略此属性,或将其设置为`default`。 +4. 表名称,具有以下特性: + - 大小写不敏感,创建成功后,统一显示为小写 + - 名称可包含特殊字符,如 `~!`"%` 等 + - 包含特殊字符或中文字符的表名创建时必须用双引号 "" 括起来。 + - 注意:SQL中特殊字符或中文表名需加双引号。原生API中无需额外添加,否则表名会包含引号字符。 + - 当为表命名时,最外层的双引号(`""`)不会在实际创建的表名中出现。 + + - ```SQL + -- SQL 中 + "a""b" --> a"b + """""" --> "" + -- API 中 + "a""b" --> "a""b" + ``` +5. columnDefinition 列名称与表名称具有相同特性,并且可包含特殊字符`.`。 +6. COMMENT 给表添加注释。 + +**示例:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "场站" STRING TAG, + "温度" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +#### 1.1.2 通过 Session 写入自动创建表 + +在通过 Session 进行数据写入时,IoTDB 能够根据写入请求中的信息自动构建表结构,无需用户事先手动创建表即可直接执行数据写入操作。 + +**示例:** + +```Java +try (ITableSession session = + new TableSessionBuilder() + .nodeUrls(Collections.singletonList("127.0.0.1:6667")) + .username("root") + .password("root") + .build()) { + + session.executeNonQueryStatement("CREATE DATABASE db1"); + session.executeNonQueryStatement("use db1"); + + // 不创建表直接写入数据 + List columnNameList = + Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); + List dataTypeList = + Arrays.asList( + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.FLOAT, + TSDataType.DOUBLE); + List columnTypeList = + new ArrayList<>( + Arrays.asList( + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.ATTRIBUTE, + ColumnCategory.FIELD, + ColumnCategory.FIELD)); + Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); + for (long timestamp = 0; timestamp < 100; timestamp++) { + int rowIndex = tablet.getRowSize(); + tablet.addTimestamp(rowIndex, timestamp); + tablet.addValue("region_id", rowIndex, "1"); + tablet.addValue("plant_id", rowIndex, "5"); + tablet.addValue("device_id", rowIndex, "3"); + tablet.addValue("model", rowIndex, "A"); + tablet.addValue("temperature", rowIndex, 37.6F); + tablet.addValue("humidity", rowIndex, 111.1); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + session.insert(tablet); + tablet.reset(); + } + } + if (tablet.getRowSize() != 0) { + session.insert(tablet); + tablet.reset(); + } +} +``` + +在代码执行完成后,可以通过下述语句确认表已成功创建,其中包含了时间列、标签列、属性列以及测点列等各类信息。 + +```SQL +IoTDB> desc table1 ++-----------+---------+-----------+-------+ +| ColumnName| DataType| Category|Comment| ++-----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| region_id| STRING| TAG| null| +| plant_id| STRING| TAG| null| +| device_id| STRING| TAG| null| +| model| STRING| ATTRIBUTE| null| +|temperature| FLOAT| FIELD| null| +| humidity| DOUBLE| FIELD| null| ++-----------+---------+-----------+-------+ +``` + +### 1.2 查看表 + +用于查看该数据库中或指定数据库中的所有表和表库的属性信息。 + +**语法:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**说明:** + +1. 在查询中指定了`FROM`或`IN`子句时,系统将展示指定数据库内的所有表。 +2. 如果未指定`FROM`或`IN`子句,系统将展示当前选定数据库中的所有表。如果用户未使用(use)某个数据库空间,系统将报错。 +3. 请求显示详细信息(指定`DETAILS`),系统将展示表的当前状态,包括: + - `USING`:表示表处于正常可用状态。 + - `PRE_CREATE`:表示表正在创建中或创建失败,此时表不可用。 + - `PRE_DELETE`:表示表正在删除中或删除失败,此类表将永久不可用。 + +**示例:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 1.3 查看表的列 + +用于查看表的列名、数据类型、类别、状态。 + +**语法:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**说明:** + +- 如果设置了`DETAILS`选项,系统将展示列的详细状态信息,包括: + - `USING`:表示列目前处于正常使用状态。 + - `PRE_DELETE`:表示列正在被删除或删除操作失败,该列将永久无法使用。 + +**示例:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 1.4 修改表 + +用于修改表,包括添加列、删除列以及设置表的属性。 + +**语法:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**说明:** + +1. `SET PROPERTIES`操作目前仅支持对表的 TTL 属性进行配置。 +2. 删除列功能,仅支持删除属性列(ATTRIBUTE)和物理量列(FIELD),标识列(TAG)不支持删除。 +3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 + +**示例:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 1.5 删除表 + +用于删除表。 + +**语法:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md new file mode 100644 index 000000000..314991c13 --- /dev/null +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md @@ -0,0 +1,315 @@ + + +# 表管理 + +在开始使用表管理功能前,推荐您先了解以下相关预备知识,以便更好地理解和应用表管理功能: +* [时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md):了解时序数据的基本概念与特点,帮助建立建模基础。 +* [建模方案设计](../Background-knowledge/Data-Model-and-Terminology_timecho.md):掌握 IoTDB 时序模型及适用场景,为表管理提供设计基础。 + +## 1. 表管理 + +### 1.1 创建表 + +#### 1.1.1 通过 Create 语句手动创建表 + +用于在当前数据库中创建表,也可以对任何指定数据库创建表,格式为“数据库名.表名”。 + +**语法:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +**说明:** + +1. 在创建表时,可以不指定时间列(TIME),IoTDB会自动添加该列。其他所有列可以通过在数据库配置时启用`enable_auto_create_schema`选项,或通过 session 接口自动创建或修改表的语句来添加。 +2. 列的类别可以省略,默认为`FIELD`。当列的类别为`TAG`或`ATTRIBUTE`时,数据类型需为`STRING`(可省略)。 +3. 表的TTL默认为其所在数据库的TTL。如果使用默认值,可以省略此属性,或将其设置为`default`。 +4. 表名称,具有以下特性: + - 大小写不敏感,创建成功后,统一显示为小写 + - 名称可包含特殊字符,如 `~!`"%` 等 + - 包含特殊字符或中文字符的表名创建时必须用双引号 "" 括起来。 + - 注意:SQL中特殊字符或中文表名需加双引号。原生API中无需额外添加,否则表名会包含引号字符。 + - 当为表命名时,最外层的双引号(`""`)不会在实际创建的表名中出现。 + + - ```SQL + -- SQL 中 + "a""b" --> a"b + """""" --> "" + -- API 中 + "a""b" --> "a""b" + ``` +5. columnDefinition 列名称与表名称具有相同特性,并且可包含特殊字符`.`。 +6. COMMENT 给表添加注释。 + +**示例:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "场站" STRING TAG, + "温度" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +#### 1.1.2 通过 Session 写入自动创建表 + +在通过 Session 进行数据写入时,IoTDB 能够根据写入请求中的信息自动构建表结构,无需用户事先手动创建表即可直接执行数据写入操作。 + +**示例:** + +```Java +try (ITableSession session = + new TableSessionBuilder() + .nodeUrls(Collections.singletonList("127.0.0.1:6667")) + .username("root") + .password("root") + .build()) { + + session.executeNonQueryStatement("CREATE DATABASE db1"); + session.executeNonQueryStatement("use db1"); + + // 不创建表直接写入数据 + List columnNameList = + Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); + List dataTypeList = + Arrays.asList( + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.FLOAT, + TSDataType.DOUBLE); + List columnTypeList = + new ArrayList<>( + Arrays.asList( + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.ATTRIBUTE, + ColumnCategory.FIELD, + ColumnCategory.FIELD)); + Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); + for (long timestamp = 0; timestamp < 100; timestamp++) { + int rowIndex = tablet.getRowSize(); + tablet.addTimestamp(rowIndex, timestamp); + tablet.addValue("region_id", rowIndex, "1"); + tablet.addValue("plant_id", rowIndex, "5"); + tablet.addValue("device_id", rowIndex, "3"); + tablet.addValue("model", rowIndex, "A"); + tablet.addValue("temperature", rowIndex, 37.6F); + tablet.addValue("humidity", rowIndex, 111.1); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + session.insert(tablet); + tablet.reset(); + } + } + if (tablet.getRowSize() != 0) { + session.insert(tablet); + tablet.reset(); + } +} +``` + +在代码执行完成后,可以通过下述语句确认表已成功创建,其中包含了时间列、标签列、属性列以及测点列等各类信息。 + +```SQL +IoTDB> desc table1 ++-----------+---------+-----------+-------+ +| ColumnName| DataType| Category|Comment| ++-----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| region_id| STRING| TAG| null| +| plant_id| STRING| TAG| null| +| device_id| STRING| TAG| null| +| model| STRING| ATTRIBUTE| null| +|temperature| FLOAT| FIELD| null| +| humidity| DOUBLE| FIELD| null| ++-----------+---------+-----------+-------+ +``` + +### 1.2 查看表 + +用于查看该数据库中或指定数据库中的所有表和表库的属性信息。 + +**语法:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**说明:** + +1. 在查询中指定了`FROM`或`IN`子句时,系统将展示指定数据库内的所有表。 +2. 如果未指定`FROM`或`IN`子句,系统将展示当前选定数据库中的所有表。如果用户未使用(use)某个数据库空间,系统将报错。 +3. 请求显示详细信息(指定`DETAILS`),系统将展示表的当前状态,包括: + - `USING`:表示表处于正常可用状态。 + - `PRE_CREATE`:表示表正在创建中或创建失败,此时表不可用。 + - `PRE_DELETE`:表示表正在删除中或删除失败,此类表将永久不可用。 + +**示例:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 1.3 查看表的列 + +用于查看表的列名、数据类型、类别、状态。 + +**语法:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**说明:** + +- 如果设置了`DETAILS`选项,系统将展示列的详细状态信息,包括: + - `USING`:表示列目前处于正常使用状态。 + - `PRE_DELETE`:表示列正在被删除或删除操作失败,该列将永久无法使用。 + +**示例:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 1.4 修改表 + +用于修改表,包括添加列、删除列以及设置表的属性。 + +**语法:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**说明:** + +1. `SET PROPERTIES`操作目前仅支持对表的 TTL 属性进行配置。 +2. 删除列功能,仅支持删除属性列(ATTRIBUTE)和物理量列(FIELD),标识列(TAG)不支持删除。 +3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 + +**示例:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 1.5 删除表 + +用于删除表。 + +**语法:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/Reference/System-Tables_apache.md b/src/zh/UserGuide/Master/Table/Reference/System-Tables_apache.md new file mode 100644 index 000000000..e0c594dc4 --- /dev/null +++ b/src/zh/UserGuide/Master/Table/Reference/System-Tables_apache.md @@ -0,0 +1,593 @@ + + +# 系统表 + +IoTDB 内置系统数据库 `INFORMATION_SCHEMA`,其中包含一系列系统表,用于存储 IoTDB 运行时信息(如当前正在执行的 SQL 语句等)。目前`INFORMATION_SCHEMA`数据库只支持读操作。 + +## 1. 系统库 + +* 名称:`INFORMATION_SCHEMA` +* 指令:只读,只支持 `Show databases (DETAILS) `​`/ Show Tables (DETAILS) / Use`,其余操作将会报错:`"The database 'information_schema' can only be queried"` +* 属性:`TTL=INF`,其余属性默认为`null` +* SQL示例: + +```sql +IoTDB> show databases ++------------------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++------------------+-------+-----------------------+---------------------+---------------------+ +|information_schema| INF| null| null| null| ++------------------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show tables from information_schema ++--------------+-------+ +| TableName|TTL(ms)| ++--------------+-------+ +| columns| INF| +| config_nodes| INF| +|configurations| INF| +| data_nodes| INF| +| databases| INF| +| functions| INF| +| keywords| INF| +| models| INF| +| nodes| INF| +| pipe_plugins| INF| +| pipes| INF| +| queries| INF| +| regions| INF| +| subscriptions| INF| +| tables| INF| +| topics| INF| +| views| INF| ++--------------+-------+ +``` + +## 2. 系统表 + +* 名称:`DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES`(详细介绍见后面小节) +* 操作:只读,只支持`SELECT`, `COUNT/SHOW DEVICES`, `DESC`,不支持对于表结构 / 内容的任意修改,如果修改将会报错:`"The database 'information_schema' can only be queried"` +* 列名:系统表的列名均默认为小写,且用`_`分隔 + +### 2.1 DATABASES 表 + +* 包含集群中所有数据库的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ----------------------------- | ---------- | ----------- | ---------------- | +| database | STRING | TAG | 数据库名称 | +| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | +| schema\_replication\_factor | INT32 | ATTRIBUTE | 元数据副本数 | +| data\_replication\_factor | INT32 | ATTRIBUTE | 数据副本数 | +| time\_partition\_interval | INT64 | ATTRIBUTE | 时间分区间隔 | +| schema\_region\_group\_num | INT32 | ATTRIBUTE | 元数据分区数量 | +| data\_region\_group\_num | INT32 | ATTRIBUTE | 数据分区数量 | + +* 查询结果只展示自身对该数据库本身或库中任意表有任意权限的数据库集合 +* 查询示例: + +```sql +IoTDB> select * from information_schema.databases ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +|information_schema| INF| null| null| null| null| null| +| database1| INF| 1| 1| 604800000| 0| 0| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +``` + +### 2.2 TABLES 表 + +* 包含集群中所有表的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------- | ---------- | ----------- | -------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 表名称 | +| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | +| status | STRING | ATTRIBUTE | 状态 | +| comment | STRING | ATTRIBUTE | 注释 | + +* 说明:status 可能为`USING`/`PRE_CREATE`/`PRE_DELETE`,具体见表管理中[查看表](../Basic-Concept/Table-Management_apache.md#12-查看表)的相关描述 +* 查询结果只展示自身有任意权限的表集合 +* 查询示例: + +```sql +IoTDB> select * from information_schema.tables ++------------------+--------------+-----------+------+-------+-----------+ +| database| table_name| ttl(ms)|status|comment| table_type| ++------------------+--------------+-----------+------+-------+-----------+ +|information_schema| databases| INF| USING| null|SYSTEM VIEW| +|information_schema| models| INF| USING| null|SYSTEM VIEW| +|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| +|information_schema| regions| INF| USING| null|SYSTEM VIEW| +|information_schema| functions| INF| USING| null|SYSTEM VIEW| +|information_schema| keywords| INF| USING| null|SYSTEM VIEW| +|information_schema| columns| INF| USING| null|SYSTEM VIEW| +|information_schema| topics| INF| USING| null|SYSTEM VIEW| +|information_schema|configurations| INF| USING| null|SYSTEM VIEW| +|information_schema| queries| INF| USING| null|SYSTEM VIEW| +|information_schema| tables| INF| USING| null|SYSTEM VIEW| +|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| +|information_schema| nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| pipes| INF| USING| null|SYSTEM VIEW| +|information_schema| views| INF| USING| null|SYSTEM VIEW| +|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| +| database1| table1|31536000000| USING| null| BASE TABLE| ++------------------+--------------+-----------+------+-------+-----------+ +``` + +### 2.3 REGIONS 表 + +* 包含集群中所有`Region`的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| --------------------- | ----------- | ----------- | ----------------------------------------------------------------------------------------------------------- | +| region\_id | INT32 | TAG | region ID | +| datanode\_id | INT32 | TAG | dataNode ID | +| type | STRING | ATTRIBUTE | 类型(SchemaRegion / DataRegion) | +| status | STRING | ATTRIBUTE | 状态(Running/Unknown 等) | +| database | STRING | ATTRIBUTE | database 名字 | +| series\_slot\_num | INT32 | ATTRIBUTE | series slot 个数 | +| time\_slot\_num | INT64 | ATTRIBUTE | time slot 个数 | +| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | +| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | +| internal\_address | STRING | ATTRIBUTE | 内部通讯地址 | +| role | STRING | ATTRIBUTE | Leader / Follower | +| create\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | +| tsfile\_size\_bytes | INT64 | ATTRIBUTE | 可统计的 DataRegion:含有 TsFile 的总文件大小;不可统计的 DataRegion(Unknown):-1;SchemaRegion:null; | + +* 仅管理员可执行查询操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.regions ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| +| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| +| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +``` + +### 2.4 QUERIES 表 + +* 包含集群中所有正在执行的查询的信息。也可以使用 `SHOW QUERIES`语法去查询。 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| --------------- | ----------- | ----------- | ------------------------------------------------ | +| query\_id | STRING | TAG | ID | +| start\_time | TIMESTAMP | ATTRIBUTE | 查询开始的时间戳,时间戳精度与系统精度保持一致 | +| datanode\_id | INT32 | ATTRIBUTE | 发起查询的DataNode ID | +| elapsed\_time | FLOAT | ATTRIBUTE | 查询执行耗时,单位是秒 | +| statement | STRING | ATTRIBUTE | 查询sql | +| user | STRING | ATTRIBUTE | 发起查询的用户 | + +* 普通用户查询结果仅显示自身执行的查询;管理员显示全部。 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.queries ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +``` + +### 2.5 COLUMNS 表 + +* 包含集群中所有表中列的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| -------------- | ---------- | ----------- | -------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 表名称 | +| column\_name | STRING | TAG | 列名称 | +| datatype | STRING | ATTRIBUTE | 列的数值类型 | +| category | STRING | ATTRIBUTE | 列类型 | +| status | STRING | ATTRIBUTE | 列状态 | +| comment | STRING | ATTRIBUTE | 列注释 | + +说明: +* status 可能为`USING`/`PRE_DELETE`,具体见表管理中[查看表的列](../Basic-Concept/Table-Management_apache.md#13-查看表的列)的相关描述 +* 查询结果只展示自身有任意权限的表的列信息 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.columns where database = 'database1' ++---------+----------+------------+---------+---------+------+-------+ +| database|table_name| column_name| datatype| category|status|comment| ++---------+----------+------------+---------+---------+------+-------+ +|database1| table1| time|TIMESTAMP| TIME| USING| null| +|database1| table1| region| STRING| TAG| USING| null| +|database1| table1| plant_id| STRING| TAG| USING| null| +|database1| table1| device_id| STRING| TAG| USING| null| +|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| +|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| +|database1| table1| temperature| FLOAT| FIELD| USING| null| +|database1| table1| humidity| FLOAT| FIELD| USING| null| +|database1| table1| status| BOOLEAN| FIELD| USING| null| +|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| ++---------+----------+------------+---------+---------+------+-------+ +``` + +### 2.6 PIPES 表 + +* 包含集群中所有 PIPE 的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------------- | ----------- | ----------- | --------------------------------------- | +| id | STRING | TAG | Pipe 名称 | +| creation\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | +| state | STRING | ATTRIBUTE | Pipe 状态(RUNNING/STOPPED) | +| pipe\_source | STRING | ATTRIBUTE | source 插件参数 | +| pipe\_processor | STRING | ATTRIBUTE | processor 插件参数 | +| pipe\_sink | STRING | ATTRIBUTE | source 插件参数 | +| exception\_message | STRING | ATTRIBUTE | Exception 信息 | +| remaining\_event\_count | INT64 | ATTRIBUTE | 剩余 event 数量,如果 Unknown 则为 -1 | +| estimated\_remaining\_seconds | DOUBLE | ATTRIBUTE | 预估剩余时间,如果 Unknown 则为 -1 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +select * from information_schema.pipes ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +``` + +### 2.7 PIPE\_PLUGINS 表 + +* 包含集群中所有PIPE插件的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| -------------- | ---------- | ----------- | ----------------------------------------------- | +| plugin\_name | STRING | TAG | 插件名称 | +| plugin\_type | STRING | ATTRIBUTE | 插件类型(Builtin/External) | +| class\_name | STRING | ATTRIBUTE | 插件的主类名 | +| plugin\_jar | STRING | ATTRIBUTE | 插件的 jar 包名称,若为 builtin 类型则为 null | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.pipe_plugins ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +| plugin_name|plugin_type| class_name|plugin_jar| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| +| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| +| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| +| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| +| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| +| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +``` + +### 2.8 SUBSCRIPTIONS 表 + +* 包含集群中所有数据订阅的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ----------------------- | ---------- | ----------- | -------------- | +| topic\_name | STRING | TAG | 订阅主题名称 | +| consumer\_group\_name | STRING | TAG | 消费者组名称 | +| subscribed\_consumers | STRING | ATTRIBUTE | 订阅的消费者 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' ++----------+-------------------+--------------------------------+ +|topic_name|consumer_group_name| subscribed_consumers| ++----------+-------------------+--------------------------------+ +| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| ++----------+-------------------+--------------------------------+ +``` + +### 2.9 TOPICS 表 + +* 包含集群中所有数据订阅主题的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------------- | ---------- | ----------- | -------------- | +| topic\_name | STRING | TAG | 订阅主题名称 | +| topic\_configs | STRING | ATTRIBUTE | 订阅主题配置 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.topics ++----------+----------------------------------------------------------------+ +|topic_name| topic_configs| ++----------+----------------------------------------------------------------+ +| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| ++----------+----------------------------------------------------------------+ +``` + +### 2.10 VIEWS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的表视图信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------ | ---------- | ----------- | ---------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 视图名称 | +| view\_definition | STRING | ATTRIBUTE | 视图的创建语句 | + +* 查询结果只展示自身有任意权限的视图集合 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.views ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +| database|table_name| view_definition| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| ++---------+----------+--------------------------------------------------------------------------------------------------------------------------------------- +``` + +### 2.11 MODELS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的模型信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------- | ---------- | ----------- | ----------------------------------------------------------------------- | +| model\_id | STRING | TAG | 模型名称 | +| model\_type | STRING | ATTRIBUTE | 模型类型(预测,异常检测,自定义) | +| state | STRING | ATTRIBUTE | 模型状态(是否可用) | +| configs | STRING | ATTRIBUTE | 模型的超参数的 string 格式,与正常的 show 相同 | +| notes | STRING | ATTRIBUTE | 模型注释* 内置 model:Built-in model in IoTDB* 用户的 model:自定义 | + +* 查询示例: + +```SQL +-- 找到类型为内置预测的所有模型 +IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' ++---------------------+-----------------+------+-------+-----------------------+ +| model_id| model_type| state|configs| notes| ++---------------------+-----------------+------+-------+-----------------------+ +| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| ++---------------------+-----------------+------+-------+-----------------------+ +``` + +### 2.12 FUNCTIONS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的函数信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------ | ---------- | ----------- | ----------------------------------------- | +| function\_name | STRING | TAG | 函数名称 | +| function\_type | STRING | ATTRIBUTE | 函数类型(内/外置数值/聚合/表函数) | +| class\_name(udf) | STRING | ATTRIBUTE | 如为 UDF,则为类名,否则为 null(暂定) | +| state | STRING | ATTRIBUTE | 是否可用 | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.functions where function_type='built-in table function' ++--------------+-----------------------+---------------+---------+ +|function_table| function_type|class_name(udf)| state| ++--------------+-----------------------+---------------+---------+ +| CUMULATE|built-in table function| null|AVAILABLE| +| SESSION|built-in table function| null|AVAILABLE| +| HOP|built-in table function| null|AVAILABLE| +| TUMBLE|built-in table function| null|AVAILABLE| +| FORECAST|built-in table function| null|AVAILABLE| +| VARIATION|built-in table function| null|AVAILABLE| +| CAPACITY|built-in table function| null|AVAILABLE| ++--------------+-----------------------+---------------+---------+ +``` + +### 2.13 CONFIGURATIONS表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的属性信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------- | ---------- | ----------- | -------- | +| variable | STRING | TAG | 属性名 | +| value | STRING | ATTRIBUTE | 属性值 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.configurations ++----------------------------------+-----------------------------------------------------------------+ +| variable| value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 2.14 KEYWORDS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的关键字信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------- | ---------- | ----------- | -------------------------------- | +| word | STRING | TAG | 关键字 | +| reserved | INT32 | ATTRIBUTE | 是否为保留字,1表示是,0表示否 | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.keywords limit 10 ++----------+--------+ +| word|reserved| ++----------+--------+ +| ABSENT| 0| +|ACTIVATION| 1| +| ACTIVATE| 1| +| ADD| 0| +| ADMIN| 0| +| AFTER| 0| +| AINODES| 1| +| ALL| 0| +| ALTER| 1| +| ANALYZE| 0| ++----------+--------+ +``` + +### 2.15 NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------------ | ---------- | ----------- | --------------- | +| node\_id | INT32 | TAG | 节点 ID | +| node\_type | STRING | ATTRIBUTE | 节点类型 | +| status | STRING | ATTRIBUTE | 节点状态 | +| internal\_address | STRING | ATTRIBUTE | 内部 rpc 地址 | +| internal\_port | INT32 | ATTRIBUTE | 内部端口 | +| version | STRING | ATTRIBUTE | 版本号 | +| build\_info | STRING | ATTRIBUTE | CommitID | +| activate\_status(仅企业版) | STRING | ATTRIBUTE | 激活状态 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.nodes ++-------+----------+-------+----------------+-------------+-------+----------+ +|node_id| node_type| status|internal_address|internal_port|version|build_info| ++-------+----------+-------+----------------+-------------+-------+----------+ +| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| +| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| ++-------+----------+-------+----------------+-------------+-------+----------+ ++----------+--------+ +``` + +### 2.16 CONFIG\_NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的配置节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------- | ---------- | ----------- | --------------------- | +| node\_id | INT32 | TAG | 节点 ID | +| config\_consensus\_port | INT32 | ATTRIBUTE | configNode 共识端口 | +| role | STRING | ATTRIBUTE | configNode 节点角色 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.config_nodes ++-------+---------------------+------+ +|node_id|config_consensus_port| role| ++-------+---------------------+------+ +| 0| 10720|Leader| ++-------+---------------------+------+ +``` + +### 2.17 DATA\_NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的数据节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------ | ---------- | ----------- | ----------------------- | +| node\_id | INT32 | TAG | 节点 ID | +| data\_region\_num | INT32 | ATTRIBUTE | DataRegion 数量 | +| schema\_region\_num | INT32 | ATTRIBUTE | SchemaRegion 数量 | +| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | +| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | +| mpp\_port | INT32 | ATTRIBUTE | MPP 通信端口 | +| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion 共识端口 | +| scema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion 共识端口 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.data_nodes ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +``` + +## 3. 权限说明 + +* 不支持通过`GRANT/REVOKE`语句对 `information_schema` 数据库及其下任何表进行权限操作 +* 支持任意用户通过`show databases`语句查看`information_schema`数据库相关信息 +* 支持任意用户通过`show tables from information_schema` 语句查看所有系统表相关信息 +* 支持任意用户通过`desc`语句查看任意系统表 diff --git a/src/zh/UserGuide/Master/Table/Reference/System-Tables_timecho.md b/src/zh/UserGuide/Master/Table/Reference/System-Tables_timecho.md new file mode 100644 index 000000000..f0f2fec5b --- /dev/null +++ b/src/zh/UserGuide/Master/Table/Reference/System-Tables_timecho.md @@ -0,0 +1,593 @@ + + +# 系统表 + +IoTDB 内置系统数据库 `INFORMATION_SCHEMA`,其中包含一系列系统表,用于存储 IoTDB 运行时信息(如当前正在执行的 SQL 语句等)。目前`INFORMATION_SCHEMA`数据库只支持读操作。 + +## 1. 系统库 + +* 名称:`INFORMATION_SCHEMA` +* 指令:只读,只支持 `Show databases (DETAILS) `​`/ Show Tables (DETAILS) / Use`,其余操作将会报错:`"The database 'information_schema' can only be queried"` +* 属性:`TTL=INF`,其余属性默认为`null` +* SQL示例: + +```sql +IoTDB> show databases ++------------------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++------------------+-------+-----------------------+---------------------+---------------------+ +|information_schema| INF| null| null| null| ++------------------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show tables from information_schema ++--------------+-------+ +| TableName|TTL(ms)| ++--------------+-------+ +| columns| INF| +| config_nodes| INF| +|configurations| INF| +| data_nodes| INF| +| databases| INF| +| functions| INF| +| keywords| INF| +| models| INF| +| nodes| INF| +| pipe_plugins| INF| +| pipes| INF| +| queries| INF| +| regions| INF| +| subscriptions| INF| +| tables| INF| +| topics| INF| +| views| INF| ++--------------+-------+ +``` + +## 2. 系统表 + +* 名称:`DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES`(详细介绍见后面小节) +* 操作:只读,只支持`SELECT`, `COUNT/SHOW DEVICES`, `DESC`,不支持对于表结构 / 内容的任意修改,如果修改将会报错:`"The database 'information_schema' can only be queried"` +* 列名:系统表的列名均默认为小写,且用`_`分隔 + +### 2.1 DATABASES 表 + +* 包含集群中所有数据库的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ----------------------------- | ---------- | ----------- | ---------------- | +| database | STRING | TAG | 数据库名称 | +| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | +| schema\_replication\_factor | INT32 | ATTRIBUTE | 元数据副本数 | +| data\_replication\_factor | INT32 | ATTRIBUTE | 数据副本数 | +| time\_partition\_interval | INT64 | ATTRIBUTE | 时间分区间隔 | +| schema\_region\_group\_num | INT32 | ATTRIBUTE | 元数据分区数量 | +| data\_region\_group\_num | INT32 | ATTRIBUTE | 数据分区数量 | + +* 查询结果只展示自身对该数据库本身或库中任意表有任意权限的数据库集合 +* 查询示例: + +```sql +IoTDB> select * from information_schema.databases ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +|information_schema| INF| null| null| null| null| null| +| database1| INF| 1| 1| 604800000| 0| 0| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +``` + +### 2.2 TABLES 表 + +* 包含集群中所有表的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------- | ---------- | ----------- | -------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 表名称 | +| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | +| status | STRING | ATTRIBUTE | 状态 | +| comment | STRING | ATTRIBUTE | 注释 | + +* 说明:status 可能为`USING`/`PRE_CREATE`/`PRE_DELETE`,具体见表管理中[查看表](../Basic-Concept/Table-Management_timecho.md#12-查看表)的相关描述 +* 查询结果只展示自身有任意权限的表集合 +* 查询示例: + +```sql +IoTDB> select * from information_schema.tables ++------------------+--------------+-----------+------+-------+-----------+ +| database| table_name| ttl(ms)|status|comment| table_type| ++------------------+--------------+-----------+------+-------+-----------+ +|information_schema| databases| INF| USING| null|SYSTEM VIEW| +|information_schema| models| INF| USING| null|SYSTEM VIEW| +|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| +|information_schema| regions| INF| USING| null|SYSTEM VIEW| +|information_schema| functions| INF| USING| null|SYSTEM VIEW| +|information_schema| keywords| INF| USING| null|SYSTEM VIEW| +|information_schema| columns| INF| USING| null|SYSTEM VIEW| +|information_schema| topics| INF| USING| null|SYSTEM VIEW| +|information_schema|configurations| INF| USING| null|SYSTEM VIEW| +|information_schema| queries| INF| USING| null|SYSTEM VIEW| +|information_schema| tables| INF| USING| null|SYSTEM VIEW| +|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| +|information_schema| nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| pipes| INF| USING| null|SYSTEM VIEW| +|information_schema| views| INF| USING| null|SYSTEM VIEW| +|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| +| database1| table1|31536000000| USING| null| BASE TABLE| ++------------------+--------------+-----------+------+-------+-----------+ +``` + +### 2.3 REGIONS 表 + +* 包含集群中所有`Region`的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| --------------------- | ----------- | ----------- | ----------------------------------------------------------------------------------------------------------- | +| region\_id | INT32 | TAG | region ID | +| datanode\_id | INT32 | TAG | dataNode ID | +| type | STRING | ATTRIBUTE | 类型(SchemaRegion / DataRegion) | +| status | STRING | ATTRIBUTE | 状态(Running/Unknown 等) | +| database | STRING | ATTRIBUTE | database 名字 | +| series\_slot\_num | INT32 | ATTRIBUTE | series slot 个数 | +| time\_slot\_num | INT64 | ATTRIBUTE | time slot 个数 | +| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | +| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | +| internal\_address | STRING | ATTRIBUTE | 内部通讯地址 | +| role | STRING | ATTRIBUTE | Leader / Follower | +| create\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | +| tsfile\_size\_bytes | INT64 | ATTRIBUTE | 可统计的 DataRegion:含有 TsFile 的总文件大小;不可统计的 DataRegion(Unknown):-1;SchemaRegion:null; | + +* 仅管理员可执行查询操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.regions ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| +| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| +| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +``` + +### 2.4 QUERIES 表 + +* 包含集群中所有正在执行的查询的信息。也可以使用 `SHOW QUERIES`语法去查询。 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| --------------- | ----------- | ----------- | ------------------------------------------------ | +| query\_id | STRING | TAG | ID | +| start\_time | TIMESTAMP | ATTRIBUTE | 查询开始的时间戳,时间戳精度与系统精度保持一致 | +| datanode\_id | INT32 | ATTRIBUTE | 发起查询的DataNode ID | +| elapsed\_time | FLOAT | ATTRIBUTE | 查询执行耗时,单位是秒 | +| statement | STRING | ATTRIBUTE | 查询sql | +| user | STRING | ATTRIBUTE | 发起查询的用户 | + +* 普通用户查询结果仅显示自身执行的查询;管理员显示全部。 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.queries ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +``` + +### 2.5 COLUMNS 表 + +* 包含集群中所有表中列的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| -------------- | ---------- | ----------- | -------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 表名称 | +| column\_name | STRING | TAG | 列名称 | +| datatype | STRING | ATTRIBUTE | 列的数值类型 | +| category | STRING | ATTRIBUTE | 列类型 | +| status | STRING | ATTRIBUTE | 列状态 | +| comment | STRING | ATTRIBUTE | 列注释 | + +说明: +* status 可能为`USING`/`PRE_DELETE`,具体见表管理中[查看表的列](../Basic-Concept/Table-Management_timecho.md#13-查看表的列)的相关描述 +* 查询结果只展示自身有任意权限的表的列信息 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.columns where database = 'database1' ++---------+----------+------------+---------+---------+------+-------+ +| database|table_name| column_name| datatype| category|status|comment| ++---------+----------+------------+---------+---------+------+-------+ +|database1| table1| time|TIMESTAMP| TIME| USING| null| +|database1| table1| region| STRING| TAG| USING| null| +|database1| table1| plant_id| STRING| TAG| USING| null| +|database1| table1| device_id| STRING| TAG| USING| null| +|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| +|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| +|database1| table1| temperature| FLOAT| FIELD| USING| null| +|database1| table1| humidity| FLOAT| FIELD| USING| null| +|database1| table1| status| BOOLEAN| FIELD| USING| null| +|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| ++---------+----------+------------+---------+---------+------+-------+ +``` + +### 2.6 PIPES 表 + +* 包含集群中所有 PIPE 的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------------- | ----------- | ----------- | --------------------------------------- | +| id | STRING | TAG | Pipe 名称 | +| creation\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | +| state | STRING | ATTRIBUTE | Pipe 状态(RUNNING/STOPPED) | +| pipe\_source | STRING | ATTRIBUTE | source 插件参数 | +| pipe\_processor | STRING | ATTRIBUTE | processor 插件参数 | +| pipe\_sink | STRING | ATTRIBUTE | source 插件参数 | +| exception\_message | STRING | ATTRIBUTE | Exception 信息 | +| remaining\_event\_count | INT64 | ATTRIBUTE | 剩余 event 数量,如果 Unknown 则为 -1 | +| estimated\_remaining\_seconds | DOUBLE | ATTRIBUTE | 预估剩余时间,如果 Unknown 则为 -1 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +select * from information_schema.pipes ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +``` + +### 2.7 PIPE\_PLUGINS 表 + +* 包含集群中所有PIPE插件的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| -------------- | ---------- | ----------- | ----------------------------------------------- | +| plugin\_name | STRING | TAG | 插件名称 | +| plugin\_type | STRING | ATTRIBUTE | 插件类型(Builtin/External) | +| class\_name | STRING | ATTRIBUTE | 插件的主类名 | +| plugin\_jar | STRING | ATTRIBUTE | 插件的 jar 包名称,若为 builtin 类型则为 null | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.pipe_plugins ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +| plugin_name|plugin_type| class_name|plugin_jar| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| +| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| +| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| +| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| +| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| +| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +``` + +### 2.8 SUBSCRIPTIONS 表 + +* 包含集群中所有数据订阅的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ----------------------- | ---------- | ----------- | -------------- | +| topic\_name | STRING | TAG | 订阅主题名称 | +| consumer\_group\_name | STRING | TAG | 消费者组名称 | +| subscribed\_consumers | STRING | ATTRIBUTE | 订阅的消费者 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' ++----------+-------------------+--------------------------------+ +|topic_name|consumer_group_name| subscribed_consumers| ++----------+-------------------+--------------------------------+ +| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| ++----------+-------------------+--------------------------------+ +``` + +### 2.9 TOPICS 表 + +* 包含集群中所有数据订阅主题的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------------- | ---------- | ----------- | -------------- | +| topic\_name | STRING | TAG | 订阅主题名称 | +| topic\_configs | STRING | ATTRIBUTE | 订阅主题配置 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.topics ++----------+----------------------------------------------------------------+ +|topic_name| topic_configs| ++----------+----------------------------------------------------------------+ +| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| ++----------+----------------------------------------------------------------+ +``` + +### 2.10 VIEWS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的表视图信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------ | ---------- | ----------- | ---------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 视图名称 | +| view\_definition | STRING | ATTRIBUTE | 视图的创建语句 | + +* 查询结果只展示自身有任意权限的视图集合 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.views ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +| database|table_name| view_definition| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| ++---------+----------+--------------------------------------------------------------------------------------------------------------------------------------- +``` + +### 2.11 MODELS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的模型信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------- | ---------- | ----------- | ----------------------------------------------------------------------- | +| model\_id | STRING | TAG | 模型名称 | +| model\_type | STRING | ATTRIBUTE | 模型类型(预测,异常检测,自定义) | +| state | STRING | ATTRIBUTE | 模型状态(是否可用) | +| configs | STRING | ATTRIBUTE | 模型的超参数的 string 格式,与正常的 show 相同 | +| notes | STRING | ATTRIBUTE | 模型注释* 内置 model:Built-in model in IoTDB* 用户的 model:自定义 | + +* 查询示例: + +```SQL +-- 找到类型为内置预测的所有模型 +IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' ++---------------------+-----------------+------+-------+-----------------------+ +| model_id| model_type| state|configs| notes| ++---------------------+-----------------+------+-------+-----------------------+ +| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| ++---------------------+-----------------+------+-------+-----------------------+ +``` + +### 2.12 FUNCTIONS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的函数信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------ | ---------- | ----------- | ----------------------------------------- | +| function\_name | STRING | TAG | 函数名称 | +| function\_type | STRING | ATTRIBUTE | 函数类型(内/外置数值/聚合/表函数) | +| class\_name(udf) | STRING | ATTRIBUTE | 如为 UDF,则为类名,否则为 null(暂定) | +| state | STRING | ATTRIBUTE | 是否可用 | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.functions where function_type='built-in table function' ++--------------+-----------------------+---------------+---------+ +|function_table| function_type|class_name(udf)| state| ++--------------+-----------------------+---------------+---------+ +| CUMULATE|built-in table function| null|AVAILABLE| +| SESSION|built-in table function| null|AVAILABLE| +| HOP|built-in table function| null|AVAILABLE| +| TUMBLE|built-in table function| null|AVAILABLE| +| FORECAST|built-in table function| null|AVAILABLE| +| VARIATION|built-in table function| null|AVAILABLE| +| CAPACITY|built-in table function| null|AVAILABLE| ++--------------+-----------------------+---------------+---------+ +``` + +### 2.13 CONFIGURATIONS表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的属性信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------- | ---------- | ----------- | -------- | +| variable | STRING | TAG | 属性名 | +| value | STRING | ATTRIBUTE | 属性值 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.configurations ++----------------------------------+-----------------------------------------------------------------+ +| variable| value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 2.14 KEYWORDS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的关键字信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------- | ---------- | ----------- | -------------------------------- | +| word | STRING | TAG | 关键字 | +| reserved | INT32 | ATTRIBUTE | 是否为保留字,1表示是,0表示否 | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.keywords limit 10 ++----------+--------+ +| word|reserved| ++----------+--------+ +| ABSENT| 0| +|ACTIVATION| 1| +| ACTIVATE| 1| +| ADD| 0| +| ADMIN| 0| +| AFTER| 0| +| AINODES| 1| +| ALL| 0| +| ALTER| 1| +| ANALYZE| 0| ++----------+--------+ +``` + +### 2.15 NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------------ | ---------- | ----------- | --------------- | +| node\_id | INT32 | TAG | 节点 ID | +| node\_type | STRING | ATTRIBUTE | 节点类型 | +| status | STRING | ATTRIBUTE | 节点状态 | +| internal\_address | STRING | ATTRIBUTE | 内部 rpc 地址 | +| internal\_port | INT32 | ATTRIBUTE | 内部端口 | +| version | STRING | ATTRIBUTE | 版本号 | +| build\_info | STRING | ATTRIBUTE | CommitID | +| activate\_status(仅企业版) | STRING | ATTRIBUTE | 激活状态 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.nodes ++-------+----------+-------+----------------+-------------+-------+----------+ +|node_id| node_type| status|internal_address|internal_port|version|build_info| ++-------+----------+-------+----------------+-------------+-------+----------+ +| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| +| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| ++-------+----------+-------+----------------+-------------+-------+----------+ ++----------+--------+ +``` + +### 2.16 CONFIG\_NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的配置节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------- | ---------- | ----------- | --------------------- | +| node\_id | INT32 | TAG | 节点 ID | +| config\_consensus\_port | INT32 | ATTRIBUTE | configNode 共识端口 | +| role | STRING | ATTRIBUTE | configNode 节点角色 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.config_nodes ++-------+---------------------+------+ +|node_id|config_consensus_port| role| ++-------+---------------------+------+ +| 0| 10720|Leader| ++-------+---------------------+------+ +``` + +### 2.17 DATA\_NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的数据节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------ | ---------- | ----------- | ----------------------- | +| node\_id | INT32 | TAG | 节点 ID | +| data\_region\_num | INT32 | ATTRIBUTE | DataRegion 数量 | +| schema\_region\_num | INT32 | ATTRIBUTE | SchemaRegion 数量 | +| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | +| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | +| mpp\_port | INT32 | ATTRIBUTE | MPP 通信端口 | +| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion 共识端口 | +| scema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion 共识端口 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.data_nodes ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +``` + +## 3. 权限说明 + +* 不支持通过`GRANT/REVOKE`语句对 `information_schema` 数据库及其下任何表进行权限操作 +* 支持任意用户通过`show databases`语句查看`information_schema`数据库相关信息 +* 支持任意用户通过`show tables from information_schema` 语句查看所有系统表相关信息 +* 支持任意用户通过`desc`语句查看任意系统表 diff --git a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md new file mode 100644 index 000000000..638e001de --- /dev/null +++ b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md @@ -0,0 +1,304 @@ + + +# 元数据操作 + +## 1. 数据库管理 + +### 1.1 创建数据库 + +**语法:** + +```SQL +CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +更多详细语法说明请参考:[创建数据库](../Basic-Concept/Database-Management_apache.md#_1-1-创建数据库) + +**示例:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +-- 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 使用数据库 + +**语法:** + +```SQL +USE +``` + +**示例:** + +```SQL +USE database1 +``` + +### 1.3 查看当前数据库 + +**语法:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**示例:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 查看所有数据库 + +**语法:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +更多返回结果详细说明请参考:[查看所有数据库](../Basic-Concept/Database-Management_apache.md#_1-4-查看所有数据库) + +**示例:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 修改数据库 + +**语法:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**示例:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 删除数据库 + +**语法:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` + +## 2. 表管理 + +### 2.1 创建表 + +**语法:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +更多详细语法说明请参考:[创建表](../Basic-Concept/Table-Management_apache.md#_1-1-创建表) + +**示例:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "场站" STRING TAG, + "温度" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +### 2.2 查看表 + +**语法:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**示例:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 2.3 查看表的列 + +**语法:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**示例:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 2.4 修改表 + +**语法:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**示例:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 2.5 删除表 + +**语法:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` + + diff --git a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md new file mode 100644 index 000000000..5a612565a --- /dev/null +++ b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md @@ -0,0 +1,304 @@ + + +# 元数据操作 + +## 1. 数据库管理 + +### 1.1 创建数据库 + +**语法:** + +```SQL +CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +更多详细语法说明请参考:[创建数据库](../Basic-Concept/Database-Management_timecho.md#_1-1-创建数据库) + +**示例:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +-- 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 使用数据库 + +**语法:** + +```SQL +USE +``` + +**示例:** + +```SQL +USE database1 +``` + +### 1.3 查看当前数据库 + +**语法:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**示例:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 查看所有数据库 + +**语法:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +更多返回结果详细说明请参考:[查看所有数据库](../Basic-Concept/Database-Management_timecho.md#_1-4-查看所有数据库) + +**示例:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 修改数据库 + +**语法:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**示例:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 删除数据库 + +**语法:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` + +## 2. 表管理 + +### 2.1 创建表 + +**语法:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +更多详细语法说明请参考:[创建表](../Basic-Concept/Table-Management_timecho.md#_1-1-创建表) + +**示例:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "场站" STRING TAG, + "温度" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +### 2.2 查看表 + +**语法:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**示例:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 2.3 查看表的列 + +**语法:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**示例:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 2.4 修改表 + +**语法:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**示例:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 2.5 删除表 + +**语法:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` + + diff --git a/src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement_apache.md b/src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement_apache.md new file mode 100644 index 000000000..9f13e8397 --- /dev/null +++ b/src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement_apache.md @@ -0,0 +1,664 @@ + +# 运维语句 + +## 1. 状态查看 + +### 1.1 查看连接的模型 + +**含义**:返回当前连接的 sql_dialect 是树模型/表模型。 + +#### 语法: + +```SQL +showCurrentSqlDialectStatement + : SHOW CURRENT_SQL_DIALECT + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_SQL_DIALECT +``` + +执行结果如下: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` +### 1.2 查看登录的用户名 + +**含义**:返回当前登录的用户名。 + +#### 语法: + +```SQL +showCurrentUserStatement + : SHOW CURRENT_USER + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_USER +``` + +执行结果如下: + +```SQL ++-----------+ +|CurrentUser| ++-----------+ +| root| ++-----------+ +``` + +### 1.3 查看连接的数据库名 + +**含义**:返回当前连接的数据库名,若没有执行过 use 语句,则为 null。 + +#### 语法: + +```SQL +showCurrentDatabaseStatement + : SHOW CURRENT_DATABASE + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_DATABASE; + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; +``` + +执行结果如下: + +```SQL ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + ++---------------+ +|CurrentDatabase| ++---------------+ +| test| ++---------------+ +``` + +### 1.4 查看集群版本 + +**含义**:返回当前集群的版本。 + +#### 语法: + +```SQL +showVersionStatement + : SHOW VERSION + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW VERSION +``` + +执行结果如下: + +```SQL ++-------+---------+ +|Version|BuildInfo| ++-------+---------+ +|2.0.1.2| 1ca4008| ++-------+---------+ +``` + +### 1.5 查看集群关键参数 + +**含义**:返回当前集群的关键参数。 + +#### 语法: + +```SQL +showVariablesStatement + : SHOW VARIABLES + ; +``` + +关键参数如下: + +1. **ClusterName**:当前集群的名称。 +2. **DataReplicationFactor**:数据副本的数量,表示每个数据分区(DataRegion)的副本数。 +3. **SchemaReplicationFactor**:元数据副本的数量,表示每个元数据分区(SchemaRegion)的副本数。 +4. **DataRegionConsensusProtocolClass**:数据分区(DataRegion)使用的共识协议类。 +5. **SchemaRegionConsensusProtocolClass**:元数据分区(SchemaRegion)使用的共识协议类。 +6. **ConfigNodeConsensusProtocolClass**:配置节点(ConfigNode)使用的共识协议类。 +7. **TimePartitionOrigin**:数据库时间分区的起始时间戳。 +8. **TimePartitionInterval**:数据库的时间分区间隔(单位:毫秒)。 +9. **ReadConsistencyLevel**:读取操作的一致性级别。 +10. **SchemaRegionPerDataNode**:数据节点(DataNode)上的元数据分区(SchemaRegion)数量。 +11. **DataRegionPerDataNode**:数据节点(DataNode)上的数据分区(DataRegion)数量。 +12. **SeriesSlotNum**:数据分区(DataRegion)的序列槽(SeriesSlot)数量。 +13. **SeriesSlotExecutorClass**:序列槽的实现类。 +14. **DiskSpaceWarningThreshold**:磁盘空间告警阈值(单位:百分比)。 +15. **TimestampPrecision**:时间戳精度。 + +#### 示例: + +```SQL +IoTDB> SHOW VARIABLES +``` + +执行结果如下: + +```SQL ++----------------------------------+-----------------------------------------------------------------+ +| Variable| Value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 1.6 查看集群ID + +**含义**:返回当前集群的ID。 + +#### 语法: + +```SQL +showClusterIdStatement + : SHOW (CLUSTERID | CLUSTER_ID) + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CLUSTER_ID +``` + +执行结果如下: + +```SQL ++------------------------------------+ +| ClusterId| ++------------------------------------+ +|40163007-9ec1-4455-aa36-8055d740fcda| +``` + +### 1.7 查看客户端直连的 DataNode 进程所在服务器的时间 + +#### 语法: + +**含义**:返回当前客户端直连的 DataNode 进程所在服务器的时间。 + +```SQL +showCurrentTimestampStatement + : SHOW CURRENT_TIMESTAMP + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_TIMESTAMP +``` + +执行结果如下: + +```SQL ++-----------------------------+ +| CurrentTimestamp| ++-----------------------------+ +|2025-02-17T11:11:52.987+08:00| ++-----------------------------+ +``` + +### 1.8 查看正在执行的查询信息 + +**含义**:用于显示所有正在执行的查询信息。 + +> 更多系统表使用方法请参考[系统表](../Reference/System-Tables_apache.md) + +#### 语法: + +```SQL +showQueriesStatement + : SHOW (QUERIES | QUERY PROCESSLIST) + (WHERE where=booleanExpression)? + (ORDER BY sortItem (',' sortItem)*)? + limitOffsetClause + ; +``` + +**参数解释**: + +1. **WHERE** 子句:需保证过滤的目标列是结果集中存在的列 +2. **ORDER BY** 子句:需保证`sortKey`是结果集中存在的列 +3. **limitOffsetClause**: + - **含义**:用于限制结果集的返回数量。 + - **格式**:`LIMIT , `, `` 是偏移量,`` 是返回的行数。 +4. **QUERIES** 表中的列: + - **query_id**:查询语句的 ID + - **start_time**:查询开始的时间戳,时间戳精度与系统精度一致 + - **datanode_id**:发起查询语句的 DataNode 的ID + - **elapsed_time**:查询的执行耗时,单位是秒 + - **statement**:查询的 SQL 语句 + - **user**:发起查询的用户 + +#### 示例: + +```SQL +IoTDB> SHOW QUERIES WHERE elapsed_time > 30 +``` + +执行结果如下: + +```SQL ++-----------------------+-----------------------------+-----------+------------+------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +``` + +### 1.9 查看分区信息 + +**含义**:返回当前集群的分区信息。 + +#### 语法: + +```SQL +showRegionsStatement + : SHOW REGIONS + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW REGIONS +``` + +执行结果如下: + +```SQL ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | +| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| +| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +``` + + +## 2. 状态设置 + +### 2.1 设置连接的模型 + +**含义**:将当前连接的 sql_dialect 置为树模型/表模型,在树模型和表模型中均可使用该命令。 + +#### 语法: + +```SQL +SET SQL_DIALECT EQ (TABLE | TREE) +``` + +#### 示例: + +```SQL +IoTDB> SET SQL_DIALECT=TABLE +IoTDB> SHOW CURRENT_SQL_DIALECT +``` + +执行结果如下: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 2.2 更新配置项 + +**含义**:用于更新配置项,执行完成后会进行配置项的热加载,对于支持热修改的配置项会立即生效。 + +#### 语法: + +```SQL +setConfigurationStatement + : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? + ; + +propertyAssignments + : property (',' property)* + ; + +property + : identifier EQ propertyValue + ; + +propertyValue + : DEFAULT + | expression + ; +``` + +**参数解释**: + +1. **propertyAssignments** + - **含义**:更新的配置列表,由多个 `property` 组成。 + - 可以更新多个配置列表,用逗号分隔。 + - **取值**: + - `DEFAULT`:将配置项恢复为默认值。 + - `expression`:具体的值,必须是一个字符串。 +2. **ON INTEGER_VALUE** + - **含义**:指定要更新配置的节点 ID。 + - **可选性**:可选。如果不指定或指定的值低于 0,则更新所有 ConfigNode 和 DataNode 的配置。 + +#### 示例: + +```SQL +IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; +``` + +### 2.3 读取手动修改的配置文件 + +**含义**:用于读取手动修改过的配置文件,并对配置项进行热加载,对于支持热修改的配置项会立即生效。 + +#### 语法: + +```SQL +loadConfigurationStatement + : LOAD CONFIGURATION localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定配置热加载的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `LOCAL`:只对客户端直连的 DataNode 进行配置热加载。 + - `CLUSTER`:对集群中所有 DataNode 进行配置热加载。 + +#### 示例: + +```SQL +IoTDB> LOAD CONFIGURATION ON LOCAL; +``` + +### 2.4 设置系统的状态 + +**含义**:用于设置系统的状态。 + +#### 语法: + +```SQL +setSystemStatusStatement + : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **RUNNING | READONLY** + - **含义**:指定系统的新状态。 + - **取值**: + - `RUNNING`:将系统设置为运行状态,允许读写操作。 + - `READONLY`:将系统设置为只读状态,只允许读取操作,禁止写入操作。 +2. **localOrClusterMode** + - **含义**:指定状态变更的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `LOCAL`:仅对客户端直连的 DataNode 生效。 + - `CLUSTER`:对集群中所有 DataNode 生效。 + +#### 示例: + +```SQL +IoTDB> SET SYSTEM TO READONLY ON CLUSTER; +``` + + +## 3. 数据管理 + +### 3.1 刷写内存表中的数据到磁盘 + +**含义**:将内存表中的数据刷写到磁盘上。 + +#### 语法: + +```SQL +flushStatement + : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? + ; + +booleanValue + : TRUE | FALSE + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **identifier** + - **含义**:指定要刷写的数据库名称。 + - **可选性**:可选。如果不指定,则默认刷写所有数据库。 + - **多个数据库**:可以指定多个数据库名称,用逗号分隔。例如:`FLUSH test_db1, test_db2`。 +2. **booleanValue** + - **含义**:指定刷写的内容。 + - **可选性**:可选。如果不指定,则默认刷写顺序和乱序空间的内存。 + - **取值**: + - `TRUE`:只刷写顺序空间的内存表。 + - `FALSE`:只刷写乱序空间的MemTable。 +3. **localOrClusterMode** + - **含义**:指定刷写的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:只刷写客户端直连的 DataNode 上的内存表。 + - `ON CLUSTER`:刷写集群中所有 DataNode 上的内存表。 + +#### 示例: + +```SQL +IoTDB> FLUSH test_db TRUE ON LOCAL; +``` + +### 3.2 清除 DataNode 上的缓存 + +**含义**:用于清除 DataNode 上的某种类型的缓存。 + +#### 语法: + +```SQL +clearCacheStatement + : CLEAR clearCacheOptions? CACHE localOrClusterMode? + ; + +clearCacheOptions + : ATTRIBUTE + | QUERY + | ALL + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **clearCacheOptions** + - **含义**:指定要清除的缓存类型。 + - **可选性**:可选。如果不指定,默认清除查询缓存(`QUERY`)。 + - **取值**: + - `ATTRIBUTE`:清除设备属性缓存。 + - `QUERY`:清除存储引擎中的查询缓存。 + - `ALL`:清除所有缓存,包括设备属性缓存、查询缓存以及树模型中的模式缓存。 +2. **localOrClusterMode** + - **含义**:指定清除缓存的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:只清除客户端直连的 DataNode 上的缓存。 + - `ON CLUSTER`:清除集群中所有 DataNode 上的缓存。 + +#### 示例: + +```SQL +IoTDB> CLEAR ALL CACHE ON LOCAL; +``` + +## 4. 数据修复 + +### 4.1 启动后台扫描并修复 tsfile 任务 + +**含义**:启动一个后台任务,开始扫描并修复 tsfile,能够修复数据文件内的时间戳乱序类异常。 + +#### 语法: + +```SQL +startRepairDataStatement + : START REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定数据修复的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 + - `ON CLUSTER`:对集群中所有 DataNode 执行。 + +#### 示例: + +```SQL +IoTDB> START REPAIR DATA ON CLUSTER; +``` + +### 4.2 暂停后台修复 tsfile 任务 + +**含义**:暂停后台的修复任务,暂停中的任务可通过再次执行 start repair data 命令恢复。 + +#### 语法: + +```SQL +stopRepairDataStatement + : STOP REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定数据修复的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 + - `ON CLUSTER`:对集群中所有 DataNode 执行。 + +#### 示例: + +```SQL +IoTDB> STOP REPAIR DATA ON CLUSTER; +``` + +## 5. 终止查询 + +### 5.1 主动终止查询 + +**含义**:使用该命令主动地终止查询。 + +#### 语法: + +```SQL +killQueryStatement + : KILL (QUERY queryId=string | ALL QUERIES) + ; +``` + +**参数解释**: + +1. **QUERY queryId=string** + - **含义**:指定要终止的查询的 ID。 `` 是正在执行的查询的唯一标识符。 + - **获取查询 ID**:可以通过 `SHOW QUERIES` 命令获取所有正在执行的查询及其 ID。 +2. **ALL QUERIES** + - **含义**:终止所有正在执行的查询。 + +#### 示例: + +通过指定 `queryId` 可以中止指定的查询,为了获取正在执行的查询 id,用户可以使用 show queries 命令,该命令将显示所有正在执行的查询列表。 + +```SQL +IoTDB> KILL QUERY 20250108_101015_00000_1; -- 终止指定query +IoTDB> KILL ALL QUERIES; -- 终止所有query +``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement_timecho.md b/src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement_timecho.md new file mode 100644 index 000000000..bd526e7fa --- /dev/null +++ b/src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement_timecho.md @@ -0,0 +1,664 @@ + +# 运维语句 + +## 1. 状态查看 + +### 1.1 查看连接的模型 + +**含义**:返回当前连接的 sql_dialect 是树模型/表模型。 + +#### 语法: + +```SQL +showCurrentSqlDialectStatement + : SHOW CURRENT_SQL_DIALECT + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_SQL_DIALECT +``` + +执行结果如下: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` +### 1.2 查看登录的用户名 + +**含义**:返回当前登录的用户名。 + +#### 语法: + +```SQL +showCurrentUserStatement + : SHOW CURRENT_USER + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_USER +``` + +执行结果如下: + +```SQL ++-----------+ +|CurrentUser| ++-----------+ +| root| ++-----------+ +``` + +### 1.3 查看连接的数据库名 + +**含义**:返回当前连接的数据库名,若没有执行过 use 语句,则为 null。 + +#### 语法: + +```SQL +showCurrentDatabaseStatement + : SHOW CURRENT_DATABASE + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_DATABASE; + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; +``` + +执行结果如下: + +```SQL ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + ++---------------+ +|CurrentDatabase| ++---------------+ +| test| ++---------------+ +``` + +### 1.4 查看集群版本 + +**含义**:返回当前集群的版本。 + +#### 语法: + +```SQL +showVersionStatement + : SHOW VERSION + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW VERSION +``` + +执行结果如下: + +```SQL ++-------+---------+ +|Version|BuildInfo| ++-------+---------+ +|2.0.1.2| 1ca4008| ++-------+---------+ +``` + +### 1.5 查看集群关键参数 + +**含义**:返回当前集群的关键参数。 + +#### 语法: + +```SQL +showVariablesStatement + : SHOW VARIABLES + ; +``` + +关键参数如下: + +1. **ClusterName**:当前集群的名称。 +2. **DataReplicationFactor**:数据副本的数量,表示每个数据分区(DataRegion)的副本数。 +3. **SchemaReplicationFactor**:元数据副本的数量,表示每个元数据分区(SchemaRegion)的副本数。 +4. **DataRegionConsensusProtocolClass**:数据分区(DataRegion)使用的共识协议类。 +5. **SchemaRegionConsensusProtocolClass**:元数据分区(SchemaRegion)使用的共识协议类。 +6. **ConfigNodeConsensusProtocolClass**:配置节点(ConfigNode)使用的共识协议类。 +7. **TimePartitionOrigin**:数据库时间分区的起始时间戳。 +8. **TimePartitionInterval**:数据库的时间分区间隔(单位:毫秒)。 +9. **ReadConsistencyLevel**:读取操作的一致性级别。 +10. **SchemaRegionPerDataNode**:数据节点(DataNode)上的元数据分区(SchemaRegion)数量。 +11. **DataRegionPerDataNode**:数据节点(DataNode)上的数据分区(DataRegion)数量。 +12. **SeriesSlotNum**:数据分区(DataRegion)的序列槽(SeriesSlot)数量。 +13. **SeriesSlotExecutorClass**:序列槽的实现类。 +14. **DiskSpaceWarningThreshold**:磁盘空间告警阈值(单位:百分比)。 +15. **TimestampPrecision**:时间戳精度。 + +#### 示例: + +```SQL +IoTDB> SHOW VARIABLES +``` + +执行结果如下: + +```SQL ++----------------------------------+-----------------------------------------------------------------+ +| Variable| Value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 1.6 查看集群ID + +**含义**:返回当前集群的ID。 + +#### 语法: + +```SQL +showClusterIdStatement + : SHOW (CLUSTERID | CLUSTER_ID) + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CLUSTER_ID +``` + +执行结果如下: + +```SQL ++------------------------------------+ +| ClusterId| ++------------------------------------+ +|40163007-9ec1-4455-aa36-8055d740fcda| +``` + +### 1.7 查看客户端直连的 DataNode 进程所在服务器的时间 + +#### 语法: + +**含义**:返回当前客户端直连的 DataNode 进程所在服务器的时间。 + +```SQL +showCurrentTimestampStatement + : SHOW CURRENT_TIMESTAMP + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_TIMESTAMP +``` + +执行结果如下: + +```SQL ++-----------------------------+ +| CurrentTimestamp| ++-----------------------------+ +|2025-02-17T11:11:52.987+08:00| ++-----------------------------+ +``` + +### 1.8 查看正在执行的查询信息 + +**含义**:用于显示所有正在执行的查询信息。 + +> 更多系统表使用方法请参考[系统表](../Reference/System-Tables_timecho.md) + +#### 语法: + +```SQL +showQueriesStatement + : SHOW (QUERIES | QUERY PROCESSLIST) + (WHERE where=booleanExpression)? + (ORDER BY sortItem (',' sortItem)*)? + limitOffsetClause + ; +``` + +**参数解释**: + +1. **WHERE** 子句:需保证过滤的目标列是结果集中存在的列 +2. **ORDER BY** 子句:需保证`sortKey`是结果集中存在的列 +3. **limitOffsetClause**: + - **含义**:用于限制结果集的返回数量。 + - **格式**:`LIMIT , `, `` 是偏移量,`` 是返回的行数。 +4. **QUERIES** 表中的列: + - **query_id**:查询语句的 ID + - **start_time**:查询开始的时间戳,时间戳精度与系统精度一致 + - **datanode_id**:发起查询语句的 DataNode 的ID + - **elapsed_time**:查询的执行耗时,单位是秒 + - **statement**:查询的 SQL 语句 + - **user**:发起查询的用户 + +#### 示例: + +```SQL +IoTDB> SHOW QUERIES WHERE elapsed_time > 30 +``` + +执行结果如下: + +```SQL ++-----------------------+-----------------------------+-----------+------------+------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +``` + +### 1.9 查看分区信息 + +**含义**:返回当前集群的分区信息。 + +#### 语法: + +```SQL +showRegionsStatement + : SHOW REGIONS + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW REGIONS +``` + +执行结果如下: + +```SQL ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | +| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| +| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +``` + + +## 2. 状态设置 + +### 2.1 设置连接的模型 + +**含义**:将当前连接的 sql_dialect 置为树模型/表模型,在树模型和表模型中均可使用该命令。 + +#### 语法: + +```SQL +SET SQL_DIALECT EQ (TABLE | TREE) +``` + +#### 示例: + +```SQL +IoTDB> SET SQL_DIALECT=TABLE +IoTDB> SHOW CURRENT_SQL_DIALECT +``` + +执行结果如下: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 2.2 更新配置项 + +**含义**:用于更新配置项,执行完成后会进行配置项的热加载,对于支持热修改的配置项会立即生效。 + +#### 语法: + +```SQL +setConfigurationStatement + : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? + ; + +propertyAssignments + : property (',' property)* + ; + +property + : identifier EQ propertyValue + ; + +propertyValue + : DEFAULT + | expression + ; +``` + +**参数解释**: + +1. **propertyAssignments** + - **含义**:更新的配置列表,由多个 `property` 组成。 + - 可以更新多个配置列表,用逗号分隔。 + - **取值**: + - `DEFAULT`:将配置项恢复为默认值。 + - `expression`:具体的值,必须是一个字符串。 +2. **ON INTEGER_VALUE** + - **含义**:指定要更新配置的节点 ID。 + - **可选性**:可选。如果不指定或指定的值低于 0,则更新所有 ConfigNode 和 DataNode 的配置。 + +#### 示例: + +```SQL +IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; +``` + +### 2.3 读取手动修改的配置文件 + +**含义**:用于读取手动修改过的配置文件,并对配置项进行热加载,对于支持热修改的配置项会立即生效。 + +#### 语法: + +```SQL +loadConfigurationStatement + : LOAD CONFIGURATION localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定配置热加载的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `LOCAL`:只对客户端直连的 DataNode 进行配置热加载。 + - `CLUSTER`:对集群中所有 DataNode 进行配置热加载。 + +#### 示例: + +```SQL +IoTDB> LOAD CONFIGURATION ON LOCAL; +``` + +### 2.4 设置系统的状态 + +**含义**:用于设置系统的状态。 + +#### 语法: + +```SQL +setSystemStatusStatement + : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **RUNNING | READONLY** + - **含义**:指定系统的新状态。 + - **取值**: + - `RUNNING`:将系统设置为运行状态,允许读写操作。 + - `READONLY`:将系统设置为只读状态,只允许读取操作,禁止写入操作。 +2. **localOrClusterMode** + - **含义**:指定状态变更的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `LOCAL`:仅对客户端直连的 DataNode 生效。 + - `CLUSTER`:对集群中所有 DataNode 生效。 + +#### 示例: + +```SQL +IoTDB> SET SYSTEM TO READONLY ON CLUSTER; +``` + + +## 3. 数据管理 + +### 3.1 刷写内存表中的数据到磁盘 + +**含义**:将内存表中的数据刷写到磁盘上。 + +#### 语法: + +```SQL +flushStatement + : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? + ; + +booleanValue + : TRUE | FALSE + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **identifier** + - **含义**:指定要刷写的数据库名称。 + - **可选性**:可选。如果不指定,则默认刷写所有数据库。 + - **多个数据库**:可以指定多个数据库名称,用逗号分隔。例如:`FLUSH test_db1, test_db2`。 +2. **booleanValue** + - **含义**:指定刷写的内容。 + - **可选性**:可选。如果不指定,则默认刷写顺序和乱序空间的内存。 + - **取值**: + - `TRUE`:只刷写顺序空间的内存表。 + - `FALSE`:只刷写乱序空间的MemTable。 +3. **localOrClusterMode** + - **含义**:指定刷写的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:只刷写客户端直连的 DataNode 上的内存表。 + - `ON CLUSTER`:刷写集群中所有 DataNode 上的内存表。 + +#### 示例: + +```SQL +IoTDB> FLUSH test_db TRUE ON LOCAL; +``` + +### 3.2 清除 DataNode 上的缓存 + +**含义**:用于清除 DataNode 上的某种类型的缓存。 + +#### 语法: + +```SQL +clearCacheStatement + : CLEAR clearCacheOptions? CACHE localOrClusterMode? + ; + +clearCacheOptions + : ATTRIBUTE + | QUERY + | ALL + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **clearCacheOptions** + - **含义**:指定要清除的缓存类型。 + - **可选性**:可选。如果不指定,默认清除查询缓存(`QUERY`)。 + - **取值**: + - `ATTRIBUTE`:清除设备属性缓存。 + - `QUERY`:清除存储引擎中的查询缓存。 + - `ALL`:清除所有缓存,包括设备属性缓存、查询缓存以及树模型中的模式缓存。 +2. **localOrClusterMode** + - **含义**:指定清除缓存的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:只清除客户端直连的 DataNode 上的缓存。 + - `ON CLUSTER`:清除集群中所有 DataNode 上的缓存。 + +#### 示例: + +```SQL +IoTDB> CLEAR ALL CACHE ON LOCAL; +``` + +## 4. 数据修复 + +### 4.1 启动后台扫描并修复 tsfile 任务 + +**含义**:启动一个后台任务,开始扫描并修复 tsfile,能够修复数据文件内的时间戳乱序类异常。 + +#### 语法: + +```SQL +startRepairDataStatement + : START REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定数据修复的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 + - `ON CLUSTER`:对集群中所有 DataNode 执行。 + +#### 示例: + +```SQL +IoTDB> START REPAIR DATA ON CLUSTER; +``` + +### 4.2 暂停后台修复 tsfile 任务 + +**含义**:暂停后台的修复任务,暂停中的任务可通过再次执行 start repair data 命令恢复。 + +#### 语法: + +```SQL +stopRepairDataStatement + : STOP REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定数据修复的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 + - `ON CLUSTER`:对集群中所有 DataNode 执行。 + +#### 示例: + +```SQL +IoTDB> STOP REPAIR DATA ON CLUSTER; +``` + +## 5. 终止查询 + +### 5.1 主动终止查询 + +**含义**:使用该命令主动地终止查询。 + +#### 语法: + +```SQL +killQueryStatement + : KILL (QUERY queryId=string | ALL QUERIES) + ; +``` + +**参数解释**: + +1. **QUERY queryId=string** + - **含义**:指定要终止的查询的 ID。 `` 是正在执行的查询的唯一标识符。 + - **获取查询 ID**:可以通过 `SHOW QUERIES` 命令获取所有正在执行的查询及其 ID。 +2. **ALL QUERIES** + - **含义**:终止所有正在执行的查询。 + +#### 示例: + +通过指定 `queryId` 可以中止指定的查询,为了获取正在执行的查询 id,用户可以使用 show queries 命令,该命令将显示所有正在执行的查询列表。 + +```SQL +IoTDB> KILL QUERY 20250108_101015_00000_1; -- 终止指定query +IoTDB> KILL ALL QUERIES; -- 终止所有query +``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table_apache.md b/src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table_apache.md new file mode 100644 index 000000000..06b2e5b62 --- /dev/null +++ b/src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table_apache.md @@ -0,0 +1,579 @@ + +# 树转表视图 + +## 1. 功能概述 + +IoTDB 提供了树转表功能,支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理: + +* 数据写入阶段,采用树模型语法,支持数据灵活接入和扩展。 +* 数据分析阶段,采用表模型语法,支持通过标准 SQL 查询语言,执行复杂的数据分析。 + +![](/img/tree-to-table-1.png) + +> - V2.0.5 及以后版本支持该功能。 +> - 表视图只读,不允许通过表视图写入数据。 + +## 2. 功能介绍 +### 2.1 创建表视图 +#### 2.1.1 语法定义 + +```SQL +-- create (or replace) view on tree +CREATE + [OR REPLACE] + VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) + [comment] + [RESTRICT] + [WITH properties] + AS prefixPath + +viewColumnDefinition + : column_name [dataType] TAG [comment] # tagColumn + | column_name [dataType] TIME [comment] # timeColumn + | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn + ; + +comment + : COMMENT string + ; +``` + +> 注意:列仅支持 tag / field / time,不支持 attribute。 + +#### 2.1.2 语法说明 +1. **`prefixPath`** + +对应树模型的路径,路径最后一级必须为 `**`,且其他层级均不能出现 `*` 或 `**`。该路径确定 VIEW 对应的子树。 + +2. **`view_name`** + +视图名称,与表名相同(具体约束可参考[创建表](../Basic-Concept/Table-Management_apache.md#\_1-1-创建表)),如 db.view。 + +3. **`viewColumnDefinition`** + +* `TAG`:每个 Tag 列按顺序对应`prefixPath`后面层级的路径节点。 +* `FIELD`:FIELD 列对应树模型中的测点(叶子节点)。 + * 若指定了 FIELD 列,则列名使用声明中的`column_name`。 + * 若声明了 `original_measurement`,则直接映射到树模型该测点。否则取小写`column_name` 作为测点名进行树模型映射。 + * 不支持多个 FIELD 映射到树模型同名测点。 + * 若未指定 FIELD 列的 `dataType`,则默认获取树模型映射测点的数据类型。 + * 若树模型中的设备不包含某些声明的 FIELD 列,或与声明的 FIELD 列的数据类型不一致,则在查询该设备时,该 FIELD 列的值永远为 NULL。 + * 若未指定 FIELD 列,则创建时会自动扫描出`prefixPath`子树下所有的测点(包括定义为所有普通序列的测点,以及挂载路径与 `prefixPath `有所重合的所有模板中的测点),列名使用树模型测点名称。 + * 不支持树模型存在名称(含小写)相同但类型不同的测点 + +4. **`WITH properties`** + +目前仅支持 TTL,表示该视图 TTL ms 之前的数据不会在查询时展示,即`WHERE time > now() - TTL`。若树模型设置了 TTL,则查询时取两者中的更小值。 + +> 注意:表视图 TTL 不影响树模型中设备的真实 TTL,当设备数据达到树模型设定的 TTL 后,将被系统物理删除。 + +5. **`OR REPLACE`** + +table 与 view 不能重名。创建时若已存在同名 table ,则会报错;若已存在同名 view ,则进行替换。 + +6. **`RESTRICT`** + +约束匹配树模型设备的层级数(从 prefixPath 下一层开始),若有 RESTRICT 字段,则匹配层级完全等于 tag 数量的 device,否则匹配层级小于等于 tag 数量的 device。默认非 RESTRICT,即匹配层级小于等于 tag 数量的 device。 + +#### 2.1.3 使用示例 +1. 树模型及表视图原型 + +![](/img/tree-to-table-2.png) + +2. 创建表视图 + +* 创建语句 + +```SQL +CREATE OR REPLACE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +with (ttl=604800000) +AS root.db.** +``` + +* 具体说明 + +该语句表示,创建出名为 `viewdb."风机表"` 的视图(viewdb 如不存在会报错),如果该视图已存在,则替换该视图: + +* 为挂载于树模型 root.db.\*\* 路径下面的序列创建表视图。 +* 具备`风机组`、`风机号`两个 `TAG` 列,因此表视图中只包含原树模型中第 3 层上的设备。 +* 具备`电压`、`电流`两个 `FIELD` 列。这里两个 `FIELD` 列对应树模型下的序列名同样是`电压`、`电流`,且仅仅选取类型为 `DOUBLE` 的序列。 + + **​序列名的改名需求:​**如果树模型下的序列名为`current`,想要创建出的表视图中对应的 `FIELD` 列名为`电流`,这种情况下,SQL 变更如下: + + ```SQL + CREATE OR REPLACE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD FROM current + ) + AS root.db.** + with (ttl=604800000) + ``` + +### 2.2 修改表视图 +#### 2.2.1 语法定义 + +修改表视图功能支持修改视图名称、添加列、列重命名、删除列、设置视图的 TTL 属性,以及通过 COMMENT 添加注释。 + +```SQL +-- 修改视图名 +ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier + +-- 在视图中添加某一列 +ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition +viewColumnDefinition + : column_name [dataType] TAG # tagColumn + | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn + +-- 为视图中的某一列重命名 +ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName + +-- 删除视图中的某一列 +ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName + +-- 修改视图的 TTL +ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments + +-- 添加注释 +COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView +COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn +``` + +#### 2.2.2 语法说明 +1. `SET PROPERTIES`操作目前仅支持对表视图的 TTL 属性进行配置。 +2. 删除列功能,仅支持删除物理量列(FIELD),标识列(TAG)不支持删除。 +3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 +#### 2.2.3 使用示例 + +```SQL +-- 修改视图名 +ALTER VIEW IF EXISTS tableview1 RENAME TO tableview + +-- 在视图中添加某一列 +ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field + +-- 为视图中的某一列重命名 +ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp + +-- 删除视图中的某一列 +ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp + +-- 修改视图的 TTL +ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 + +-- 添加注释 +COMMENT ON VIEW tableview IS '树转表' +COMMENT ON COLUMN tableview.status is Null +``` + +### 2.3 删除表视图 +#### 2.3.1 语法定义 + +```SQL +DROP VIEW [IF EXISTS] viewName +``` + +#### 2.3.2 使用示例 + +```SQL +DROP VIEW IF EXISTS tableview +``` + +### 2.4 查看表视图 +#### 2.4.1 **`Show Tables`** +1. 语法定义 + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +2. 语法说明 + +`SHOW TABLES (DETAILS)` 语句通过结果集的`TABLE_TYPE`字段展示表或视图的类型信息: + +| 类型 | `TABLE_TYPE`字段值 | +| -------------------------------------- | ------------------------ | +| 普通表(Table) | `BASE TABLE` | +| 树转表视图(Tree View) | `VIEW FROM TREE` | +| 系统表(Iinformation\_schema.Tables) | `SYSTEM VIEW` | + +3. 使用示例 + +```SQL +IoTDB> show tables details from database1 ++-----------+-----------+------+-------+--------------+ +| TableName| TTL(ms)|Status|Comment| TableType| ++-----------+-----------+------+-------+--------------+ +| tableview| INF| USING| 树转表 |VIEW FROM TREE| +| table1|31536000000| USING| null| BASE TABLE| +| table2|31536000000| USING| null| BASE TABLE| ++-----------+-----------+------+-------+--------------+ + +IoTDB> show tables details from information_schema ++--------------+-------+------+-------+-----------+ +| TableName|TTL(ms)|Status|Comment| TableType| ++--------------+-------+------+-------+-----------+ +| columns| INF| USING| null|SYSTEM VIEW| +| config_nodes| INF| USING| null|SYSTEM VIEW| +|configurations| INF| USING| null|SYSTEM VIEW| +| data_nodes| INF| USING| null|SYSTEM VIEW| +| databases| INF| USING| null|SYSTEM VIEW| +| functions| INF| USING| null|SYSTEM VIEW| +| keywords| INF| USING| null|SYSTEM VIEW| +| models| INF| USING| null|SYSTEM VIEW| +| nodes| INF| USING| null|SYSTEM VIEW| +| pipe_plugins| INF| USING| null|SYSTEM VIEW| +| pipes| INF| USING| null|SYSTEM VIEW| +| queries| INF| USING| null|SYSTEM VIEW| +| regions| INF| USING| null|SYSTEM VIEW| +| subscriptions| INF| USING| null|SYSTEM VIEW| +| tables| INF| USING| null|SYSTEM VIEW| +| topics| INF| USING| null|SYSTEM VIEW| +| views| INF| USING| null|SYSTEM VIEW| ++--------------+-------+------+-------+-----------+ +``` + +#### 2.4.2 **`Show Create Table/View`** +1. 语法定义 + +```SQL +SHOW CREATE TABLE|VIEW viewname; +``` + +2. 语法说明 + +* SHOW CREATE TABLE 语句可用于展示普通表或者视图的完整创建信息; +* SHOW CREATE VIEW 语句仅可用于展示视图的完整创建信息; +* 两种语句均不支持用于展示系统表; + +3. 使用示例 + +```SQL +IoTDB> show create table tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +IoTDB> show create view tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +``` + +### 2.5 非对齐与对齐设备的查询差异 + +树转表视图在查询对齐设备和非对齐设备中有 null 值的情况下结果​**可能与等价的树模型 align by device 查询不同**​。 + +* **对齐设备** + * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 + * 表视图的查询表现:与表模型一致,保留全是 null 的行 +* **非对齐设备** + * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 + * 表视图的查询表现:与树模型一致,不保留全是 null 的行 +* **说明示例** + * 对齐 + + ```SQL + -- 树模型写入数据(对齐) + CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) + + -- 创建 VIEW 语句 + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- 查询 + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + | null| + +-------+ + Total line number = 2 + ``` + + * 非对齐 + + ```SQL + -- 树模型写入数据(非对齐) + CREATE TIMESERIES root.db.battery.b1.voltage INT32 + CREATE TIMESERIES root.db.battery.b1.current FLOAT + INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) + + -- 创建 VIEW 语句 + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- 查询 + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + +-------+ + Total line number = 1 + + -- 如果在查询语句中指定了所有 field 列,或是仅指定了非 field 列时,才可以确保查到所有行 + IoTDB> select voltage,current from view1 + +-------+-------+ + |voltage|current| + +-------+-------+ + | 1| 1.0| + | null| 1.0| + +-------+-------+ + Total line number = 2 + + IoTDB> select battery_id from view1 + +-------+ + |battery_id| + +-------+ + | b1| + | b1| + +-------+ + Total line number = 2 + + -- 如果查询中同时有部分 field 列,那最终结果的行数取决于这部分 field 列根据时间戳对齐后的行数 + IoTDB> select time,voltage from view1 + +-----------------------------+-------+ + | time|voltage| + +-----------------------------+-------+ + |1970-01-01T08:00:00.001+08:00| 1| + +-----------------------------+-------+ + Total line number = 1 + ``` + +## 3. 场景示例 +### 3.1 原树模型管理了多种类型的设备 + +* 场景中不同类型的设备具备不同的层级路径和测点集合。 +* ​**写入时**​:在数据库节点下按设备类型创建分支,每种设备下可以有不同的测点结构 +* ​**查询时**​:为每种类型的设备建立一张表,每个表具有不同的标签和测点集合 + +![](/img/tree-to-table-3.png) + +**表视图的创建 SQL:** + +```SQL +-- 风机表 +CREATE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +AS root.db."风机".** + +-- 电机表 +CREATE VIEW viewdb."电机表" + ("电机组" TAG, + "电机号" TAG, + "功率" FLOAT FIELD, + "电量" FLOAT FIELD, + "温度" FLOAT FIELD + ) +AS root.db."电机".** +``` + +### 3.2 原树模型中没有设备,只有测点 + +如场站的监控系统中,每个测点都有唯一编号,但无法对应到某些设备 + +> 大宽表形式 + +![](/img/tree-to-table-4.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine + (DCS_PIT_02105A DOUBLE FIELD, + DCS_PIT_02105B DOUBLE FIELD, + DCS_PIT_02105C DOUBLE FIELD, + ... + DCS_XI_02716A DOUBLE FIELD + ) +AS root.db.** +``` + +### 3.3 原树模型中一个设备既有子设备,也有测点 + +如在储能场景中,每一层结构都要监控其电压和电流 + +* ​**写入时**​:按照物理世界的监测点,对每一层结构进行建模 +* ​**查询时**​:按照设备分类,建立多个表对每一层结构信息进行管理 + +![](/img/tree-to-table-5.png) + +**表视图的创建 SQL:** + +```SQL +-- 电池舱表 +CREATE VIEW viewdb."电池舱表" + ("电池站" TAG, + "电池舱" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- 电池堆表 +CREATE VIEW viewdb."电池堆表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- 电池簇表 +CREATE VIEW viewdb."电池簇表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电池簇" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS 'root.db.**' + +-- 电芯表 +CREATE VIEW viewdb."电芯表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电池簇" TAG, + "电芯" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** +``` + +### 3.4 原树模型中一个设备下只有一个测点 + +> 窄表形式 + +#### 3.4.1 所有测点数据类型相同 + +![](/img/tree-to-table-6.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** +``` + +#### 3.4.2 测点的数据类型不相同 +##### 3.4.2.1 为每一种数据类型的测点建一个窄表视图 + +​**优点**​:表视图数量是常数个,仅与系统中的数据类型相关 + +​**缺点**​:查询某一个测点值时,需要提前知道其数据类型,再去决定查询哪张表视图 + +![](/img/tree-to-table-7.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine_float + ( + sensor_id STRING TAG, + value FLOAT FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_double + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int32 + ( + sensor_id STRING TAG, + value INT32 FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int64 + ( + sensor_id STRING TAG, + value INT64 FIELD + ) +AS root.db.** + +... +``` + +##### 3.4.2.2 为每一个测点建一个表 + +​**优点**​:查询某一个测点值时,不需要先查一下数据类型,再去决定查询哪张表,简单便捷 + +​**缺点**​:当测点数量较多时,会引入过多的表视图,需要写大量的建视图语句 + +![](/img/tree-to-table-8.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.DCS_PIT_02105A + ( + value FLOAT FIELD + ) +AS root.db.DCS_PIT_02105A.** + +CREATE VIEW viewdb.DCS_PIT_02105B + ( + value DOUBLE FIELD + ) +AS root.db.DCS_PIT_02105B.** + +CREATE VIEW viewdb.DCS_XI_02716A + ( + value INT64 FIELD + ) +AS root.db.DCS_XI_02716A.** + +...... +``` diff --git a/src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table_timecho.md b/src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table_timecho.md new file mode 100644 index 000000000..75378e3c5 --- /dev/null +++ b/src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table_timecho.md @@ -0,0 +1,579 @@ + +# 树转表视图 + +## 1. 功能概述 + +IoTDB 提供了树转表功能,支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理: + +* 数据写入阶段,采用树模型语法,支持数据灵活接入和扩展。 +* 数据分析阶段,采用表模型语法,支持通过标准 SQL 查询语言,执行复杂的数据分析。 + +![](/img/tree-to-table-1.png) + +> - V2.0.5 及以后版本支持该功能。 +> - 表视图只读,不允许通过表视图写入数据。 + +## 2. 功能介绍 +### 2.1 创建表视图 +#### 2.1.1 语法定义 + +```SQL +-- create (or replace) view on tree +CREATE + [OR REPLACE] + VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) + [comment] + [RESTRICT] + [WITH properties] + AS prefixPath + +viewColumnDefinition + : column_name [dataType] TAG [comment] # tagColumn + | column_name [dataType] TIME [comment] # timeColumn + | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn + ; + +comment + : COMMENT string + ; +``` + +> 注意:列仅支持 tag / field / time,不支持 attribute。 + +#### 2.1.2 语法说明 +1. **`prefixPath`** + +对应树模型的路径,路径最后一级必须为 `**`,且其他层级均不能出现 `*` 或 `**`。该路径确定 VIEW 对应的子树。 + +2. **`view_name`** + +视图名称,与表名相同(具体约束可参考[创建表](../Basic-Concept/Table-Management_timecho.md#\_1-1-创建表)),如 db.view。 + +3. **`viewColumnDefinition`** + +* `TAG`:每个 Tag 列按顺序对应`prefixPath`后面层级的路径节点。 +* `FIELD`:FIELD 列对应树模型中的测点(叶子节点)。 + * 若指定了 FIELD 列,则列名使用声明中的`column_name`。 + * 若声明了 `original_measurement`,则直接映射到树模型该测点。否则取小写`column_name` 作为测点名进行树模型映射。 + * 不支持多个 FIELD 映射到树模型同名测点。 + * 若未指定 FIELD 列的 `dataType`,则默认获取树模型映射测点的数据类型。 + * 若树模型中的设备不包含某些声明的 FIELD 列,或与声明的 FIELD 列的数据类型不一致,则在查询该设备时,该 FIELD 列的值永远为 NULL。 + * 若未指定 FIELD 列,则创建时会自动扫描出`prefixPath`子树下所有的测点(包括定义为所有普通序列的测点,以及挂载路径与 `prefixPath `有所重合的所有模板中的测点),列名使用树模型测点名称。 + * 不支持树模型存在名称(含小写)相同但类型不同的测点 + +4. **`WITH properties`** + +目前仅支持 TTL,表示该视图 TTL ms 之前的数据不会在查询时展示,即`WHERE time > now() - TTL`。若树模型设置了 TTL,则查询时取两者中的更小值。 + +> 注意:表视图 TTL 不影响树模型中设备的真实 TTL,当设备数据达到树模型设定的 TTL 后,将被系统物理删除。 + +5. **`OR REPLACE`** + +table 与 view 不能重名。创建时若已存在同名 table ,则会报错;若已存在同名 view ,则进行替换。 + +6. **`RESTRICT`** + +约束匹配树模型设备的层级数(从 prefixPath 下一层开始),若有 RESTRICT 字段,则匹配层级完全等于 tag 数量的 device,否则匹配层级小于等于 tag 数量的 device。默认非 RESTRICT,即匹配层级小于等于 tag 数量的 device。 + +#### 2.1.3 使用示例 +1. 树模型及表视图原型 + +![](/img/tree-to-table-2.png) + +2. 创建表视图 + +* 创建语句 + +```SQL +CREATE OR REPLACE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +with (ttl=604800000) +AS root.db.** +``` + +* 具体说明 + +该语句表示,创建出名为 `viewdb."风机表"` 的视图(viewdb 如不存在会报错),如果该视图已存在,则替换该视图: + +* 为挂载于树模型 root.db.\*\* 路径下面的序列创建表视图。 +* 具备`风机组`、`风机号`两个 `TAG` 列,因此表视图中只包含原树模型中第 3 层上的设备。 +* 具备`电压`、`电流`两个 `FIELD` 列。这里两个 `FIELD` 列对应树模型下的序列名同样是`电压`、`电流`,且仅仅选取类型为 `DOUBLE` 的序列。 + + **​序列名的改名需求:​**如果树模型下的序列名为`current`,想要创建出的表视图中对应的 `FIELD` 列名为`电流`,这种情况下,SQL 变更如下: + + ```SQL + CREATE OR REPLACE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD FROM current + ) + AS root.db.** + with (ttl=604800000) + ``` + +### 2.2 修改表视图 +#### 2.2.1 语法定义 + +修改表视图功能支持修改视图名称、添加列、列重命名、删除列、设置视图的 TTL 属性,以及通过 COMMENT 添加注释。 + +```SQL +-- 修改视图名 +ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier + +-- 在视图中添加某一列 +ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition +viewColumnDefinition + : column_name [dataType] TAG # tagColumn + | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn + +-- 为视图中的某一列重命名 +ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName + +-- 删除视图中的某一列 +ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName + +-- 修改视图的 TTL +ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments + +-- 添加注释 +COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView +COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn +``` + +#### 2.2.2 语法说明 +1. `SET PROPERTIES`操作目前仅支持对表视图的 TTL 属性进行配置。 +2. 删除列功能,仅支持删除物理量列(FIELD),标识列(TAG)不支持删除。 +3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 +#### 2.2.3 使用示例 + +```SQL +-- 修改视图名 +ALTER VIEW IF EXISTS tableview1 RENAME TO tableview + +-- 在视图中添加某一列 +ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field + +-- 为视图中的某一列重命名 +ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp + +-- 删除视图中的某一列 +ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp + +-- 修改视图的 TTL +ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 + +-- 添加注释 +COMMENT ON VIEW tableview IS '树转表' +COMMENT ON COLUMN tableview.status is Null +``` + +### 2.3 删除表视图 +#### 2.3.1 语法定义 + +```SQL +DROP VIEW [IF EXISTS] viewName +``` + +#### 2.3.2 使用示例 + +```SQL +DROP VIEW IF EXISTS tableview +``` + +### 2.4 查看表视图 +#### 2.4.1 **`Show Tables`** +1. 语法定义 + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +2. 语法说明 + +`SHOW TABLES (DETAILS)` 语句通过结果集的`TABLE_TYPE`字段展示表或视图的类型信息: + +| 类型 | `TABLE_TYPE`字段值 | +| -------------------------------------- | ------------------------ | +| 普通表(Table) | `BASE TABLE` | +| 树转表视图(Tree View) | `VIEW FROM TREE` | +| 系统表(Iinformation\_schema.Tables) | `SYSTEM VIEW` | + +3. 使用示例 + +```SQL +IoTDB> show tables details from database1 ++-----------+-----------+------+-------+--------------+ +| TableName| TTL(ms)|Status|Comment| TableType| ++-----------+-----------+------+-------+--------------+ +| tableview| INF| USING| 树转表 |VIEW FROM TREE| +| table1|31536000000| USING| null| BASE TABLE| +| table2|31536000000| USING| null| BASE TABLE| ++-----------+-----------+------+-------+--------------+ + +IoTDB> show tables details from information_schema ++--------------+-------+------+-------+-----------+ +| TableName|TTL(ms)|Status|Comment| TableType| ++--------------+-------+------+-------+-----------+ +| columns| INF| USING| null|SYSTEM VIEW| +| config_nodes| INF| USING| null|SYSTEM VIEW| +|configurations| INF| USING| null|SYSTEM VIEW| +| data_nodes| INF| USING| null|SYSTEM VIEW| +| databases| INF| USING| null|SYSTEM VIEW| +| functions| INF| USING| null|SYSTEM VIEW| +| keywords| INF| USING| null|SYSTEM VIEW| +| models| INF| USING| null|SYSTEM VIEW| +| nodes| INF| USING| null|SYSTEM VIEW| +| pipe_plugins| INF| USING| null|SYSTEM VIEW| +| pipes| INF| USING| null|SYSTEM VIEW| +| queries| INF| USING| null|SYSTEM VIEW| +| regions| INF| USING| null|SYSTEM VIEW| +| subscriptions| INF| USING| null|SYSTEM VIEW| +| tables| INF| USING| null|SYSTEM VIEW| +| topics| INF| USING| null|SYSTEM VIEW| +| views| INF| USING| null|SYSTEM VIEW| ++--------------+-------+------+-------+-----------+ +``` + +#### 2.4.2 **`Show Create Table/View`** +1. 语法定义 + +```SQL +SHOW CREATE TABLE|VIEW viewname; +``` + +2. 语法说明 + +* SHOW CREATE TABLE 语句可用于展示普通表或者视图的完整创建信息; +* SHOW CREATE VIEW 语句仅可用于展示视图的完整创建信息; +* 两种语句均不支持用于展示系统表; + +3. 使用示例 + +```SQL +IoTDB> show create table tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +IoTDB> show create view tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +``` + +### 2.5 非对齐与对齐设备的查询差异 + +树转表视图在查询对齐设备和非对齐设备中有 null 值的情况下结果​**可能与等价的树模型 align by device 查询不同**​。 + +* **对齐设备** + * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 + * 表视图的查询表现:与表模型一致,保留全是 null 的行 +* **非对齐设备** + * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 + * 表视图的查询表现:与树模型一致,不保留全是 null 的行 +* **说明示例** + * 对齐 + + ```SQL + -- 树模型写入数据(对齐) + CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) + + -- 创建 VIEW 语句 + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- 查询 + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + | null| + +-------+ + Total line number = 2 + ``` + + * 非对齐 + + ```SQL + -- 树模型写入数据(非对齐) + CREATE TIMESERIES root.db.battery.b1.voltage INT32 + CREATE TIMESERIES root.db.battery.b1.current FLOAT + INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) + + -- 创建 VIEW 语句 + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- 查询 + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + +-------+ + Total line number = 1 + + -- 如果在查询语句中指定了所有 field 列,或是仅指定了非 field 列时,才可以确保查到所有行 + IoTDB> select voltage,current from view1 + +-------+-------+ + |voltage|current| + +-------+-------+ + | 1| 1.0| + | null| 1.0| + +-------+-------+ + Total line number = 2 + + IoTDB> select battery_id from view1 + +-------+ + |battery_id| + +-------+ + | b1| + | b1| + +-------+ + Total line number = 2 + + -- 如果查询中同时有部分 field 列,那最终结果的行数取决于这部分 field 列根据时间戳对齐后的行数 + IoTDB> select time,voltage from view1 + +-----------------------------+-------+ + | time|voltage| + +-----------------------------+-------+ + |1970-01-01T08:00:00.001+08:00| 1| + +-----------------------------+-------+ + Total line number = 1 + ``` + +## 3. 场景示例 +### 3.1 原树模型管理了多种类型的设备 + +* 场景中不同类型的设备具备不同的层级路径和测点集合。 +* ​**写入时**​:在数据库节点下按设备类型创建分支,每种设备下可以有不同的测点结构 +* ​**查询时**​:为每种类型的设备建立一张表,每个表具有不同的标签和测点集合 + +![](/img/tree-to-table-3.png) + +**表视图的创建 SQL:** + +```SQL +-- 风机表 +CREATE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +AS root.db."风机".** + +-- 电机表 +CREATE VIEW viewdb."电机表" + ("电机组" TAG, + "电机号" TAG, + "功率" FLOAT FIELD, + "电量" FLOAT FIELD, + "温度" FLOAT FIELD + ) +AS root.db."电机".** +``` + +### 3.2 原树模型中没有设备,只有测点 + +如场站的监控系统中,每个测点都有唯一编号,但无法对应到某些设备 + +> 大宽表形式 + +![](/img/tree-to-table-4.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine + (DCS_PIT_02105A DOUBLE FIELD, + DCS_PIT_02105B DOUBLE FIELD, + DCS_PIT_02105C DOUBLE FIELD, + ... + DCS_XI_02716A DOUBLE FIELD + ) +AS root.db.** +``` + +### 3.3 原树模型中一个设备既有子设备,也有测点 + +如在储能场景中,每一层结构都要监控其电压和电流 + +* ​**写入时**​:按照物理世界的监测点,对每一层结构进行建模 +* ​**查询时**​:按照设备分类,建立多个表对每一层结构信息进行管理 + +![](/img/tree-to-table-5.png) + +**表视图的创建 SQL:** + +```SQL +-- 电池舱表 +CREATE VIEW viewdb."电池舱表" + ("电池站" TAG, + "电池舱" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- 电池堆表 +CREATE VIEW viewdb."电池堆表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- 电池簇表 +CREATE VIEW viewdb."电池簇表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电池簇" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS 'root.db.**' + +-- 电芯表 +CREATE VIEW viewdb."电芯表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电池簇" TAG, + "电芯" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** +``` + +### 3.4 原树模型中一个设备下只有一个测点 + +> 窄表形式 + +#### 3.4.1 所有测点数据类型相同 + +![](/img/tree-to-table-6.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** +``` + +#### 3.4.2 测点的数据类型不相同 +##### 3.4.2.1 为每一种数据类型的测点建一个窄表视图 + +​**优点**​:表视图数量是常数个,仅与系统中的数据类型相关 + +​**缺点**​:查询某一个测点值时,需要提前知道其数据类型,再去决定查询哪张表视图 + +![](/img/tree-to-table-7.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine_float + ( + sensor_id STRING TAG, + value FLOAT FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_double + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int32 + ( + sensor_id STRING TAG, + value INT32 FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int64 + ( + sensor_id STRING TAG, + value INT64 FIELD + ) +AS root.db.** + +... +``` + +##### 3.4.2.2 为每一个测点建一个表 + +​**优点**​:查询某一个测点值时,不需要先查一下数据类型,再去决定查询哪张表,简单便捷 + +​**缺点**​:当测点数量较多时,会引入过多的表视图,需要写大量的建视图语句 + +![](/img/tree-to-table-8.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.DCS_PIT_02105A + ( + value FLOAT FIELD + ) +AS root.db.DCS_PIT_02105A.** + +CREATE VIEW viewdb.DCS_PIT_02105B + ( + value DOUBLE FIELD + ) +AS root.db.DCS_PIT_02105B.** + +CREATE VIEW viewdb.DCS_XI_02716A + ( + value INT64 FIELD + ) +AS root.db.DCS_XI_02716A.** + +...... +``` diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md new file mode 100644 index 000000000..668d44e95 --- /dev/null +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md @@ -0,0 +1,191 @@ + + +# 数据库管理 + +## 1. 数据库管理 + +### 1.1 创建数据库 + +用于创建数据库。 + +**语法:** + +```SQL + CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +**说明:** + +1. 数据库名称,具有以下特性: + - 大小写不敏感,创建成功后,统一显示为小写 + - 名称的长度不得超过 64 个字符。 + - 名称中包含下划线(_)、数字(非开头)、英文字母可以直接创建 + - 名称中包含特殊字符(如`)、中文字符、数字开头时,必须用双引号 "" 括起来。 + +2. WITH properties 子句可配置如下属性: + +> 注:属性的大小写不敏感,有关详细信息[大小写敏感规则](../SQL-Manual/Identifier.md#大小写敏感性)。 + +| 属性 | 含义 | 默认值 | +| ------------------------- | ---------------------------------------- | --------- | +| `TTL` | 数据自动过期删除,单位 ms | INF | +| `TIME_PARTITION_INTERVAL` | 数据库的时间分区间隔,单位 ms | 604800000 | +| `SCHEMA_REGION_GROUP_NUM` | 数据库的元数据副本组数量,一般不需要修改 | 1 | +| `DATA_REGION_GROUP_NUM` | 数据库的数据副本组数量,一般不需要修改 | 2 | + +**示例:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +// 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 使用数据库 + +用于指定当前数据库作为表的命名空间。 + +**语法:** + +```SQL +USE +``` + +**示例:** + +```SQL +USE database1 +``` + +### 1.3 查看当前数据库 + +返回当前会话所连接的数据库名称,若未执行过 `use`语句指定数据库,则默认为 `null`。 + +**语法:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**示例:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 查看所有数据库 + +用于查看所有数据库和数据库的属性信息。 + +**语法:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +**语句返回列含义如下:** + +| 列名 | 含义 | +| ----------------------- | ------------------------------------------------------------ | +| database | database名称。 | +| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management.md#14-修改表) 来设置或更新表的TTL时间。 | +| SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | +| DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | +| TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | +| SchemaRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的元数据副本组数量,一般不需要修改 | +| DataRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的数据副本组数量,一般不需要修改 | + +**示例:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 修改数据库 + +用于修改数据库中的部分属性。 + +**语法:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**说明:** + +1. `ALTER DATABASE`操作目前仅支持对数据库的`SCHEMA_REGION_GROUP_NUM`、`DATA_REGION_GROUP_NUM`以及`TTL`属性进行修改。 + +**示例:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 删除数据库 + +用于删除数据库。 + +**语法:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**说明:** + +1. 数据库已被设置为当前使用(use)的数据库,仍然可以被删除(drop)。 +2. 删除数据库将导致所选数据库及其内所有表连同其存储的数据一并被删除。 + +**示例:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md new file mode 100644 index 000000000..668d44e95 --- /dev/null +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md @@ -0,0 +1,191 @@ + + +# 数据库管理 + +## 1. 数据库管理 + +### 1.1 创建数据库 + +用于创建数据库。 + +**语法:** + +```SQL + CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +**说明:** + +1. 数据库名称,具有以下特性: + - 大小写不敏感,创建成功后,统一显示为小写 + - 名称的长度不得超过 64 个字符。 + - 名称中包含下划线(_)、数字(非开头)、英文字母可以直接创建 + - 名称中包含特殊字符(如`)、中文字符、数字开头时,必须用双引号 "" 括起来。 + +2. WITH properties 子句可配置如下属性: + +> 注:属性的大小写不敏感,有关详细信息[大小写敏感规则](../SQL-Manual/Identifier.md#大小写敏感性)。 + +| 属性 | 含义 | 默认值 | +| ------------------------- | ---------------------------------------- | --------- | +| `TTL` | 数据自动过期删除,单位 ms | INF | +| `TIME_PARTITION_INTERVAL` | 数据库的时间分区间隔,单位 ms | 604800000 | +| `SCHEMA_REGION_GROUP_NUM` | 数据库的元数据副本组数量,一般不需要修改 | 1 | +| `DATA_REGION_GROUP_NUM` | 数据库的数据副本组数量,一般不需要修改 | 2 | + +**示例:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +// 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 使用数据库 + +用于指定当前数据库作为表的命名空间。 + +**语法:** + +```SQL +USE +``` + +**示例:** + +```SQL +USE database1 +``` + +### 1.3 查看当前数据库 + +返回当前会话所连接的数据库名称,若未执行过 `use`语句指定数据库,则默认为 `null`。 + +**语法:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**示例:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 查看所有数据库 + +用于查看所有数据库和数据库的属性信息。 + +**语法:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +**语句返回列含义如下:** + +| 列名 | 含义 | +| ----------------------- | ------------------------------------------------------------ | +| database | database名称。 | +| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management.md#14-修改表) 来设置或更新表的TTL时间。 | +| SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | +| DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | +| TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | +| SchemaRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的元数据副本组数量,一般不需要修改 | +| DataRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的数据副本组数量,一般不需要修改 | + +**示例:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 修改数据库 + +用于修改数据库中的部分属性。 + +**语法:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**说明:** + +1. `ALTER DATABASE`操作目前仅支持对数据库的`SCHEMA_REGION_GROUP_NUM`、`DATA_REGION_GROUP_NUM`以及`TTL`属性进行修改。 + +**示例:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 删除数据库 + +用于删除数据库。 + +**语法:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**说明:** + +1. 数据库已被设置为当前使用(use)的数据库,仍然可以被删除(drop)。 +2. 删除数据库将导致所选数据库及其内所有表连同其存储的数据一并被删除。 + +**示例:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md new file mode 100644 index 000000000..9c9f3178d --- /dev/null +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md @@ -0,0 +1,141 @@ + + +# 数据保留时间 + +## 1. 概览 + +IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系统自动定期删除旧数据,以有效控制磁盘空间并维护高性能查询和低内存占用。TTL默认以毫秒为单位,数据过期后不可查询且禁止写入,但物理删除会延迟至压缩时。需注意,TTL变更可能导致短暂数据可查询性变化。 + +**注意事项:** + +1. TTL设置为毫秒,不受配置文件时间精度影响。 +2. TTL变更可能影响数据的可查询性。 +3. 系统最终会移除过期数据,但存在延迟。 +4. TTL 判断数据是否过期依据的是数据点时间,非写入时间。 + +## 2. 设置 TTL + +在表模型中,IoTDB 的 TTL 是按照表的粒度生效的。可以直接在表上设置 TTL,或者在数据库级别设置 TTL。当在数据库级别设置了TTL时,在创建新表的过程中,系统会自动采用这个TTL值作为新表的默认设置,但每个表仍然可以独立地被设置或覆盖该值。 + +注意,如果数据库级别的TTL被修改,不会直接影响到已经存在的表的TTL设置。 + +### 2.1 为表设置 TTL + +如果在建表时通过sql语句设置了表的 TTL,则会以表的ttl为准。建表语句详情可见:[表管理](../Basic-Concept/Table-Management.md) + +示例1:创建表时设置 TTL + +```SQL +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600) +``` + +示例2:更改表语句设置TTL: + +```SQL +ALTER TABLE tableB SET PROPERTIES TTL=3600; +``` + +示例3:不指定TTL或设为默认值,它将与数据库的TTL相同,默认情况下是'INF'(无穷大): + +```SQL +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT) +CREATE TABLE test3 ("场站" string id, "温度" int32) +ALTER TABLE tableB set properties TTL=DEFAULT +``` + +### 2.2 为数据库设置 TTL + +没有设置表的TTL,则会继承database的ttl。建数据库语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md) + +示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) +``` + +示例5:数据库不设置ttl,将生成一个没有ttl的表: + +```SQL +CREATE DATABASE db +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) +``` + +示例6:数据库设置了ttl,但想显式设置没有TTL的表,可以将TTL设置为'INF': + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') +``` + +## 3. 取消 TTL + +取消 TTL 设置,可以修改表的 TTL 设置为 'INF'。目前,IoTDB 不支持修改数据库的 TTL。 + +```SQL +ALTER TABLE tableB set properties TTL='INF' +``` + +## 4. 查看 TTL 信息 + +使用 "SHOW DATABASES" 和 "SHOW TABLES" 命令可以直接显示数据库和表的 TTL 详情。数据库和表管理语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md)、[表管理](../Basic-Concept/Table-Management.md) + +> 注意,树模型数据库的TTL也将显示。 + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 1| 3| 100000| +| test2| 300| 1| 1| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +|test_prop| 300| 1| 3| 100000|TABLE| +| test2| 300| 1| 1| 604800000| TREE| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +IoTDB> show tables ++---------+-------+ +|TableName|TTL(ms)| ++---------+-------+ +| grass| 1000| +| bamboo| 300| +| flower| INF| ++---------+-------+ + +IoTDB> show tables details ++---------+-------+----------+ +|TableName|TTL(ms)| Status| ++---------+-------+----------+ +| bean| 300|PRE_CREATE| +| grass| 1000| USING| +| bamboo| 300| USING| +| flower| INF| USING| ++---------+-------+----------+ +``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md new file mode 100644 index 000000000..9c9f3178d --- /dev/null +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md @@ -0,0 +1,141 @@ + + +# 数据保留时间 + +## 1. 概览 + +IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系统自动定期删除旧数据,以有效控制磁盘空间并维护高性能查询和低内存占用。TTL默认以毫秒为单位,数据过期后不可查询且禁止写入,但物理删除会延迟至压缩时。需注意,TTL变更可能导致短暂数据可查询性变化。 + +**注意事项:** + +1. TTL设置为毫秒,不受配置文件时间精度影响。 +2. TTL变更可能影响数据的可查询性。 +3. 系统最终会移除过期数据,但存在延迟。 +4. TTL 判断数据是否过期依据的是数据点时间,非写入时间。 + +## 2. 设置 TTL + +在表模型中,IoTDB 的 TTL 是按照表的粒度生效的。可以直接在表上设置 TTL,或者在数据库级别设置 TTL。当在数据库级别设置了TTL时,在创建新表的过程中,系统会自动采用这个TTL值作为新表的默认设置,但每个表仍然可以独立地被设置或覆盖该值。 + +注意,如果数据库级别的TTL被修改,不会直接影响到已经存在的表的TTL设置。 + +### 2.1 为表设置 TTL + +如果在建表时通过sql语句设置了表的 TTL,则会以表的ttl为准。建表语句详情可见:[表管理](../Basic-Concept/Table-Management.md) + +示例1:创建表时设置 TTL + +```SQL +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600) +``` + +示例2:更改表语句设置TTL: + +```SQL +ALTER TABLE tableB SET PROPERTIES TTL=3600; +``` + +示例3:不指定TTL或设为默认值,它将与数据库的TTL相同,默认情况下是'INF'(无穷大): + +```SQL +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT) +CREATE TABLE test3 ("场站" string id, "温度" int32) +ALTER TABLE tableB set properties TTL=DEFAULT +``` + +### 2.2 为数据库设置 TTL + +没有设置表的TTL,则会继承database的ttl。建数据库语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md) + +示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) +``` + +示例5:数据库不设置ttl,将生成一个没有ttl的表: + +```SQL +CREATE DATABASE db +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) +``` + +示例6:数据库设置了ttl,但想显式设置没有TTL的表,可以将TTL设置为'INF': + +```SQL +CREATE DATABASE db WITH (ttl=3600000) +use db +CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') +``` + +## 3. 取消 TTL + +取消 TTL 设置,可以修改表的 TTL 设置为 'INF'。目前,IoTDB 不支持修改数据库的 TTL。 + +```SQL +ALTER TABLE tableB set properties TTL='INF' +``` + +## 4. 查看 TTL 信息 + +使用 "SHOW DATABASES" 和 "SHOW TABLES" 命令可以直接显示数据库和表的 TTL 详情。数据库和表管理语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md)、[表管理](../Basic-Concept/Table-Management.md) + +> 注意,树模型数据库的TTL也将显示。 + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 1| 3| 100000| +| test2| 300| 1| 1| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +|test_prop| 300| 1| 3| 100000|TABLE| +| test2| 300| 1| 1| 604800000| TREE| ++---------+-------+-----------------------+---------------------+---------------------+-----+ +IoTDB> show tables ++---------+-------+ +|TableName|TTL(ms)| ++---------+-------+ +| grass| 1000| +| bamboo| 300| +| flower| INF| ++---------+-------+ + +IoTDB> show tables details ++---------+-------+----------+ +|TableName|TTL(ms)| Status| ++---------+-------+----------+ +| bean| 300|PRE_CREATE| +| grass| 1000| USING| +| bamboo| 300| USING| +| flower| INF| USING| ++---------+-------+----------+ +``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management.md index 23b9cf795..314991c13 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management.md @@ -21,6 +21,10 @@ # 表管理 +在开始使用表管理功能前,推荐您先了解以下相关预备知识,以便更好地理解和应用表管理功能: +* [时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md):了解时序数据的基本概念与特点,帮助建立建模基础。 +* [建模方案设计](../Background-knowledge/Data-Model-and-Terminology_timecho.md):掌握 IoTDB 时序模型及适用场景,为表管理提供设计基础。 + ## 1. 表管理 ### 1.1 创建表 diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md new file mode 100644 index 000000000..314991c13 --- /dev/null +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md @@ -0,0 +1,315 @@ + + +# 表管理 + +在开始使用表管理功能前,推荐您先了解以下相关预备知识,以便更好地理解和应用表管理功能: +* [时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md):了解时序数据的基本概念与特点,帮助建立建模基础。 +* [建模方案设计](../Background-knowledge/Data-Model-and-Terminology_timecho.md):掌握 IoTDB 时序模型及适用场景,为表管理提供设计基础。 + +## 1. 表管理 + +### 1.1 创建表 + +#### 1.1.1 通过 Create 语句手动创建表 + +用于在当前数据库中创建表,也可以对任何指定数据库创建表,格式为“数据库名.表名”。 + +**语法:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +**说明:** + +1. 在创建表时,可以不指定时间列(TIME),IoTDB会自动添加该列。其他所有列可以通过在数据库配置时启用`enable_auto_create_schema`选项,或通过 session 接口自动创建或修改表的语句来添加。 +2. 列的类别可以省略,默认为`FIELD`。当列的类别为`TAG`或`ATTRIBUTE`时,数据类型需为`STRING`(可省略)。 +3. 表的TTL默认为其所在数据库的TTL。如果使用默认值,可以省略此属性,或将其设置为`default`。 +4. 表名称,具有以下特性: + - 大小写不敏感,创建成功后,统一显示为小写 + - 名称可包含特殊字符,如 `~!`"%` 等 + - 包含特殊字符或中文字符的表名创建时必须用双引号 "" 括起来。 + - 注意:SQL中特殊字符或中文表名需加双引号。原生API中无需额外添加,否则表名会包含引号字符。 + - 当为表命名时,最外层的双引号(`""`)不会在实际创建的表名中出现。 + + - ```SQL + -- SQL 中 + "a""b" --> a"b + """""" --> "" + -- API 中 + "a""b" --> "a""b" + ``` +5. columnDefinition 列名称与表名称具有相同特性,并且可包含特殊字符`.`。 +6. COMMENT 给表添加注释。 + +**示例:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "场站" STRING TAG, + "温度" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +#### 1.1.2 通过 Session 写入自动创建表 + +在通过 Session 进行数据写入时,IoTDB 能够根据写入请求中的信息自动构建表结构,无需用户事先手动创建表即可直接执行数据写入操作。 + +**示例:** + +```Java +try (ITableSession session = + new TableSessionBuilder() + .nodeUrls(Collections.singletonList("127.0.0.1:6667")) + .username("root") + .password("root") + .build()) { + + session.executeNonQueryStatement("CREATE DATABASE db1"); + session.executeNonQueryStatement("use db1"); + + // 不创建表直接写入数据 + List columnNameList = + Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); + List dataTypeList = + Arrays.asList( + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.FLOAT, + TSDataType.DOUBLE); + List columnTypeList = + new ArrayList<>( + Arrays.asList( + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.ATTRIBUTE, + ColumnCategory.FIELD, + ColumnCategory.FIELD)); + Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); + for (long timestamp = 0; timestamp < 100; timestamp++) { + int rowIndex = tablet.getRowSize(); + tablet.addTimestamp(rowIndex, timestamp); + tablet.addValue("region_id", rowIndex, "1"); + tablet.addValue("plant_id", rowIndex, "5"); + tablet.addValue("device_id", rowIndex, "3"); + tablet.addValue("model", rowIndex, "A"); + tablet.addValue("temperature", rowIndex, 37.6F); + tablet.addValue("humidity", rowIndex, 111.1); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + session.insert(tablet); + tablet.reset(); + } + } + if (tablet.getRowSize() != 0) { + session.insert(tablet); + tablet.reset(); + } +} +``` + +在代码执行完成后,可以通过下述语句确认表已成功创建,其中包含了时间列、标签列、属性列以及测点列等各类信息。 + +```SQL +IoTDB> desc table1 ++-----------+---------+-----------+-------+ +| ColumnName| DataType| Category|Comment| ++-----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| region_id| STRING| TAG| null| +| plant_id| STRING| TAG| null| +| device_id| STRING| TAG| null| +| model| STRING| ATTRIBUTE| null| +|temperature| FLOAT| FIELD| null| +| humidity| DOUBLE| FIELD| null| ++-----------+---------+-----------+-------+ +``` + +### 1.2 查看表 + +用于查看该数据库中或指定数据库中的所有表和表库的属性信息。 + +**语法:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**说明:** + +1. 在查询中指定了`FROM`或`IN`子句时,系统将展示指定数据库内的所有表。 +2. 如果未指定`FROM`或`IN`子句,系统将展示当前选定数据库中的所有表。如果用户未使用(use)某个数据库空间,系统将报错。 +3. 请求显示详细信息(指定`DETAILS`),系统将展示表的当前状态,包括: + - `USING`:表示表处于正常可用状态。 + - `PRE_CREATE`:表示表正在创建中或创建失败,此时表不可用。 + - `PRE_DELETE`:表示表正在删除中或删除失败,此类表将永久不可用。 + +**示例:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 1.3 查看表的列 + +用于查看表的列名、数据类型、类别、状态。 + +**语法:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**说明:** + +- 如果设置了`DETAILS`选项,系统将展示列的详细状态信息,包括: + - `USING`:表示列目前处于正常使用状态。 + - `PRE_DELETE`:表示列正在被删除或删除操作失败,该列将永久无法使用。 + +**示例:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 1.4 修改表 + +用于修改表,包括添加列、删除列以及设置表的属性。 + +**语法:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**说明:** + +1. `SET PROPERTIES`操作目前仅支持对表的 TTL 属性进行配置。 +2. 删除列功能,仅支持删除属性列(ATTRIBUTE)和物理量列(FIELD),标识列(TAG)不支持删除。 +3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 + +**示例:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 1.5 删除表 + +用于删除表。 + +**语法:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md new file mode 100644 index 000000000..314991c13 --- /dev/null +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md @@ -0,0 +1,315 @@ + + +# 表管理 + +在开始使用表管理功能前,推荐您先了解以下相关预备知识,以便更好地理解和应用表管理功能: +* [时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md):了解时序数据的基本概念与特点,帮助建立建模基础。 +* [建模方案设计](../Background-knowledge/Data-Model-and-Terminology_timecho.md):掌握 IoTDB 时序模型及适用场景,为表管理提供设计基础。 + +## 1. 表管理 + +### 1.1 创建表 + +#### 1.1.1 通过 Create 语句手动创建表 + +用于在当前数据库中创建表,也可以对任何指定数据库创建表,格式为“数据库名.表名”。 + +**语法:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +**说明:** + +1. 在创建表时,可以不指定时间列(TIME),IoTDB会自动添加该列。其他所有列可以通过在数据库配置时启用`enable_auto_create_schema`选项,或通过 session 接口自动创建或修改表的语句来添加。 +2. 列的类别可以省略,默认为`FIELD`。当列的类别为`TAG`或`ATTRIBUTE`时,数据类型需为`STRING`(可省略)。 +3. 表的TTL默认为其所在数据库的TTL。如果使用默认值,可以省略此属性,或将其设置为`default`。 +4. 表名称,具有以下特性: + - 大小写不敏感,创建成功后,统一显示为小写 + - 名称可包含特殊字符,如 `~!`"%` 等 + - 包含特殊字符或中文字符的表名创建时必须用双引号 "" 括起来。 + - 注意:SQL中特殊字符或中文表名需加双引号。原生API中无需额外添加,否则表名会包含引号字符。 + - 当为表命名时,最外层的双引号(`""`)不会在实际创建的表名中出现。 + + - ```SQL + -- SQL 中 + "a""b" --> a"b + """""" --> "" + -- API 中 + "a""b" --> "a""b" + ``` +5. columnDefinition 列名称与表名称具有相同特性,并且可包含特殊字符`.`。 +6. COMMENT 给表添加注释。 + +**示例:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "场站" STRING TAG, + "温度" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +#### 1.1.2 通过 Session 写入自动创建表 + +在通过 Session 进行数据写入时,IoTDB 能够根据写入请求中的信息自动构建表结构,无需用户事先手动创建表即可直接执行数据写入操作。 + +**示例:** + +```Java +try (ITableSession session = + new TableSessionBuilder() + .nodeUrls(Collections.singletonList("127.0.0.1:6667")) + .username("root") + .password("root") + .build()) { + + session.executeNonQueryStatement("CREATE DATABASE db1"); + session.executeNonQueryStatement("use db1"); + + // 不创建表直接写入数据 + List columnNameList = + Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); + List dataTypeList = + Arrays.asList( + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.FLOAT, + TSDataType.DOUBLE); + List columnTypeList = + new ArrayList<>( + Arrays.asList( + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.TAG, + ColumnCategory.ATTRIBUTE, + ColumnCategory.FIELD, + ColumnCategory.FIELD)); + Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); + for (long timestamp = 0; timestamp < 100; timestamp++) { + int rowIndex = tablet.getRowSize(); + tablet.addTimestamp(rowIndex, timestamp); + tablet.addValue("region_id", rowIndex, "1"); + tablet.addValue("plant_id", rowIndex, "5"); + tablet.addValue("device_id", rowIndex, "3"); + tablet.addValue("model", rowIndex, "A"); + tablet.addValue("temperature", rowIndex, 37.6F); + tablet.addValue("humidity", rowIndex, 111.1); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + session.insert(tablet); + tablet.reset(); + } + } + if (tablet.getRowSize() != 0) { + session.insert(tablet); + tablet.reset(); + } +} +``` + +在代码执行完成后,可以通过下述语句确认表已成功创建,其中包含了时间列、标签列、属性列以及测点列等各类信息。 + +```SQL +IoTDB> desc table1 ++-----------+---------+-----------+-------+ +| ColumnName| DataType| Category|Comment| ++-----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| region_id| STRING| TAG| null| +| plant_id| STRING| TAG| null| +| device_id| STRING| TAG| null| +| model| STRING| ATTRIBUTE| null| +|temperature| FLOAT| FIELD| null| +| humidity| DOUBLE| FIELD| null| ++-----------+---------+-----------+-------+ +``` + +### 1.2 查看表 + +用于查看该数据库中或指定数据库中的所有表和表库的属性信息。 + +**语法:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**说明:** + +1. 在查询中指定了`FROM`或`IN`子句时,系统将展示指定数据库内的所有表。 +2. 如果未指定`FROM`或`IN`子句,系统将展示当前选定数据库中的所有表。如果用户未使用(use)某个数据库空间,系统将报错。 +3. 请求显示详细信息(指定`DETAILS`),系统将展示表的当前状态,包括: + - `USING`:表示表处于正常可用状态。 + - `PRE_CREATE`:表示表正在创建中或创建失败,此时表不可用。 + - `PRE_DELETE`:表示表正在删除中或删除失败,此类表将永久不可用。 + +**示例:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 1.3 查看表的列 + +用于查看表的列名、数据类型、类别、状态。 + +**语法:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**说明:** + +- 如果设置了`DETAILS`选项,系统将展示列的详细状态信息,包括: + - `USING`:表示列目前处于正常使用状态。 + - `PRE_DELETE`:表示列正在被删除或删除操作失败,该列将永久无法使用。 + +**示例:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 1.4 修改表 + +用于修改表,包括添加列、删除列以及设置表的属性。 + +**语法:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**说明:** + +1. `SET PROPERTIES`操作目前仅支持对表的 TTL 属性进行配置。 +2. 删除列功能,仅支持删除属性列(ATTRIBUTE)和物理量列(FIELD),标识列(TAG)不支持删除。 +3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 + +**示例:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 1.5 删除表 + +用于删除表。 + +**语法:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/Reference/System-Tables_apache.md b/src/zh/UserGuide/latest-Table/Reference/System-Tables_apache.md new file mode 100644 index 000000000..6239cd69c --- /dev/null +++ b/src/zh/UserGuide/latest-Table/Reference/System-Tables_apache.md @@ -0,0 +1,593 @@ + + +# 系统表 + +IoTDB 内置系统数据库 `INFORMATION_SCHEMA`,其中包含一系列系统表,用于存储 IoTDB 运行时信息(如当前正在执行的 SQL 语句等)。目前`INFORMATION_SCHEMA`数据库只支持读操作。 + +## 1. 系统库 + +* 名称:`INFORMATION_SCHEMA` +* 指令:只读,只支持 `Show databases (DETAILS) `​`/ Show Tables (DETAILS) / Use`,其余操作将会报错:`"The database 'information_schema' can only be queried"` +* 属性:`TTL=INF`,其余属性默认为`null` +* SQL示例: + +```sql +IoTDB> show databases ++------------------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++------------------+-------+-----------------------+---------------------+---------------------+ +|information_schema| INF| null| null| null| ++------------------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show tables from information_schema ++--------------+-------+ +| TableName|TTL(ms)| ++--------------+-------+ +| columns| INF| +| config_nodes| INF| +|configurations| INF| +| data_nodes| INF| +| databases| INF| +| functions| INF| +| keywords| INF| +| models| INF| +| nodes| INF| +| pipe_plugins| INF| +| pipes| INF| +| queries| INF| +| regions| INF| +| subscriptions| INF| +| tables| INF| +| topics| INF| +| views| INF| ++--------------+-------+ +``` + +## 2. 系统表 + +* 名称:`DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES`(详细介绍见后面小节) +* 操作:只读,只支持`SELECT`, `COUNT/SHOW DEVICES`, `DESC`,不支持对于表结构 / 内容的任意修改,如果修改将会报错:`"The database 'information_schema' can only be queried"` +* 列名:系统表的列名均默认为小写,且用`_`分隔 + +### 2.1 DATABASES 表 + +* 包含集群中所有数据库的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ----------------------------- | ---------- | ----------- | ---------------- | +| database | STRING | TAG | 数据库名称 | +| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | +| schema\_replication\_factor | INT32 | ATTRIBUTE | 元数据副本数 | +| data\_replication\_factor | INT32 | ATTRIBUTE | 数据副本数 | +| time\_partition\_interval | INT64 | ATTRIBUTE | 时间分区间隔 | +| schema\_region\_group\_num | INT32 | ATTRIBUTE | 元数据分区数量 | +| data\_region\_group\_num | INT32 | ATTRIBUTE | 数据分区数量 | + +* 查询结果只展示自身对该数据库本身或库中任意表有任意权限的数据库集合 +* 查询示例: + +```sql +IoTDB> select * from information_schema.databases ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +|information_schema| INF| null| null| null| null| null| +| database1| INF| 1| 1| 604800000| 0| 0| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +``` + +### 2.2 TABLES 表 + +* 包含集群中所有表的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------- | ---------- | ----------- | -------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 表名称 | +| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | +| status | STRING | ATTRIBUTE | 状态 | +| comment | STRING | ATTRIBUTE | 注释 | + +* 说明:status 可能为`USING`/`PRE_CREATE`/`PRE_DELETE`,具体见表管理中[查看表](../Basic-Concept/Table-Management.md#12-查看表)的相关描述 +* 查询结果只展示自身有任意权限的表集合 +* 查询示例: + +```sql +IoTDB> select * from information_schema.tables ++------------------+--------------+-----------+------+-------+-----------+ +| database| table_name| ttl(ms)|status|comment| table_type| ++------------------+--------------+-----------+------+-------+-----------+ +|information_schema| databases| INF| USING| null|SYSTEM VIEW| +|information_schema| models| INF| USING| null|SYSTEM VIEW| +|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| +|information_schema| regions| INF| USING| null|SYSTEM VIEW| +|information_schema| functions| INF| USING| null|SYSTEM VIEW| +|information_schema| keywords| INF| USING| null|SYSTEM VIEW| +|information_schema| columns| INF| USING| null|SYSTEM VIEW| +|information_schema| topics| INF| USING| null|SYSTEM VIEW| +|information_schema|configurations| INF| USING| null|SYSTEM VIEW| +|information_schema| queries| INF| USING| null|SYSTEM VIEW| +|information_schema| tables| INF| USING| null|SYSTEM VIEW| +|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| +|information_schema| nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| pipes| INF| USING| null|SYSTEM VIEW| +|information_schema| views| INF| USING| null|SYSTEM VIEW| +|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| +| database1| table1|31536000000| USING| null| BASE TABLE| ++------------------+--------------+-----------+------+-------+-----------+ +``` + +### 2.3 REGIONS 表 + +* 包含集群中所有`Region`的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| --------------------- | ----------- | ----------- | ----------------------------------------------------------------------------------------------------------- | +| region\_id | INT32 | TAG | region ID | +| datanode\_id | INT32 | TAG | dataNode ID | +| type | STRING | ATTRIBUTE | 类型(SchemaRegion / DataRegion) | +| status | STRING | ATTRIBUTE | 状态(Running/Unknown 等) | +| database | STRING | ATTRIBUTE | database 名字 | +| series\_slot\_num | INT32 | ATTRIBUTE | series slot 个数 | +| time\_slot\_num | INT64 | ATTRIBUTE | time slot 个数 | +| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | +| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | +| internal\_address | STRING | ATTRIBUTE | 内部通讯地址 | +| role | STRING | ATTRIBUTE | Leader / Follower | +| create\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | +| tsfile\_size\_bytes | INT64 | ATTRIBUTE | 可统计的 DataRegion:含有 TsFile 的总文件大小;不可统计的 DataRegion(Unknown):-1;SchemaRegion:null; | + +* 仅管理员可执行查询操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.regions ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| +| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| +| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +``` + +### 2.4 QUERIES 表 + +* 包含集群中所有正在执行的查询的信息。也可以使用 `SHOW QUERIES`语法去查询。 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| --------------- | ----------- | ----------- | ------------------------------------------------ | +| query\_id | STRING | TAG | ID | +| start\_time | TIMESTAMP | ATTRIBUTE | 查询开始的时间戳,时间戳精度与系统精度保持一致 | +| datanode\_id | INT32 | ATTRIBUTE | 发起查询的DataNode ID | +| elapsed\_time | FLOAT | ATTRIBUTE | 查询执行耗时,单位是秒 | +| statement | STRING | ATTRIBUTE | 查询sql | +| user | STRING | ATTRIBUTE | 发起查询的用户 | + +* 普通用户查询结果仅显示自身执行的查询;管理员显示全部。 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.queries ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +``` + +### 2.5 COLUMNS 表 + +* 包含集群中所有表中列的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| -------------- | ---------- | ----------- | -------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 表名称 | +| column\_name | STRING | TAG | 列名称 | +| datatype | STRING | ATTRIBUTE | 列的数值类型 | +| category | STRING | ATTRIBUTE | 列类型 | +| status | STRING | ATTRIBUTE | 列状态 | +| comment | STRING | ATTRIBUTE | 列注释 | + +说明: +* status 可能为`USING`/`PRE_DELETE`,具体见表管理中[查看表的列](../Basic-Concept/Table-Management.html#13-查看表的列)的相关描述 +* 查询结果只展示自身有任意权限的表的列信息 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.columns where database = 'database1' ++---------+----------+------------+---------+---------+------+-------+ +| database|table_name| column_name| datatype| category|status|comment| ++---------+----------+------------+---------+---------+------+-------+ +|database1| table1| time|TIMESTAMP| TIME| USING| null| +|database1| table1| region| STRING| TAG| USING| null| +|database1| table1| plant_id| STRING| TAG| USING| null| +|database1| table1| device_id| STRING| TAG| USING| null| +|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| +|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| +|database1| table1| temperature| FLOAT| FIELD| USING| null| +|database1| table1| humidity| FLOAT| FIELD| USING| null| +|database1| table1| status| BOOLEAN| FIELD| USING| null| +|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| ++---------+----------+------------+---------+---------+------+-------+ +``` + +### 2.6 PIPES 表 + +* 包含集群中所有 PIPE 的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------------- | ----------- | ----------- | --------------------------------------- | +| id | STRING | TAG | Pipe 名称 | +| creation\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | +| state | STRING | ATTRIBUTE | Pipe 状态(RUNNING/STOPPED) | +| pipe\_source | STRING | ATTRIBUTE | source 插件参数 | +| pipe\_processor | STRING | ATTRIBUTE | processor 插件参数 | +| pipe\_sink | STRING | ATTRIBUTE | source 插件参数 | +| exception\_message | STRING | ATTRIBUTE | Exception 信息 | +| remaining\_event\_count | INT64 | ATTRIBUTE | 剩余 event 数量,如果 Unknown 则为 -1 | +| estimated\_remaining\_seconds | DOUBLE | ATTRIBUTE | 预估剩余时间,如果 Unknown 则为 -1 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +select * from information_schema.pipes ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +``` + +### 2.7 PIPE\_PLUGINS 表 + +* 包含集群中所有PIPE插件的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| -------------- | ---------- | ----------- | ----------------------------------------------- | +| plugin\_name | STRING | TAG | 插件名称 | +| plugin\_type | STRING | ATTRIBUTE | 插件类型(Builtin/External) | +| class\_name | STRING | ATTRIBUTE | 插件的主类名 | +| plugin\_jar | STRING | ATTRIBUTE | 插件的 jar 包名称,若为 builtin 类型则为 null | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.pipe_plugins ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +| plugin_name|plugin_type| class_name|plugin_jar| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| +| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| +| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| +| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| +| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| +| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +``` + +### 2.8 SUBSCRIPTIONS 表 + +* 包含集群中所有数据订阅的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ----------------------- | ---------- | ----------- | -------------- | +| topic\_name | STRING | TAG | 订阅主题名称 | +| consumer\_group\_name | STRING | TAG | 消费者组名称 | +| subscribed\_consumers | STRING | ATTRIBUTE | 订阅的消费者 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' ++----------+-------------------+--------------------------------+ +|topic_name|consumer_group_name| subscribed_consumers| ++----------+-------------------+--------------------------------+ +| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| ++----------+-------------------+--------------------------------+ +``` + +### 2.9 TOPICS 表 + +* 包含集群中所有数据订阅主题的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------------- | ---------- | ----------- | -------------- | +| topic\_name | STRING | TAG | 订阅主题名称 | +| topic\_configs | STRING | ATTRIBUTE | 订阅主题配置 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.topics ++----------+----------------------------------------------------------------+ +|topic_name| topic_configs| ++----------+----------------------------------------------------------------+ +| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| ++----------+----------------------------------------------------------------+ +``` + +### 2.10 VIEWS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的表视图信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------ | ---------- | ----------- | ---------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 视图名称 | +| view\_definition | STRING | ATTRIBUTE | 视图的创建语句 | + +* 查询结果只展示自身有任意权限的视图集合 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.views ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +| database|table_name| view_definition| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| ++---------+----------+--------------------------------------------------------------------------------------------------------------------------------------- +``` + +### 2.11 MODELS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的模型信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------- | ---------- | ----------- | ----------------------------------------------------------------------- | +| model\_id | STRING | TAG | 模型名称 | +| model\_type | STRING | ATTRIBUTE | 模型类型(预测,异常检测,自定义) | +| state | STRING | ATTRIBUTE | 模型状态(是否可用) | +| configs | STRING | ATTRIBUTE | 模型的超参数的 string 格式,与正常的 show 相同 | +| notes | STRING | ATTRIBUTE | 模型注释* 内置 model:Built-in model in IoTDB* 用户的 model:自定义 | + +* 查询示例: + +```SQL +-- 找到类型为内置预测的所有模型 +IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' ++---------------------+-----------------+------+-------+-----------------------+ +| model_id| model_type| state|configs| notes| ++---------------------+-----------------+------+-------+-----------------------+ +| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| ++---------------------+-----------------+------+-------+-----------------------+ +``` + +### 2.12 FUNCTIONS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的函数信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------ | ---------- | ----------- | ----------------------------------------- | +| function\_name | STRING | TAG | 函数名称 | +| function\_type | STRING | ATTRIBUTE | 函数类型(内/外置数值/聚合/表函数) | +| class\_name(udf) | STRING | ATTRIBUTE | 如为 UDF,则为类名,否则为 null(暂定) | +| state | STRING | ATTRIBUTE | 是否可用 | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.functions where function_type='built-in table function' ++--------------+-----------------------+---------------+---------+ +|function_table| function_type|class_name(udf)| state| ++--------------+-----------------------+---------------+---------+ +| CUMULATE|built-in table function| null|AVAILABLE| +| SESSION|built-in table function| null|AVAILABLE| +| HOP|built-in table function| null|AVAILABLE| +| TUMBLE|built-in table function| null|AVAILABLE| +| FORECAST|built-in table function| null|AVAILABLE| +| VARIATION|built-in table function| null|AVAILABLE| +| CAPACITY|built-in table function| null|AVAILABLE| ++--------------+-----------------------+---------------+---------+ +``` + +### 2.13 CONFIGURATIONS表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的属性信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------- | ---------- | ----------- | -------- | +| variable | STRING | TAG | 属性名 | +| value | STRING | ATTRIBUTE | 属性值 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.configurations ++----------------------------------+-----------------------------------------------------------------+ +| variable| value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 2.14 KEYWORDS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的关键字信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------- | ---------- | ----------- | -------------------------------- | +| word | STRING | TAG | 关键字 | +| reserved | INT32 | ATTRIBUTE | 是否为保留字,1表示是,0表示否 | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.keywords limit 10 ++----------+--------+ +| word|reserved| ++----------+--------+ +| ABSENT| 0| +|ACTIVATION| 1| +| ACTIVATE| 1| +| ADD| 0| +| ADMIN| 0| +| AFTER| 0| +| AINODES| 1| +| ALL| 0| +| ALTER| 1| +| ANALYZE| 0| ++----------+--------+ +``` + +### 2.15 NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------------ | ---------- | ----------- | --------------- | +| node\_id | INT32 | TAG | 节点 ID | +| node\_type | STRING | ATTRIBUTE | 节点类型 | +| status | STRING | ATTRIBUTE | 节点状态 | +| internal\_address | STRING | ATTRIBUTE | 内部 rpc 地址 | +| internal\_port | INT32 | ATTRIBUTE | 内部端口 | +| version | STRING | ATTRIBUTE | 版本号 | +| build\_info | STRING | ATTRIBUTE | CommitID | +| activate\_status(仅企业版) | STRING | ATTRIBUTE | 激活状态 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.nodes ++-------+----------+-------+----------------+-------------+-------+----------+ +|node_id| node_type| status|internal_address|internal_port|version|build_info| ++-------+----------+-------+----------------+-------------+-------+----------+ +| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| +| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| ++-------+----------+-------+----------------+-------------+-------+----------+ ++----------+--------+ +``` + +### 2.16 CONFIG\_NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的配置节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------- | ---------- | ----------- | --------------------- | +| node\_id | INT32 | TAG | 节点 ID | +| config\_consensus\_port | INT32 | ATTRIBUTE | configNode 共识端口 | +| role | STRING | ATTRIBUTE | configNode 节点角色 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.config_nodes ++-------+---------------------+------+ +|node_id|config_consensus_port| role| ++-------+---------------------+------+ +| 0| 10720|Leader| ++-------+---------------------+------+ +``` + +### 2.17 DATA\_NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的数据节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------ | ---------- | ----------- | ----------------------- | +| node\_id | INT32 | TAG | 节点 ID | +| data\_region\_num | INT32 | ATTRIBUTE | DataRegion 数量 | +| schema\_region\_num | INT32 | ATTRIBUTE | SchemaRegion 数量 | +| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | +| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | +| mpp\_port | INT32 | ATTRIBUTE | MPP 通信端口 | +| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion 共识端口 | +| scema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion 共识端口 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.data_nodes ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +``` + +## 3. 权限说明 + +* 不支持通过`GRANT/REVOKE`语句对 `information_schema` 数据库及其下任何表进行权限操作 +* 支持任意用户通过`show databases`语句查看`information_schema`数据库相关信息 +* 支持任意用户通过`show tables from information_schema` 语句查看所有系统表相关信息 +* 支持任意用户通过`desc`语句查看任意系统表 diff --git a/src/zh/UserGuide/latest-Table/Reference/System-Tables_timecho.md b/src/zh/UserGuide/latest-Table/Reference/System-Tables_timecho.md new file mode 100644 index 000000000..6239cd69c --- /dev/null +++ b/src/zh/UserGuide/latest-Table/Reference/System-Tables_timecho.md @@ -0,0 +1,593 @@ + + +# 系统表 + +IoTDB 内置系统数据库 `INFORMATION_SCHEMA`,其中包含一系列系统表,用于存储 IoTDB 运行时信息(如当前正在执行的 SQL 语句等)。目前`INFORMATION_SCHEMA`数据库只支持读操作。 + +## 1. 系统库 + +* 名称:`INFORMATION_SCHEMA` +* 指令:只读,只支持 `Show databases (DETAILS) `​`/ Show Tables (DETAILS) / Use`,其余操作将会报错:`"The database 'information_schema' can only be queried"` +* 属性:`TTL=INF`,其余属性默认为`null` +* SQL示例: + +```sql +IoTDB> show databases ++------------------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++------------------+-------+-----------------------+---------------------+---------------------+ +|information_schema| INF| null| null| null| ++------------------+-------+-----------------------+---------------------+---------------------+ + +IoTDB> show tables from information_schema ++--------------+-------+ +| TableName|TTL(ms)| ++--------------+-------+ +| columns| INF| +| config_nodes| INF| +|configurations| INF| +| data_nodes| INF| +| databases| INF| +| functions| INF| +| keywords| INF| +| models| INF| +| nodes| INF| +| pipe_plugins| INF| +| pipes| INF| +| queries| INF| +| regions| INF| +| subscriptions| INF| +| tables| INF| +| topics| INF| +| views| INF| ++--------------+-------+ +``` + +## 2. 系统表 + +* 名称:`DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES`(详细介绍见后面小节) +* 操作:只读,只支持`SELECT`, `COUNT/SHOW DEVICES`, `DESC`,不支持对于表结构 / 内容的任意修改,如果修改将会报错:`"The database 'information_schema' can only be queried"` +* 列名:系统表的列名均默认为小写,且用`_`分隔 + +### 2.1 DATABASES 表 + +* 包含集群中所有数据库的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ----------------------------- | ---------- | ----------- | ---------------- | +| database | STRING | TAG | 数据库名称 | +| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | +| schema\_replication\_factor | INT32 | ATTRIBUTE | 元数据副本数 | +| data\_replication\_factor | INT32 | ATTRIBUTE | 数据副本数 | +| time\_partition\_interval | INT64 | ATTRIBUTE | 时间分区间隔 | +| schema\_region\_group\_num | INT32 | ATTRIBUTE | 元数据分区数量 | +| data\_region\_group\_num | INT32 | ATTRIBUTE | 数据分区数量 | + +* 查询结果只展示自身对该数据库本身或库中任意表有任意权限的数据库集合 +* 查询示例: + +```sql +IoTDB> select * from information_schema.databases ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +|information_schema| INF| null| null| null| null| null| +| database1| INF| 1| 1| 604800000| 0| 0| ++------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ +``` + +### 2.2 TABLES 表 + +* 包含集群中所有表的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------- | ---------- | ----------- | -------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 表名称 | +| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | +| status | STRING | ATTRIBUTE | 状态 | +| comment | STRING | ATTRIBUTE | 注释 | + +* 说明:status 可能为`USING`/`PRE_CREATE`/`PRE_DELETE`,具体见表管理中[查看表](../Basic-Concept/Table-Management.md#12-查看表)的相关描述 +* 查询结果只展示自身有任意权限的表集合 +* 查询示例: + +```sql +IoTDB> select * from information_schema.tables ++------------------+--------------+-----------+------+-------+-----------+ +| database| table_name| ttl(ms)|status|comment| table_type| ++------------------+--------------+-----------+------+-------+-----------+ +|information_schema| databases| INF| USING| null|SYSTEM VIEW| +|information_schema| models| INF| USING| null|SYSTEM VIEW| +|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| +|information_schema| regions| INF| USING| null|SYSTEM VIEW| +|information_schema| functions| INF| USING| null|SYSTEM VIEW| +|information_schema| keywords| INF| USING| null|SYSTEM VIEW| +|information_schema| columns| INF| USING| null|SYSTEM VIEW| +|information_schema| topics| INF| USING| null|SYSTEM VIEW| +|information_schema|configurations| INF| USING| null|SYSTEM VIEW| +|information_schema| queries| INF| USING| null|SYSTEM VIEW| +|information_schema| tables| INF| USING| null|SYSTEM VIEW| +|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| +|information_schema| nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| +|information_schema| pipes| INF| USING| null|SYSTEM VIEW| +|information_schema| views| INF| USING| null|SYSTEM VIEW| +|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| +| database1| table1|31536000000| USING| null| BASE TABLE| ++------------------+--------------+-----------+------+-------+-----------+ +``` + +### 2.3 REGIONS 表 + +* 包含集群中所有`Region`的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| --------------------- | ----------- | ----------- | ----------------------------------------------------------------------------------------------------------- | +| region\_id | INT32 | TAG | region ID | +| datanode\_id | INT32 | TAG | dataNode ID | +| type | STRING | ATTRIBUTE | 类型(SchemaRegion / DataRegion) | +| status | STRING | ATTRIBUTE | 状态(Running/Unknown 等) | +| database | STRING | ATTRIBUTE | database 名字 | +| series\_slot\_num | INT32 | ATTRIBUTE | series slot 个数 | +| time\_slot\_num | INT64 | ATTRIBUTE | time slot 个数 | +| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | +| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | +| internal\_address | STRING | ATTRIBUTE | 内部通讯地址 | +| role | STRING | ATTRIBUTE | Leader / Follower | +| create\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | +| tsfile\_size\_bytes | INT64 | ATTRIBUTE | 可统计的 DataRegion:含有 TsFile 的总文件大小;不可统计的 DataRegion(Unknown):-1;SchemaRegion:null; | + +* 仅管理员可执行查询操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.regions ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| +| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| +| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| ++---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ +``` + +### 2.4 QUERIES 表 + +* 包含集群中所有正在执行的查询的信息。也可以使用 `SHOW QUERIES`语法去查询。 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| --------------- | ----------- | ----------- | ------------------------------------------------ | +| query\_id | STRING | TAG | ID | +| start\_time | TIMESTAMP | ATTRIBUTE | 查询开始的时间戳,时间戳精度与系统精度保持一致 | +| datanode\_id | INT32 | ATTRIBUTE | 发起查询的DataNode ID | +| elapsed\_time | FLOAT | ATTRIBUTE | 查询执行耗时,单位是秒 | +| statement | STRING | ATTRIBUTE | 查询sql | +| user | STRING | ATTRIBUTE | 发起查询的用户 | + +* 普通用户查询结果仅显示自身执行的查询;管理员显示全部。 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.queries ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| ++-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ +``` + +### 2.5 COLUMNS 表 + +* 包含集群中所有表中列的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| -------------- | ---------- | ----------- | -------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 表名称 | +| column\_name | STRING | TAG | 列名称 | +| datatype | STRING | ATTRIBUTE | 列的数值类型 | +| category | STRING | ATTRIBUTE | 列类型 | +| status | STRING | ATTRIBUTE | 列状态 | +| comment | STRING | ATTRIBUTE | 列注释 | + +说明: +* status 可能为`USING`/`PRE_DELETE`,具体见表管理中[查看表的列](../Basic-Concept/Table-Management.html#13-查看表的列)的相关描述 +* 查询结果只展示自身有任意权限的表的列信息 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.columns where database = 'database1' ++---------+----------+------------+---------+---------+------+-------+ +| database|table_name| column_name| datatype| category|status|comment| ++---------+----------+------------+---------+---------+------+-------+ +|database1| table1| time|TIMESTAMP| TIME| USING| null| +|database1| table1| region| STRING| TAG| USING| null| +|database1| table1| plant_id| STRING| TAG| USING| null| +|database1| table1| device_id| STRING| TAG| USING| null| +|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| +|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| +|database1| table1| temperature| FLOAT| FIELD| USING| null| +|database1| table1| humidity| FLOAT| FIELD| USING| null| +|database1| table1| status| BOOLEAN| FIELD| USING| null| +|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| ++---------+----------+------------+---------+---------+------+-------+ +``` + +### 2.6 PIPES 表 + +* 包含集群中所有 PIPE 的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------------- | ----------- | ----------- | --------------------------------------- | +| id | STRING | TAG | Pipe 名称 | +| creation\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | +| state | STRING | ATTRIBUTE | Pipe 状态(RUNNING/STOPPED) | +| pipe\_source | STRING | ATTRIBUTE | source 插件参数 | +| pipe\_processor | STRING | ATTRIBUTE | processor 插件参数 | +| pipe\_sink | STRING | ATTRIBUTE | source 插件参数 | +| exception\_message | STRING | ATTRIBUTE | Exception 信息 | +| remaining\_event\_count | INT64 | ATTRIBUTE | 剩余 event 数量,如果 Unknown 则为 -1 | +| estimated\_remaining\_seconds | DOUBLE | ATTRIBUTE | 预估剩余时间,如果 Unknown 则为 -1 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +select * from information_schema.pipes ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| ++----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ +``` + +### 2.7 PIPE\_PLUGINS 表 + +* 包含集群中所有PIPE插件的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| -------------- | ---------- | ----------- | ----------------------------------------------- | +| plugin\_name | STRING | TAG | 插件名称 | +| plugin\_type | STRING | ATTRIBUTE | 插件类型(Builtin/External) | +| class\_name | STRING | ATTRIBUTE | 插件的主类名 | +| plugin\_jar | STRING | ATTRIBUTE | 插件的 jar 包名称,若为 builtin 类型则为 null | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.pipe_plugins ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +| plugin_name|plugin_type| class_name|plugin_jar| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| +| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| +| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| +| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| +| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| +| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| ++---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ +``` + +### 2.8 SUBSCRIPTIONS 表 + +* 包含集群中所有数据订阅的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ----------------------- | ---------- | ----------- | -------------- | +| topic\_name | STRING | TAG | 订阅主题名称 | +| consumer\_group\_name | STRING | TAG | 消费者组名称 | +| subscribed\_consumers | STRING | ATTRIBUTE | 订阅的消费者 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' ++----------+-------------------+--------------------------------+ +|topic_name|consumer_group_name| subscribed_consumers| ++----------+-------------------+--------------------------------+ +| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| ++----------+-------------------+--------------------------------+ +``` + +### 2.9 TOPICS 表 + +* 包含集群中所有数据订阅主题的信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------------- | ---------- | ----------- | -------------- | +| topic\_name | STRING | TAG | 订阅主题名称 | +| topic\_configs | STRING | ATTRIBUTE | 订阅主题配置 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.topics ++----------+----------------------------------------------------------------+ +|topic_name| topic_configs| ++----------+----------------------------------------------------------------+ +| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| ++----------+----------------------------------------------------------------+ +``` + +### 2.10 VIEWS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的表视图信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------ | ---------- | ----------- | ---------------- | +| database | STRING | TAG | 数据库名称 | +| table\_name | STRING | TAG | 视图名称 | +| view\_definition | STRING | ATTRIBUTE | 视图的创建语句 | + +* 查询结果只展示自身有任意权限的视图集合 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.views ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +| database|table_name| view_definition| ++---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ +|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| ++---------+----------+--------------------------------------------------------------------------------------------------------------------------------------- +``` + +### 2.11 MODELS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的模型信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------- | ---------- | ----------- | ----------------------------------------------------------------------- | +| model\_id | STRING | TAG | 模型名称 | +| model\_type | STRING | ATTRIBUTE | 模型类型(预测,异常检测,自定义) | +| state | STRING | ATTRIBUTE | 模型状态(是否可用) | +| configs | STRING | ATTRIBUTE | 模型的超参数的 string 格式,与正常的 show 相同 | +| notes | STRING | ATTRIBUTE | 模型注释* 内置 model:Built-in model in IoTDB* 用户的 model:自定义 | + +* 查询示例: + +```SQL +-- 找到类型为内置预测的所有模型 +IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' ++---------------------+-----------------+------+-------+-----------------------+ +| model_id| model_type| state|configs| notes| ++---------------------+-----------------+------+-------+-----------------------+ +| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| +| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| ++---------------------+-----------------+------+-------+-----------------------+ +``` + +### 2.12 FUNCTIONS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的函数信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------ | ---------- | ----------- | ----------------------------------------- | +| function\_name | STRING | TAG | 函数名称 | +| function\_type | STRING | ATTRIBUTE | 函数类型(内/外置数值/聚合/表函数) | +| class\_name(udf) | STRING | ATTRIBUTE | 如为 UDF,则为类名,否则为 null(暂定) | +| state | STRING | ATTRIBUTE | 是否可用 | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.functions where function_type='built-in table function' ++--------------+-----------------------+---------------+---------+ +|function_table| function_type|class_name(udf)| state| ++--------------+-----------------------+---------------+---------+ +| CUMULATE|built-in table function| null|AVAILABLE| +| SESSION|built-in table function| null|AVAILABLE| +| HOP|built-in table function| null|AVAILABLE| +| TUMBLE|built-in table function| null|AVAILABLE| +| FORECAST|built-in table function| null|AVAILABLE| +| VARIATION|built-in table function| null|AVAILABLE| +| CAPACITY|built-in table function| null|AVAILABLE| ++--------------+-----------------------+---------------+---------+ +``` + +### 2.13 CONFIGURATIONS表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的属性信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------- | ---------- | ----------- | -------- | +| variable | STRING | TAG | 属性名 | +| value | STRING | ATTRIBUTE | 属性值 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.configurations ++----------------------------------+-----------------------------------------------------------------+ +| variable| value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 2.14 KEYWORDS 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的关键字信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ---------- | ---------- | ----------- | -------------------------------- | +| word | STRING | TAG | 关键字 | +| reserved | INT32 | ATTRIBUTE | 是否为保留字,1表示是,0表示否 | + +* 查询示例: + +```SQL +IoTDB> select * from information_schema.keywords limit 10 ++----------+--------+ +| word|reserved| ++----------+--------+ +| ABSENT| 0| +|ACTIVATION| 1| +| ACTIVATE| 1| +| ADD| 0| +| ADMIN| 0| +| AFTER| 0| +| AINODES| 1| +| ALL| 0| +| ALTER| 1| +| ANALYZE| 0| ++----------+--------+ +``` + +### 2.15 NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------------ | ---------- | ----------- | --------------- | +| node\_id | INT32 | TAG | 节点 ID | +| node\_type | STRING | ATTRIBUTE | 节点类型 | +| status | STRING | ATTRIBUTE | 节点状态 | +| internal\_address | STRING | ATTRIBUTE | 内部 rpc 地址 | +| internal\_port | INT32 | ATTRIBUTE | 内部端口 | +| version | STRING | ATTRIBUTE | 版本号 | +| build\_info | STRING | ATTRIBUTE | CommitID | +| activate\_status(仅企业版) | STRING | ATTRIBUTE | 激活状态 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.nodes ++-------+----------+-------+----------------+-------------+-------+----------+ +|node_id| node_type| status|internal_address|internal_port|version|build_info| ++-------+----------+-------+----------------+-------------+-------+----------+ +| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| +| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| ++-------+----------+-------+----------------+-------------+-------+----------+ ++----------+--------+ +``` + +### 2.16 CONFIG\_NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的配置节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------- | ---------- | ----------- | --------------------- | +| node\_id | INT32 | TAG | 节点 ID | +| config\_consensus\_port | INT32 | ATTRIBUTE | configNode 共识端口 | +| role | STRING | ATTRIBUTE | configNode 节点角色 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.config_nodes ++-------+---------------------+------+ +|node_id|config_consensus_port| role| ++-------+---------------------+------+ +| 0| 10720|Leader| ++-------+---------------------+------+ +``` + +### 2.17 DATA\_NODES 表 + +> 该系统表从 V 2.0.5 版本开始提供 + +* 包含数据库内所有的数据节点信息 +* 表结构如下表所示: + +| 列名 | 数据类型 | 列类型 | 说明 | +| ------------------------ | ---------- | ----------- | ----------------------- | +| node\_id | INT32 | TAG | 节点 ID | +| data\_region\_num | INT32 | ATTRIBUTE | DataRegion 数量 | +| schema\_region\_num | INT32 | ATTRIBUTE | SchemaRegion 数量 | +| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | +| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | +| mpp\_port | INT32 | ATTRIBUTE | MPP 通信端口 | +| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion 共识端口 | +| scema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion 共识端口 | + +* 仅管理员可执行操作 +* 查询示例: + +```SQL +IoTDB> select * from information_schema.data_nodes ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| ++-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ +``` + +## 3. 权限说明 + +* 不支持通过`GRANT/REVOKE`语句对 `information_schema` 数据库及其下任何表进行权限操作 +* 支持任意用户通过`show databases`语句查看`information_schema`数据库相关信息 +* 支持任意用户通过`show tables from information_schema` 语句查看所有系统表相关信息 +* 支持任意用户通过`desc`语句查看任意系统表 diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md new file mode 100644 index 000000000..1831e8557 --- /dev/null +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md @@ -0,0 +1,304 @@ + + +# 元数据操作 + +## 1. 数据库管理 + +### 1.1 创建数据库 + +**语法:** + +```SQL +CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +更多详细语法说明请参考:[创建数据库](../Basic-Concept/Database-Management.md#_1-1-创建数据库) + +**示例:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +-- 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 使用数据库 + +**语法:** + +```SQL +USE +``` + +**示例:** + +```SQL +USE database1 +``` + +### 1.3 查看当前数据库 + +**语法:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**示例:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 查看所有数据库 + +**语法:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +更多返回结果详细说明请参考:[查看所有数据库](../Basic-Concept/Database-Management.md#_1-4-查看所有数据库) + +**示例:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 修改数据库 + +**语法:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**示例:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 删除数据库 + +**语法:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` + +## 2. 表管理 + +### 2.1 创建表 + +**语法:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +更多详细语法说明请参考:[创建表](../Basic-Concept/Table-Management.md#_1-1-创建表) + +**示例:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "场站" STRING TAG, + "温度" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +### 2.2 查看表 + +**语法:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**示例:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 2.3 查看表的列 + +**语法:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**示例:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 2.4 修改表 + +**语法:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**示例:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 2.5 删除表 + +**语法:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` + + diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md new file mode 100644 index 000000000..1831e8557 --- /dev/null +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md @@ -0,0 +1,304 @@ + + +# 元数据操作 + +## 1. 数据库管理 + +### 1.1 创建数据库 + +**语法:** + +```SQL +CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +更多详细语法说明请参考:[创建数据库](../Basic-Concept/Database-Management.md#_1-1-创建数据库) + +**示例:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +-- 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 使用数据库 + +**语法:** + +```SQL +USE +``` + +**示例:** + +```SQL +USE database1 +``` + +### 1.3 查看当前数据库 + +**语法:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**示例:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 查看所有数据库 + +**语法:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +更多返回结果详细说明请参考:[查看所有数据库](../Basic-Concept/Database-Management.md#_1-4-查看所有数据库) + +**示例:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 修改数据库 + +**语法:** + +```SQL +ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments +``` + +**示例:** + +```SQL +ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; +``` + +### 1.6 删除数据库 + +**语法:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` + +## 2. 表管理 + +### 2.1 创建表 + +**语法:** + +```SQL +createTableStatement + : CREATE TABLE (IF NOT EXISTS)? qualifiedName + '(' (columnDefinition (',' columnDefinition)*)? ')' + charsetDesc? + comment? + (WITH properties)? + ; + +charsetDesc + : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString + ; + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? + ; + +charsetName + : CHAR SET identifier + | CHARSET identifier + | CHARACTER SET identifier + ; + +comment + : COMMENT string + ; +``` + +更多详细语法说明请参考:[创建表](../Basic-Concept/Table-Management.md#_1-1-创建表) + +**示例:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE COMMENT 'maintenance', + temperature FLOAT FIELD COMMENT 'temperature', + humidity FLOAT FIELD COMMENT 'humidity', + status Boolean FIELD COMMENT 'status', + arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' +) COMMENT 'table1' WITH (TTL=31536000000); + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "场站" STRING TAG, + "温度" int32 FIELD COMMENT 'temperature' + ) with (TTL=DEFAULT); +``` + +### 2.2 查看表 + +**语法:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**示例:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+-------+ +|TableName|TTL(ms)|Comment| ++---------+-------+-------+ +| test| INF| TEST| ++---------+-------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+-------+ +|TableName|TTL(ms)| Status|Comment| ++---------+-------+----------+-------+ +| test| INF| USING| TEST| +| turbine| INF|PRE_CREATE| null| +| car| 1000|PRE_DELETE| null| ++---------+-------+----------+-------+ +``` + +### 2.3 查看表的列 + +**语法:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**示例:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+-------+ +|ColumnName| DataType| Category|Comment| ++----------+---------+-----------+-------+ +| time|TIMESTAMP| TIME| null| +| a| STRING| TAG| a| +| b| STRING| ATTRIBUTE| b| +| c| INT32| FIELD| c| ++----------+---------+-----------+-------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+-------+ +|ColumnName| DataType| Category| Status|Comment| ++----------+---------+-----------+----------+-------+ +| time|TIMESTAMP| TIME| USING| null| +| a| STRING| TAG| USING| a| +| b| STRING| ATTRIBUTE| USING| b| +| c| INT32| FIELD| USING| c| +| d| INT32| FIELD|PRE_DELETE| d| ++----------+---------+-----------+----------+-------+ +``` + +### 2.4 修改表 + +**语法:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' +| COMMENT ON COLUMN tableName.column IS 'column_comment' +``` + +**示例:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' +ALTER TABLE tableB set properties TTL=3600 +COMMENT ON TABLE table1 IS 'table1' +COMMENT ON COLUMN table1.a IS null +``` + +### 2.5 删除表 + +**语法:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**示例:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` + + diff --git a/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_apache.md b/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_apache.md new file mode 100644 index 000000000..99b6e36e5 --- /dev/null +++ b/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_apache.md @@ -0,0 +1,664 @@ + +# 运维语句 + +## 1. 状态查看 + +### 1.1 查看连接的模型 + +**含义**:返回当前连接的 sql_dialect 是树模型/表模型。 + +#### 语法: + +```SQL +showCurrentSqlDialectStatement + : SHOW CURRENT_SQL_DIALECT + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_SQL_DIALECT +``` + +执行结果如下: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` +### 1.2 查看登录的用户名 + +**含义**:返回当前登录的用户名。 + +#### 语法: + +```SQL +showCurrentUserStatement + : SHOW CURRENT_USER + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_USER +``` + +执行结果如下: + +```SQL ++-----------+ +|CurrentUser| ++-----------+ +| root| ++-----------+ +``` + +### 1.3 查看连接的数据库名 + +**含义**:返回当前连接的数据库名,若没有执行过 use 语句,则为 null。 + +#### 语法: + +```SQL +showCurrentDatabaseStatement + : SHOW CURRENT_DATABASE + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_DATABASE; + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; +``` + +执行结果如下: + +```SQL ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + ++---------------+ +|CurrentDatabase| ++---------------+ +| test| ++---------------+ +``` + +### 1.4 查看集群版本 + +**含义**:返回当前集群的版本。 + +#### 语法: + +```SQL +showVersionStatement + : SHOW VERSION + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW VERSION +``` + +执行结果如下: + +```SQL ++-------+---------+ +|Version|BuildInfo| ++-------+---------+ +|2.0.1.2| 1ca4008| ++-------+---------+ +``` + +### 1.5 查看集群关键参数 + +**含义**:返回当前集群的关键参数。 + +#### 语法: + +```SQL +showVariablesStatement + : SHOW VARIABLES + ; +``` + +关键参数如下: + +1. **ClusterName**:当前集群的名称。 +2. **DataReplicationFactor**:数据副本的数量,表示每个数据分区(DataRegion)的副本数。 +3. **SchemaReplicationFactor**:元数据副本的数量,表示每个元数据分区(SchemaRegion)的副本数。 +4. **DataRegionConsensusProtocolClass**:数据分区(DataRegion)使用的共识协议类。 +5. **SchemaRegionConsensusProtocolClass**:元数据分区(SchemaRegion)使用的共识协议类。 +6. **ConfigNodeConsensusProtocolClass**:配置节点(ConfigNode)使用的共识协议类。 +7. **TimePartitionOrigin**:数据库时间分区的起始时间戳。 +8. **TimePartitionInterval**:数据库的时间分区间隔(单位:毫秒)。 +9. **ReadConsistencyLevel**:读取操作的一致性级别。 +10. **SchemaRegionPerDataNode**:数据节点(DataNode)上的元数据分区(SchemaRegion)数量。 +11. **DataRegionPerDataNode**:数据节点(DataNode)上的数据分区(DataRegion)数量。 +12. **SeriesSlotNum**:数据分区(DataRegion)的序列槽(SeriesSlot)数量。 +13. **SeriesSlotExecutorClass**:序列槽的实现类。 +14. **DiskSpaceWarningThreshold**:磁盘空间告警阈值(单位:百分比)。 +15. **TimestampPrecision**:时间戳精度。 + +#### 示例: + +```SQL +IoTDB> SHOW VARIABLES +``` + +执行结果如下: + +```SQL ++----------------------------------+-----------------------------------------------------------------+ +| Variable| Value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 1.6 查看集群ID + +**含义**:返回当前集群的ID。 + +#### 语法: + +```SQL +showClusterIdStatement + : SHOW (CLUSTERID | CLUSTER_ID) + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CLUSTER_ID +``` + +执行结果如下: + +```SQL ++------------------------------------+ +| ClusterId| ++------------------------------------+ +|40163007-9ec1-4455-aa36-8055d740fcda| +``` + +### 1.7 查看客户端直连的 DataNode 进程所在服务器的时间 + +#### 语法: + +**含义**:返回当前客户端直连的 DataNode 进程所在服务器的时间。 + +```SQL +showCurrentTimestampStatement + : SHOW CURRENT_TIMESTAMP + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_TIMESTAMP +``` + +执行结果如下: + +```SQL ++-----------------------------+ +| CurrentTimestamp| ++-----------------------------+ +|2025-02-17T11:11:52.987+08:00| ++-----------------------------+ +``` + +### 1.8 查看正在执行的查询信息 + +**含义**:用于显示所有正在执行的查询信息。 + +> 更多系统表使用方法请参考[系统表](../Reference/System-Tables.md) + +#### 语法: + +```SQL +showQueriesStatement + : SHOW (QUERIES | QUERY PROCESSLIST) + (WHERE where=booleanExpression)? + (ORDER BY sortItem (',' sortItem)*)? + limitOffsetClause + ; +``` + +**参数解释**: + +1. **WHERE** 子句:需保证过滤的目标列是结果集中存在的列 +2. **ORDER BY** 子句:需保证`sortKey`是结果集中存在的列 +3. **limitOffsetClause**: + - **含义**:用于限制结果集的返回数量。 + - **格式**:`LIMIT , `, `` 是偏移量,`` 是返回的行数。 +4. **QUERIES** 表中的列: + - **query_id**:查询语句的 ID + - **start_time**:查询开始的时间戳,时间戳精度与系统精度一致 + - **datanode_id**:发起查询语句的 DataNode 的ID + - **elapsed_time**:查询的执行耗时,单位是秒 + - **statement**:查询的 SQL 语句 + - **user**:发起查询的用户 + +#### 示例: + +```SQL +IoTDB> SHOW QUERIES WHERE elapsed_time > 30 +``` + +执行结果如下: + +```SQL ++-----------------------+-----------------------------+-----------+------------+------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +``` + +### 1.9 查看分区信息 + +**含义**:返回当前集群的分区信息。 + +#### 语法: + +```SQL +showRegionsStatement + : SHOW REGIONS + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW REGIONS +``` + +执行结果如下: + +```SQL ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | +| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| +| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +``` + + +## 2. 状态设置 + +### 2.1 设置连接的模型 + +**含义**:将当前连接的 sql_dialect 置为树模型/表模型,在树模型和表模型中均可使用该命令。 + +#### 语法: + +```SQL +SET SQL_DIALECT EQ (TABLE | TREE) +``` + +#### 示例: + +```SQL +IoTDB> SET SQL_DIALECT=TABLE +IoTDB> SHOW CURRENT_SQL_DIALECT +``` + +执行结果如下: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 2.2 更新配置项 + +**含义**:用于更新配置项,执行完成后会进行配置项的热加载,对于支持热修改的配置项会立即生效。 + +#### 语法: + +```SQL +setConfigurationStatement + : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? + ; + +propertyAssignments + : property (',' property)* + ; + +property + : identifier EQ propertyValue + ; + +propertyValue + : DEFAULT + | expression + ; +``` + +**参数解释**: + +1. **propertyAssignments** + - **含义**:更新的配置列表,由多个 `property` 组成。 + - 可以更新多个配置列表,用逗号分隔。 + - **取值**: + - `DEFAULT`:将配置项恢复为默认值。 + - `expression`:具体的值,必须是一个字符串。 +2. **ON INTEGER_VALUE** + - **含义**:指定要更新配置的节点 ID。 + - **可选性**:可选。如果不指定或指定的值低于 0,则更新所有 ConfigNode 和 DataNode 的配置。 + +#### 示例: + +```SQL +IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; +``` + +### 2.3 读取手动修改的配置文件 + +**含义**:用于读取手动修改过的配置文件,并对配置项进行热加载,对于支持热修改的配置项会立即生效。 + +#### 语法: + +```SQL +loadConfigurationStatement + : LOAD CONFIGURATION localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定配置热加载的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `LOCAL`:只对客户端直连的 DataNode 进行配置热加载。 + - `CLUSTER`:对集群中所有 DataNode 进行配置热加载。 + +#### 示例: + +```SQL +IoTDB> LOAD CONFIGURATION ON LOCAL; +``` + +### 2.4 设置系统的状态 + +**含义**:用于设置系统的状态。 + +#### 语法: + +```SQL +setSystemStatusStatement + : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **RUNNING | READONLY** + - **含义**:指定系统的新状态。 + - **取值**: + - `RUNNING`:将系统设置为运行状态,允许读写操作。 + - `READONLY`:将系统设置为只读状态,只允许读取操作,禁止写入操作。 +2. **localOrClusterMode** + - **含义**:指定状态变更的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `LOCAL`:仅对客户端直连的 DataNode 生效。 + - `CLUSTER`:对集群中所有 DataNode 生效。 + +#### 示例: + +```SQL +IoTDB> SET SYSTEM TO READONLY ON CLUSTER; +``` + + +## 3. 数据管理 + +### 3.1 刷写内存表中的数据到磁盘 + +**含义**:将内存表中的数据刷写到磁盘上。 + +#### 语法: + +```SQL +flushStatement + : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? + ; + +booleanValue + : TRUE | FALSE + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **identifier** + - **含义**:指定要刷写的数据库名称。 + - **可选性**:可选。如果不指定,则默认刷写所有数据库。 + - **多个数据库**:可以指定多个数据库名称,用逗号分隔。例如:`FLUSH test_db1, test_db2`。 +2. **booleanValue** + - **含义**:指定刷写的内容。 + - **可选性**:可选。如果不指定,则默认刷写顺序和乱序空间的内存。 + - **取值**: + - `TRUE`:只刷写顺序空间的内存表。 + - `FALSE`:只刷写乱序空间的MemTable。 +3. **localOrClusterMode** + - **含义**:指定刷写的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:只刷写客户端直连的 DataNode 上的内存表。 + - `ON CLUSTER`:刷写集群中所有 DataNode 上的内存表。 + +#### 示例: + +```SQL +IoTDB> FLUSH test_db TRUE ON LOCAL; +``` + +### 3.2 清除 DataNode 上的缓存 + +**含义**:用于清除 DataNode 上的某种类型的缓存。 + +#### 语法: + +```SQL +clearCacheStatement + : CLEAR clearCacheOptions? CACHE localOrClusterMode? + ; + +clearCacheOptions + : ATTRIBUTE + | QUERY + | ALL + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **clearCacheOptions** + - **含义**:指定要清除的缓存类型。 + - **可选性**:可选。如果不指定,默认清除查询缓存(`QUERY`)。 + - **取值**: + - `ATTRIBUTE`:清除设备属性缓存。 + - `QUERY`:清除存储引擎中的查询缓存。 + - `ALL`:清除所有缓存,包括设备属性缓存、查询缓存以及树模型中的模式缓存。 +2. **localOrClusterMode** + - **含义**:指定清除缓存的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:只清除客户端直连的 DataNode 上的缓存。 + - `ON CLUSTER`:清除集群中所有 DataNode 上的缓存。 + +#### 示例: + +```SQL +IoTDB> CLEAR ALL CACHE ON LOCAL; +``` + +## 4. 数据修复 + +### 4.1 启动后台扫描并修复 tsfile 任务 + +**含义**:启动一个后台任务,开始扫描并修复 tsfile,能够修复数据文件内的时间戳乱序类异常。 + +#### 语法: + +```SQL +startRepairDataStatement + : START REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定数据修复的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 + - `ON CLUSTER`:对集群中所有 DataNode 执行。 + +#### 示例: + +```SQL +IoTDB> START REPAIR DATA ON CLUSTER; +``` + +### 4.2 暂停后台修复 tsfile 任务 + +**含义**:暂停后台的修复任务,暂停中的任务可通过再次执行 start repair data 命令恢复。 + +#### 语法: + +```SQL +stopRepairDataStatement + : STOP REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定数据修复的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 + - `ON CLUSTER`:对集群中所有 DataNode 执行。 + +#### 示例: + +```SQL +IoTDB> STOP REPAIR DATA ON CLUSTER; +``` + +## 5. 终止查询 + +### 5.1 主动终止查询 + +**含义**:使用该命令主动地终止查询。 + +#### 语法: + +```SQL +killQueryStatement + : KILL (QUERY queryId=string | ALL QUERIES) + ; +``` + +**参数解释**: + +1. **QUERY queryId=string** + - **含义**:指定要终止的查询的 ID。 `` 是正在执行的查询的唯一标识符。 + - **获取查询 ID**:可以通过 `SHOW QUERIES` 命令获取所有正在执行的查询及其 ID。 +2. **ALL QUERIES** + - **含义**:终止所有正在执行的查询。 + +#### 示例: + +通过指定 `queryId` 可以中止指定的查询,为了获取正在执行的查询 id,用户可以使用 show queries 命令,该命令将显示所有正在执行的查询列表。 + +```SQL +IoTDB> KILL QUERY 20250108_101015_00000_1; -- 终止指定query +IoTDB> KILL ALL QUERIES; -- 终止所有query +``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_timecho.md b/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_timecho.md new file mode 100644 index 000000000..99b6e36e5 --- /dev/null +++ b/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_timecho.md @@ -0,0 +1,664 @@ + +# 运维语句 + +## 1. 状态查看 + +### 1.1 查看连接的模型 + +**含义**:返回当前连接的 sql_dialect 是树模型/表模型。 + +#### 语法: + +```SQL +showCurrentSqlDialectStatement + : SHOW CURRENT_SQL_DIALECT + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_SQL_DIALECT +``` + +执行结果如下: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` +### 1.2 查看登录的用户名 + +**含义**:返回当前登录的用户名。 + +#### 语法: + +```SQL +showCurrentUserStatement + : SHOW CURRENT_USER + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_USER +``` + +执行结果如下: + +```SQL ++-----------+ +|CurrentUser| ++-----------+ +| root| ++-----------+ +``` + +### 1.3 查看连接的数据库名 + +**含义**:返回当前连接的数据库名,若没有执行过 use 语句,则为 null。 + +#### 语法: + +```SQL +showCurrentDatabaseStatement + : SHOW CURRENT_DATABASE + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_DATABASE; + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; +``` + +执行结果如下: + +```SQL ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + ++---------------+ +|CurrentDatabase| ++---------------+ +| test| ++---------------+ +``` + +### 1.4 查看集群版本 + +**含义**:返回当前集群的版本。 + +#### 语法: + +```SQL +showVersionStatement + : SHOW VERSION + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW VERSION +``` + +执行结果如下: + +```SQL ++-------+---------+ +|Version|BuildInfo| ++-------+---------+ +|2.0.1.2| 1ca4008| ++-------+---------+ +``` + +### 1.5 查看集群关键参数 + +**含义**:返回当前集群的关键参数。 + +#### 语法: + +```SQL +showVariablesStatement + : SHOW VARIABLES + ; +``` + +关键参数如下: + +1. **ClusterName**:当前集群的名称。 +2. **DataReplicationFactor**:数据副本的数量,表示每个数据分区(DataRegion)的副本数。 +3. **SchemaReplicationFactor**:元数据副本的数量,表示每个元数据分区(SchemaRegion)的副本数。 +4. **DataRegionConsensusProtocolClass**:数据分区(DataRegion)使用的共识协议类。 +5. **SchemaRegionConsensusProtocolClass**:元数据分区(SchemaRegion)使用的共识协议类。 +6. **ConfigNodeConsensusProtocolClass**:配置节点(ConfigNode)使用的共识协议类。 +7. **TimePartitionOrigin**:数据库时间分区的起始时间戳。 +8. **TimePartitionInterval**:数据库的时间分区间隔(单位:毫秒)。 +9. **ReadConsistencyLevel**:读取操作的一致性级别。 +10. **SchemaRegionPerDataNode**:数据节点(DataNode)上的元数据分区(SchemaRegion)数量。 +11. **DataRegionPerDataNode**:数据节点(DataNode)上的数据分区(DataRegion)数量。 +12. **SeriesSlotNum**:数据分区(DataRegion)的序列槽(SeriesSlot)数量。 +13. **SeriesSlotExecutorClass**:序列槽的实现类。 +14. **DiskSpaceWarningThreshold**:磁盘空间告警阈值(单位:百分比)。 +15. **TimestampPrecision**:时间戳精度。 + +#### 示例: + +```SQL +IoTDB> SHOW VARIABLES +``` + +执行结果如下: + +```SQL ++----------------------------------+-----------------------------------------------------------------+ +| Variable| Value| ++----------------------------------+-----------------------------------------------------------------+ +| ClusterName| defaultCluster| +| DataReplicationFactor| 1| +| SchemaReplicationFactor| 1| +| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| +|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| +| TimePartitionOrigin| 0| +| TimePartitionInterval| 604800000| +| ReadConsistencyLevel| strong| +| SchemaRegionPerDataNode| 1| +| DataRegionPerDataNode| 0| +| SeriesSlotNum| 1000| +| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| +| DiskSpaceWarningThreshold| 0.05| +| TimestampPrecision| ms| ++----------------------------------+-----------------------------------------------------------------+ +``` + +### 1.6 查看集群ID + +**含义**:返回当前集群的ID。 + +#### 语法: + +```SQL +showClusterIdStatement + : SHOW (CLUSTERID | CLUSTER_ID) + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CLUSTER_ID +``` + +执行结果如下: + +```SQL ++------------------------------------+ +| ClusterId| ++------------------------------------+ +|40163007-9ec1-4455-aa36-8055d740fcda| +``` + +### 1.7 查看客户端直连的 DataNode 进程所在服务器的时间 + +#### 语法: + +**含义**:返回当前客户端直连的 DataNode 进程所在服务器的时间。 + +```SQL +showCurrentTimestampStatement + : SHOW CURRENT_TIMESTAMP + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW CURRENT_TIMESTAMP +``` + +执行结果如下: + +```SQL ++-----------------------------+ +| CurrentTimestamp| ++-----------------------------+ +|2025-02-17T11:11:52.987+08:00| ++-----------------------------+ +``` + +### 1.8 查看正在执行的查询信息 + +**含义**:用于显示所有正在执行的查询信息。 + +> 更多系统表使用方法请参考[系统表](../Reference/System-Tables.md) + +#### 语法: + +```SQL +showQueriesStatement + : SHOW (QUERIES | QUERY PROCESSLIST) + (WHERE where=booleanExpression)? + (ORDER BY sortItem (',' sortItem)*)? + limitOffsetClause + ; +``` + +**参数解释**: + +1. **WHERE** 子句:需保证过滤的目标列是结果集中存在的列 +2. **ORDER BY** 子句:需保证`sortKey`是结果集中存在的列 +3. **limitOffsetClause**: + - **含义**:用于限制结果集的返回数量。 + - **格式**:`LIMIT , `, `` 是偏移量,`` 是返回的行数。 +4. **QUERIES** 表中的列: + - **query_id**:查询语句的 ID + - **start_time**:查询开始的时间戳,时间戳精度与系统精度一致 + - **datanode_id**:发起查询语句的 DataNode 的ID + - **elapsed_time**:查询的执行耗时,单位是秒 + - **statement**:查询的 SQL 语句 + - **user**:发起查询的用户 + +#### 示例: + +```SQL +IoTDB> SHOW QUERIES WHERE elapsed_time > 30 +``` + +执行结果如下: + +```SQL ++-----------------------+-----------------------------+-----------+------------+------------+----+ +| query_id| start_time|datanode_id|elapsed_time| statement|user| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| ++-----------------------+-----------------------------+-----------+------------+------------+----+ +``` + +### 1.9 查看分区信息 + +**含义**:返回当前集群的分区信息。 + +#### 语法: + +```SQL +showRegionsStatement + : SHOW REGIONS + ; +``` + +#### 示例: + +```SQL +IoTDB> SHOW REGIONS +``` + +执行结果如下: + +```SQL ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | +| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| +| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| ++--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ +``` + + +## 2. 状态设置 + +### 2.1 设置连接的模型 + +**含义**:将当前连接的 sql_dialect 置为树模型/表模型,在树模型和表模型中均可使用该命令。 + +#### 语法: + +```SQL +SET SQL_DIALECT EQ (TABLE | TREE) +``` + +#### 示例: + +```SQL +IoTDB> SET SQL_DIALECT=TABLE +IoTDB> SHOW CURRENT_SQL_DIALECT +``` + +执行结果如下: + +```SQL ++-----------------+ +|CurrentSqlDialect| ++-----------------+ +| TABLE| ++-----------------+ +``` + +### 2.2 更新配置项 + +**含义**:用于更新配置项,执行完成后会进行配置项的热加载,对于支持热修改的配置项会立即生效。 + +#### 语法: + +```SQL +setConfigurationStatement + : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? + ; + +propertyAssignments + : property (',' property)* + ; + +property + : identifier EQ propertyValue + ; + +propertyValue + : DEFAULT + | expression + ; +``` + +**参数解释**: + +1. **propertyAssignments** + - **含义**:更新的配置列表,由多个 `property` 组成。 + - 可以更新多个配置列表,用逗号分隔。 + - **取值**: + - `DEFAULT`:将配置项恢复为默认值。 + - `expression`:具体的值,必须是一个字符串。 +2. **ON INTEGER_VALUE** + - **含义**:指定要更新配置的节点 ID。 + - **可选性**:可选。如果不指定或指定的值低于 0,则更新所有 ConfigNode 和 DataNode 的配置。 + +#### 示例: + +```SQL +IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; +``` + +### 2.3 读取手动修改的配置文件 + +**含义**:用于读取手动修改过的配置文件,并对配置项进行热加载,对于支持热修改的配置项会立即生效。 + +#### 语法: + +```SQL +loadConfigurationStatement + : LOAD CONFIGURATION localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定配置热加载的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `LOCAL`:只对客户端直连的 DataNode 进行配置热加载。 + - `CLUSTER`:对集群中所有 DataNode 进行配置热加载。 + +#### 示例: + +```SQL +IoTDB> LOAD CONFIGURATION ON LOCAL; +``` + +### 2.4 设置系统的状态 + +**含义**:用于设置系统的状态。 + +#### 语法: + +```SQL +setSystemStatusStatement + : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **RUNNING | READONLY** + - **含义**:指定系统的新状态。 + - **取值**: + - `RUNNING`:将系统设置为运行状态,允许读写操作。 + - `READONLY`:将系统设置为只读状态,只允许读取操作,禁止写入操作。 +2. **localOrClusterMode** + - **含义**:指定状态变更的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `LOCAL`:仅对客户端直连的 DataNode 生效。 + - `CLUSTER`:对集群中所有 DataNode 生效。 + +#### 示例: + +```SQL +IoTDB> SET SYSTEM TO READONLY ON CLUSTER; +``` + + +## 3. 数据管理 + +### 3.1 刷写内存表中的数据到磁盘 + +**含义**:将内存表中的数据刷写到磁盘上。 + +#### 语法: + +```SQL +flushStatement + : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? + ; + +booleanValue + : TRUE | FALSE + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **identifier** + - **含义**:指定要刷写的数据库名称。 + - **可选性**:可选。如果不指定,则默认刷写所有数据库。 + - **多个数据库**:可以指定多个数据库名称,用逗号分隔。例如:`FLUSH test_db1, test_db2`。 +2. **booleanValue** + - **含义**:指定刷写的内容。 + - **可选性**:可选。如果不指定,则默认刷写顺序和乱序空间的内存。 + - **取值**: + - `TRUE`:只刷写顺序空间的内存表。 + - `FALSE`:只刷写乱序空间的MemTable。 +3. **localOrClusterMode** + - **含义**:指定刷写的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:只刷写客户端直连的 DataNode 上的内存表。 + - `ON CLUSTER`:刷写集群中所有 DataNode 上的内存表。 + +#### 示例: + +```SQL +IoTDB> FLUSH test_db TRUE ON LOCAL; +``` + +### 3.2 清除 DataNode 上的缓存 + +**含义**:用于清除 DataNode 上的某种类型的缓存。 + +#### 语法: + +```SQL +clearCacheStatement + : CLEAR clearCacheOptions? CACHE localOrClusterMode? + ; + +clearCacheOptions + : ATTRIBUTE + | QUERY + | ALL + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **clearCacheOptions** + - **含义**:指定要清除的缓存类型。 + - **可选性**:可选。如果不指定,默认清除查询缓存(`QUERY`)。 + - **取值**: + - `ATTRIBUTE`:清除设备属性缓存。 + - `QUERY`:清除存储引擎中的查询缓存。 + - `ALL`:清除所有缓存,包括设备属性缓存、查询缓存以及树模型中的模式缓存。 +2. **localOrClusterMode** + - **含义**:指定清除缓存的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:只清除客户端直连的 DataNode 上的缓存。 + - `ON CLUSTER`:清除集群中所有 DataNode 上的缓存。 + +#### 示例: + +```SQL +IoTDB> CLEAR ALL CACHE ON LOCAL; +``` + +## 4. 数据修复 + +### 4.1 启动后台扫描并修复 tsfile 任务 + +**含义**:启动一个后台任务,开始扫描并修复 tsfile,能够修复数据文件内的时间戳乱序类异常。 + +#### 语法: + +```SQL +startRepairDataStatement + : START REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定数据修复的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 + - `ON CLUSTER`:对集群中所有 DataNode 执行。 + +#### 示例: + +```SQL +IoTDB> START REPAIR DATA ON CLUSTER; +``` + +### 4.2 暂停后台修复 tsfile 任务 + +**含义**:暂停后台的修复任务,暂停中的任务可通过再次执行 start repair data 命令恢复。 + +#### 语法: + +```SQL +stopRepairDataStatement + : STOP REPAIR DATA localOrClusterMode? + ; + +localOrClusterMode + : (ON (LOCAL | CLUSTER)) + ; +``` + +**参数解释**: + +1. **localOrClusterMode** + - **含义**:指定数据修复的范围。 + - **可选性**:可选。默认值为 `CLUSTER`。 + - **取值**: + - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 + - `ON CLUSTER`:对集群中所有 DataNode 执行。 + +#### 示例: + +```SQL +IoTDB> STOP REPAIR DATA ON CLUSTER; +``` + +## 5. 终止查询 + +### 5.1 主动终止查询 + +**含义**:使用该命令主动地终止查询。 + +#### 语法: + +```SQL +killQueryStatement + : KILL (QUERY queryId=string | ALL QUERIES) + ; +``` + +**参数解释**: + +1. **QUERY queryId=string** + - **含义**:指定要终止的查询的 ID。 `` 是正在执行的查询的唯一标识符。 + - **获取查询 ID**:可以通过 `SHOW QUERIES` 命令获取所有正在执行的查询及其 ID。 +2. **ALL QUERIES** + - **含义**:终止所有正在执行的查询。 + +#### 示例: + +通过指定 `queryId` 可以中止指定的查询,为了获取正在执行的查询 id,用户可以使用 show queries 命令,该命令将显示所有正在执行的查询列表。 + +```SQL +IoTDB> KILL QUERY 20250108_101015_00000_1; -- 终止指定query +IoTDB> KILL ALL QUERIES; -- 终止所有query +``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md b/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md new file mode 100644 index 000000000..fc6a446c5 --- /dev/null +++ b/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md @@ -0,0 +1,579 @@ + +# 树转表视图 + +## 1. 功能概述 + +IoTDB 提供了树转表功能,支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理: + +* 数据写入阶段,采用树模型语法,支持数据灵活接入和扩展。 +* 数据分析阶段,采用表模型语法,支持通过标准 SQL 查询语言,执行复杂的数据分析。 + +![](/img/tree-to-table-1.png) + +> - V2.0.5 及以后版本支持该功能。 +> - 表视图只读,不允许通过表视图写入数据。 + +## 2. 功能介绍 +### 2.1 创建表视图 +#### 2.1.1 语法定义 + +```SQL +-- create (or replace) view on tree +CREATE + [OR REPLACE] + VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) + [comment] + [RESTRICT] + [WITH properties] + AS prefixPath + +viewColumnDefinition + : column_name [dataType] TAG [comment] # tagColumn + | column_name [dataType] TIME [comment] # timeColumn + | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn + ; + +comment + : COMMENT string + ; +``` + +> 注意:列仅支持 tag / field / time,不支持 attribute。 + +#### 2.1.2 语法说明 +1. **`prefixPath`** + +对应树模型的路径,路径最后一级必须为 `**`,且其他层级均不能出现 `*` 或 `**`。该路径确定 VIEW 对应的子树。 + +2. **`view_name`** + +视图名称,与表名相同(具体约束可参考[创建表](../Basic-Concept/Table-Management.md#\_1-1-创建表)),如 db.view。 + +3. **`viewColumnDefinition`** + +* `TAG`:每个 Tag 列按顺序对应`prefixPath`后面层级的路径节点。 +* `FIELD`:FIELD 列对应树模型中的测点(叶子节点)。 + * 若指定了 FIELD 列,则列名使用声明中的`column_name`。 + * 若声明了 `original_measurement`,则直接映射到树模型该测点。否则取小写`column_name` 作为测点名进行树模型映射。 + * 不支持多个 FIELD 映射到树模型同名测点。 + * 若未指定 FIELD 列的 `dataType`,则默认获取树模型映射测点的数据类型。 + * 若树模型中的设备不包含某些声明的 FIELD 列,或与声明的 FIELD 列的数据类型不一致,则在查询该设备时,该 FIELD 列的值永远为 NULL。 + * 若未指定 FIELD 列,则创建时会自动扫描出`prefixPath`子树下所有的测点(包括定义为所有普通序列的测点,以及挂载路径与 `prefixPath `有所重合的所有模板中的测点),列名使用树模型测点名称。 + * 不支持树模型存在名称(含小写)相同但类型不同的测点 + +4. **`WITH properties`** + +目前仅支持 TTL,表示该视图 TTL ms 之前的数据不会在查询时展示,即`WHERE time > now() - TTL`。若树模型设置了 TTL,则查询时取两者中的更小值。 + +> 注意:表视图 TTL 不影响树模型中设备的真实 TTL,当设备数据达到树模型设定的 TTL 后,将被系统物理删除。 + +5. **`OR REPLACE`** + +table 与 view 不能重名。创建时若已存在同名 table ,则会报错;若已存在同名 view ,则进行替换。 + +6. **`RESTRICT`** + +约束匹配树模型设备的层级数(从 prefixPath 下一层开始),若有 RESTRICT 字段,则匹配层级完全等于 tag 数量的 device,否则匹配层级小于等于 tag 数量的 device。默认非 RESTRICT,即匹配层级小于等于 tag 数量的 device。 + +#### 2.1.3 使用示例 +1. 树模型及表视图原型 + +![](/img/tree-to-table-2.png) + +2. 创建表视图 + +* 创建语句 + +```SQL +CREATE OR REPLACE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +with (ttl=604800000) +AS root.db.** +``` + +* 具体说明 + +该语句表示,创建出名为 `viewdb."风机表"` 的视图(viewdb 如不存在会报错),如果该视图已存在,则替换该视图: + +* 为挂载于树模型 root.db.\*\* 路径下面的序列创建表视图。 +* 具备`风机组`、`风机号`两个 `TAG` 列,因此表视图中只包含原树模型中第 3 层上的设备。 +* 具备`电压`、`电流`两个 `FIELD` 列。这里两个 `FIELD` 列对应树模型下的序列名同样是`电压`、`电流`,且仅仅选取类型为 `DOUBLE` 的序列。 + + **​序列名的改名需求:​**如果树模型下的序列名为`current`,想要创建出的表视图中对应的 `FIELD` 列名为`电流`,这种情况下,SQL 变更如下: + + ```SQL + CREATE OR REPLACE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD FROM current + ) + AS root.db.** + with (ttl=604800000) + ``` + +### 2.2 修改表视图 +#### 2.2.1 语法定义 + +修改表视图功能支持修改视图名称、添加列、列重命名、删除列、设置视图的 TTL 属性,以及通过 COMMENT 添加注释。 + +```SQL +-- 修改视图名 +ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier + +-- 在视图中添加某一列 +ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition +viewColumnDefinition + : column_name [dataType] TAG # tagColumn + | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn + +-- 为视图中的某一列重命名 +ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName + +-- 删除视图中的某一列 +ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName + +-- 修改视图的 TTL +ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments + +-- 添加注释 +COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView +COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn +``` + +#### 2.2.2 语法说明 +1. `SET PROPERTIES`操作目前仅支持对表视图的 TTL 属性进行配置。 +2. 删除列功能,仅支持删除物理量列(FIELD),标识列(TAG)不支持删除。 +3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 +#### 2.2.3 使用示例 + +```SQL +-- 修改视图名 +ALTER VIEW IF EXISTS tableview1 RENAME TO tableview + +-- 在视图中添加某一列 +ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field + +-- 为视图中的某一列重命名 +ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp + +-- 删除视图中的某一列 +ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp + +-- 修改视图的 TTL +ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 + +-- 添加注释 +COMMENT ON VIEW tableview IS '树转表' +COMMENT ON COLUMN tableview.status is Null +``` + +### 2.3 删除表视图 +#### 2.3.1 语法定义 + +```SQL +DROP VIEW [IF EXISTS] viewName +``` + +#### 2.3.2 使用示例 + +```SQL +DROP VIEW IF EXISTS tableview +``` + +### 2.4 查看表视图 +#### 2.4.1 **`Show Tables`** +1. 语法定义 + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +2. 语法说明 + +`SHOW TABLES (DETAILS)` 语句通过结果集的`TABLE_TYPE`字段展示表或视图的类型信息: + +| 类型 | `TABLE_TYPE`字段值 | +| -------------------------------------- | ------------------------ | +| 普通表(Table) | `BASE TABLE` | +| 树转表视图(Tree View) | `VIEW FROM TREE` | +| 系统表(Iinformation\_schema.Tables) | `SYSTEM VIEW` | + +3. 使用示例 + +```SQL +IoTDB> show tables details from database1 ++-----------+-----------+------+-------+--------------+ +| TableName| TTL(ms)|Status|Comment| TableType| ++-----------+-----------+------+-------+--------------+ +| tableview| INF| USING| 树转表 |VIEW FROM TREE| +| table1|31536000000| USING| null| BASE TABLE| +| table2|31536000000| USING| null| BASE TABLE| ++-----------+-----------+------+-------+--------------+ + +IoTDB> show tables details from information_schema ++--------------+-------+------+-------+-----------+ +| TableName|TTL(ms)|Status|Comment| TableType| ++--------------+-------+------+-------+-----------+ +| columns| INF| USING| null|SYSTEM VIEW| +| config_nodes| INF| USING| null|SYSTEM VIEW| +|configurations| INF| USING| null|SYSTEM VIEW| +| data_nodes| INF| USING| null|SYSTEM VIEW| +| databases| INF| USING| null|SYSTEM VIEW| +| functions| INF| USING| null|SYSTEM VIEW| +| keywords| INF| USING| null|SYSTEM VIEW| +| models| INF| USING| null|SYSTEM VIEW| +| nodes| INF| USING| null|SYSTEM VIEW| +| pipe_plugins| INF| USING| null|SYSTEM VIEW| +| pipes| INF| USING| null|SYSTEM VIEW| +| queries| INF| USING| null|SYSTEM VIEW| +| regions| INF| USING| null|SYSTEM VIEW| +| subscriptions| INF| USING| null|SYSTEM VIEW| +| tables| INF| USING| null|SYSTEM VIEW| +| topics| INF| USING| null|SYSTEM VIEW| +| views| INF| USING| null|SYSTEM VIEW| ++--------------+-------+------+-------+-----------+ +``` + +#### 2.4.2 **`Show Create Table/View`** +1. 语法定义 + +```SQL +SHOW CREATE TABLE|VIEW viewname; +``` + +2. 语法说明 + +* SHOW CREATE TABLE 语句可用于展示普通表或者视图的完整创建信息; +* SHOW CREATE VIEW 语句仅可用于展示视图的完整创建信息; +* 两种语句均不支持用于展示系统表; + +3. 使用示例 + +```SQL +IoTDB> show create table tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +IoTDB> show create view tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +``` + +### 2.5 非对齐与对齐设备的查询差异 + +树转表视图在查询对齐设备和非对齐设备中有 null 值的情况下结果​**可能与等价的树模型 align by device 查询不同**​。 + +* **对齐设备** + * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 + * 表视图的查询表现:与表模型一致,保留全是 null 的行 +* **非对齐设备** + * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 + * 表视图的查询表现:与树模型一致,不保留全是 null 的行 +* **说明示例** + * 对齐 + + ```SQL + -- 树模型写入数据(对齐) + CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) + + -- 创建 VIEW 语句 + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- 查询 + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + | null| + +-------+ + Total line number = 2 + ``` + + * 非对齐 + + ```SQL + -- 树模型写入数据(非对齐) + CREATE TIMESERIES root.db.battery.b1.voltage INT32 + CREATE TIMESERIES root.db.battery.b1.current FLOAT + INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) + + -- 创建 VIEW 语句 + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- 查询 + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + +-------+ + Total line number = 1 + + -- 如果在查询语句中指定了所有 field 列,或是仅指定了非 field 列时,才可以确保查到所有行 + IoTDB> select voltage,current from view1 + +-------+-------+ + |voltage|current| + +-------+-------+ + | 1| 1.0| + | null| 1.0| + +-------+-------+ + Total line number = 2 + + IoTDB> select battery_id from view1 + +-------+ + |battery_id| + +-------+ + | b1| + | b1| + +-------+ + Total line number = 2 + + -- 如果查询中同时有部分 field 列,那最终结果的行数取决于这部分 field 列根据时间戳对齐后的行数 + IoTDB> select time,voltage from view1 + +-----------------------------+-------+ + | time|voltage| + +-----------------------------+-------+ + |1970-01-01T08:00:00.001+08:00| 1| + +-----------------------------+-------+ + Total line number = 1 + ``` + +## 3. 场景示例 +### 3.1 原树模型管理了多种类型的设备 + +* 场景中不同类型的设备具备不同的层级路径和测点集合。 +* ​**写入时**​:在数据库节点下按设备类型创建分支,每种设备下可以有不同的测点结构 +* ​**查询时**​:为每种类型的设备建立一张表,每个表具有不同的标签和测点集合 + +![](/img/tree-to-table-3.png) + +**表视图的创建 SQL:** + +```SQL +-- 风机表 +CREATE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +AS root.db."风机".** + +-- 电机表 +CREATE VIEW viewdb."电机表" + ("电机组" TAG, + "电机号" TAG, + "功率" FLOAT FIELD, + "电量" FLOAT FIELD, + "温度" FLOAT FIELD + ) +AS root.db."电机".** +``` + +### 3.2 原树模型中没有设备,只有测点 + +如场站的监控系统中,每个测点都有唯一编号,但无法对应到某些设备 + +> 大宽表形式 + +![](/img/tree-to-table-4.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine + (DCS_PIT_02105A DOUBLE FIELD, + DCS_PIT_02105B DOUBLE FIELD, + DCS_PIT_02105C DOUBLE FIELD, + ... + DCS_XI_02716A DOUBLE FIELD + ) +AS root.db.** +``` + +### 3.3 原树模型中一个设备既有子设备,也有测点 + +如在储能场景中,每一层结构都要监控其电压和电流 + +* ​**写入时**​:按照物理世界的监测点,对每一层结构进行建模 +* ​**查询时**​:按照设备分类,建立多个表对每一层结构信息进行管理 + +![](/img/tree-to-table-5.png) + +**表视图的创建 SQL:** + +```SQL +-- 电池舱表 +CREATE VIEW viewdb."电池舱表" + ("电池站" TAG, + "电池舱" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- 电池堆表 +CREATE VIEW viewdb."电池堆表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- 电池簇表 +CREATE VIEW viewdb."电池簇表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电池簇" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS 'root.db.**' + +-- 电芯表 +CREATE VIEW viewdb."电芯表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电池簇" TAG, + "电芯" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** +``` + +### 3.4 原树模型中一个设备下只有一个测点 + +> 窄表形式 + +#### 3.4.1 所有测点数据类型相同 + +![](/img/tree-to-table-6.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** +``` + +#### 3.4.2 测点的数据类型不相同 +##### 3.4.2.1 为每一种数据类型的测点建一个窄表视图 + +​**优点**​:表视图数量是常数个,仅与系统中的数据类型相关 + +​**缺点**​:查询某一个测点值时,需要提前知道其数据类型,再去决定查询哪张表视图 + +![](/img/tree-to-table-7.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine_float + ( + sensor_id STRING TAG, + value FLOAT FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_double + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int32 + ( + sensor_id STRING TAG, + value INT32 FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int64 + ( + sensor_id STRING TAG, + value INT64 FIELD + ) +AS root.db.** + +... +``` + +##### 3.4.2.2 为每一个测点建一个表 + +​**优点**​:查询某一个测点值时,不需要先查一下数据类型,再去决定查询哪张表,简单便捷 + +​**缺点**​:当测点数量较多时,会引入过多的表视图,需要写大量的建视图语句 + +![](/img/tree-to-table-8.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.DCS_PIT_02105A + ( + value FLOAT FIELD + ) +AS root.db.DCS_PIT_02105A.** + +CREATE VIEW viewdb.DCS_PIT_02105B + ( + value DOUBLE FIELD + ) +AS root.db.DCS_PIT_02105B.** + +CREATE VIEW viewdb.DCS_XI_02716A + ( + value INT64 FIELD + ) +AS root.db.DCS_XI_02716A.** + +...... +``` diff --git a/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md b/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md new file mode 100644 index 000000000..fc6a446c5 --- /dev/null +++ b/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md @@ -0,0 +1,579 @@ + +# 树转表视图 + +## 1. 功能概述 + +IoTDB 提供了树转表功能,支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理: + +* 数据写入阶段,采用树模型语法,支持数据灵活接入和扩展。 +* 数据分析阶段,采用表模型语法,支持通过标准 SQL 查询语言,执行复杂的数据分析。 + +![](/img/tree-to-table-1.png) + +> - V2.0.5 及以后版本支持该功能。 +> - 表视图只读,不允许通过表视图写入数据。 + +## 2. 功能介绍 +### 2.1 创建表视图 +#### 2.1.1 语法定义 + +```SQL +-- create (or replace) view on tree +CREATE + [OR REPLACE] + VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) + [comment] + [RESTRICT] + [WITH properties] + AS prefixPath + +viewColumnDefinition + : column_name [dataType] TAG [comment] # tagColumn + | column_name [dataType] TIME [comment] # timeColumn + | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn + ; + +comment + : COMMENT string + ; +``` + +> 注意:列仅支持 tag / field / time,不支持 attribute。 + +#### 2.1.2 语法说明 +1. **`prefixPath`** + +对应树模型的路径,路径最后一级必须为 `**`,且其他层级均不能出现 `*` 或 `**`。该路径确定 VIEW 对应的子树。 + +2. **`view_name`** + +视图名称,与表名相同(具体约束可参考[创建表](../Basic-Concept/Table-Management.md#\_1-1-创建表)),如 db.view。 + +3. **`viewColumnDefinition`** + +* `TAG`:每个 Tag 列按顺序对应`prefixPath`后面层级的路径节点。 +* `FIELD`:FIELD 列对应树模型中的测点(叶子节点)。 + * 若指定了 FIELD 列,则列名使用声明中的`column_name`。 + * 若声明了 `original_measurement`,则直接映射到树模型该测点。否则取小写`column_name` 作为测点名进行树模型映射。 + * 不支持多个 FIELD 映射到树模型同名测点。 + * 若未指定 FIELD 列的 `dataType`,则默认获取树模型映射测点的数据类型。 + * 若树模型中的设备不包含某些声明的 FIELD 列,或与声明的 FIELD 列的数据类型不一致,则在查询该设备时,该 FIELD 列的值永远为 NULL。 + * 若未指定 FIELD 列,则创建时会自动扫描出`prefixPath`子树下所有的测点(包括定义为所有普通序列的测点,以及挂载路径与 `prefixPath `有所重合的所有模板中的测点),列名使用树模型测点名称。 + * 不支持树模型存在名称(含小写)相同但类型不同的测点 + +4. **`WITH properties`** + +目前仅支持 TTL,表示该视图 TTL ms 之前的数据不会在查询时展示,即`WHERE time > now() - TTL`。若树模型设置了 TTL,则查询时取两者中的更小值。 + +> 注意:表视图 TTL 不影响树模型中设备的真实 TTL,当设备数据达到树模型设定的 TTL 后,将被系统物理删除。 + +5. **`OR REPLACE`** + +table 与 view 不能重名。创建时若已存在同名 table ,则会报错;若已存在同名 view ,则进行替换。 + +6. **`RESTRICT`** + +约束匹配树模型设备的层级数(从 prefixPath 下一层开始),若有 RESTRICT 字段,则匹配层级完全等于 tag 数量的 device,否则匹配层级小于等于 tag 数量的 device。默认非 RESTRICT,即匹配层级小于等于 tag 数量的 device。 + +#### 2.1.3 使用示例 +1. 树模型及表视图原型 + +![](/img/tree-to-table-2.png) + +2. 创建表视图 + +* 创建语句 + +```SQL +CREATE OR REPLACE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +with (ttl=604800000) +AS root.db.** +``` + +* 具体说明 + +该语句表示,创建出名为 `viewdb."风机表"` 的视图(viewdb 如不存在会报错),如果该视图已存在,则替换该视图: + +* 为挂载于树模型 root.db.\*\* 路径下面的序列创建表视图。 +* 具备`风机组`、`风机号`两个 `TAG` 列,因此表视图中只包含原树模型中第 3 层上的设备。 +* 具备`电压`、`电流`两个 `FIELD` 列。这里两个 `FIELD` 列对应树模型下的序列名同样是`电压`、`电流`,且仅仅选取类型为 `DOUBLE` 的序列。 + + **​序列名的改名需求:​**如果树模型下的序列名为`current`,想要创建出的表视图中对应的 `FIELD` 列名为`电流`,这种情况下,SQL 变更如下: + + ```SQL + CREATE OR REPLACE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD FROM current + ) + AS root.db.** + with (ttl=604800000) + ``` + +### 2.2 修改表视图 +#### 2.2.1 语法定义 + +修改表视图功能支持修改视图名称、添加列、列重命名、删除列、设置视图的 TTL 属性,以及通过 COMMENT 添加注释。 + +```SQL +-- 修改视图名 +ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier + +-- 在视图中添加某一列 +ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition +viewColumnDefinition + : column_name [dataType] TAG # tagColumn + | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn + +-- 为视图中的某一列重命名 +ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName + +-- 删除视图中的某一列 +ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName + +-- 修改视图的 TTL +ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments + +-- 添加注释 +COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView +COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn +``` + +#### 2.2.2 语法说明 +1. `SET PROPERTIES`操作目前仅支持对表视图的 TTL 属性进行配置。 +2. 删除列功能,仅支持删除物理量列(FIELD),标识列(TAG)不支持删除。 +3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 +#### 2.2.3 使用示例 + +```SQL +-- 修改视图名 +ALTER VIEW IF EXISTS tableview1 RENAME TO tableview + +-- 在视图中添加某一列 +ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field + +-- 为视图中的某一列重命名 +ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp + +-- 删除视图中的某一列 +ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp + +-- 修改视图的 TTL +ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 + +-- 添加注释 +COMMENT ON VIEW tableview IS '树转表' +COMMENT ON COLUMN tableview.status is Null +``` + +### 2.3 删除表视图 +#### 2.3.1 语法定义 + +```SQL +DROP VIEW [IF EXISTS] viewName +``` + +#### 2.3.2 使用示例 + +```SQL +DROP VIEW IF EXISTS tableview +``` + +### 2.4 查看表视图 +#### 2.4.1 **`Show Tables`** +1. 语法定义 + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +2. 语法说明 + +`SHOW TABLES (DETAILS)` 语句通过结果集的`TABLE_TYPE`字段展示表或视图的类型信息: + +| 类型 | `TABLE_TYPE`字段值 | +| -------------------------------------- | ------------------------ | +| 普通表(Table) | `BASE TABLE` | +| 树转表视图(Tree View) | `VIEW FROM TREE` | +| 系统表(Iinformation\_schema.Tables) | `SYSTEM VIEW` | + +3. 使用示例 + +```SQL +IoTDB> show tables details from database1 ++-----------+-----------+------+-------+--------------+ +| TableName| TTL(ms)|Status|Comment| TableType| ++-----------+-----------+------+-------+--------------+ +| tableview| INF| USING| 树转表 |VIEW FROM TREE| +| table1|31536000000| USING| null| BASE TABLE| +| table2|31536000000| USING| null| BASE TABLE| ++-----------+-----------+------+-------+--------------+ + +IoTDB> show tables details from information_schema ++--------------+-------+------+-------+-----------+ +| TableName|TTL(ms)|Status|Comment| TableType| ++--------------+-------+------+-------+-----------+ +| columns| INF| USING| null|SYSTEM VIEW| +| config_nodes| INF| USING| null|SYSTEM VIEW| +|configurations| INF| USING| null|SYSTEM VIEW| +| data_nodes| INF| USING| null|SYSTEM VIEW| +| databases| INF| USING| null|SYSTEM VIEW| +| functions| INF| USING| null|SYSTEM VIEW| +| keywords| INF| USING| null|SYSTEM VIEW| +| models| INF| USING| null|SYSTEM VIEW| +| nodes| INF| USING| null|SYSTEM VIEW| +| pipe_plugins| INF| USING| null|SYSTEM VIEW| +| pipes| INF| USING| null|SYSTEM VIEW| +| queries| INF| USING| null|SYSTEM VIEW| +| regions| INF| USING| null|SYSTEM VIEW| +| subscriptions| INF| USING| null|SYSTEM VIEW| +| tables| INF| USING| null|SYSTEM VIEW| +| topics| INF| USING| null|SYSTEM VIEW| +| views| INF| USING| null|SYSTEM VIEW| ++--------------+-------+------+-------+-----------+ +``` + +#### 2.4.2 **`Show Create Table/View`** +1. 语法定义 + +```SQL +SHOW CREATE TABLE|VIEW viewname; +``` + +2. 语法说明 + +* SHOW CREATE TABLE 语句可用于展示普通表或者视图的完整创建信息; +* SHOW CREATE VIEW 语句仅可用于展示视图的完整创建信息; +* 两种语句均不支持用于展示系统表; + +3. 使用示例 + +```SQL +IoTDB> show create table tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +IoTDB> show create view tableview ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| View| Create View| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| ++---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ +``` + +### 2.5 非对齐与对齐设备的查询差异 + +树转表视图在查询对齐设备和非对齐设备中有 null 值的情况下结果​**可能与等价的树模型 align by device 查询不同**​。 + +* **对齐设备** + * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 + * 表视图的查询表现:与表模型一致,保留全是 null 的行 +* **非对齐设备** + * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 + * 表视图的查询表现:与树模型一致,不保留全是 null 的行 +* **说明示例** + * 对齐 + + ```SQL + -- 树模型写入数据(对齐) + CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) + + -- 创建 VIEW 语句 + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- 查询 + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + | null| + +-------+ + Total line number = 2 + ``` + + * 非对齐 + + ```SQL + -- 树模型写入数据(非对齐) + CREATE TIMESERIES root.db.battery.b1.voltage INT32 + CREATE TIMESERIES root.db.battery.b1.current FLOAT + INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) + INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) + + -- 创建 VIEW 语句 + CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** + + -- 查询 + IoTDB> select voltage from view1 + +-------+ + |voltage| + +-------+ + | 1| + +-------+ + Total line number = 1 + + -- 如果在查询语句中指定了所有 field 列,或是仅指定了非 field 列时,才可以确保查到所有行 + IoTDB> select voltage,current from view1 + +-------+-------+ + |voltage|current| + +-------+-------+ + | 1| 1.0| + | null| 1.0| + +-------+-------+ + Total line number = 2 + + IoTDB> select battery_id from view1 + +-------+ + |battery_id| + +-------+ + | b1| + | b1| + +-------+ + Total line number = 2 + + -- 如果查询中同时有部分 field 列,那最终结果的行数取决于这部分 field 列根据时间戳对齐后的行数 + IoTDB> select time,voltage from view1 + +-----------------------------+-------+ + | time|voltage| + +-----------------------------+-------+ + |1970-01-01T08:00:00.001+08:00| 1| + +-----------------------------+-------+ + Total line number = 1 + ``` + +## 3. 场景示例 +### 3.1 原树模型管理了多种类型的设备 + +* 场景中不同类型的设备具备不同的层级路径和测点集合。 +* ​**写入时**​:在数据库节点下按设备类型创建分支,每种设备下可以有不同的测点结构 +* ​**查询时**​:为每种类型的设备建立一张表,每个表具有不同的标签和测点集合 + +![](/img/tree-to-table-3.png) + +**表视图的创建 SQL:** + +```SQL +-- 风机表 +CREATE VIEW viewdb."风机表" + ("风机组" TAG, + "风机号" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +AS root.db."风机".** + +-- 电机表 +CREATE VIEW viewdb."电机表" + ("电机组" TAG, + "电机号" TAG, + "功率" FLOAT FIELD, + "电量" FLOAT FIELD, + "温度" FLOAT FIELD + ) +AS root.db."电机".** +``` + +### 3.2 原树模型中没有设备,只有测点 + +如场站的监控系统中,每个测点都有唯一编号,但无法对应到某些设备 + +> 大宽表形式 + +![](/img/tree-to-table-4.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine + (DCS_PIT_02105A DOUBLE FIELD, + DCS_PIT_02105B DOUBLE FIELD, + DCS_PIT_02105C DOUBLE FIELD, + ... + DCS_XI_02716A DOUBLE FIELD + ) +AS root.db.** +``` + +### 3.3 原树模型中一个设备既有子设备,也有测点 + +如在储能场景中,每一层结构都要监控其电压和电流 + +* ​**写入时**​:按照物理世界的监测点,对每一层结构进行建模 +* ​**查询时**​:按照设备分类,建立多个表对每一层结构信息进行管理 + +![](/img/tree-to-table-5.png) + +**表视图的创建 SQL:** + +```SQL +-- 电池舱表 +CREATE VIEW viewdb."电池舱表" + ("电池站" TAG, + "电池舱" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- 电池堆表 +CREATE VIEW viewdb."电池堆表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** + +-- 电池簇表 +CREATE VIEW viewdb."电池簇表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电池簇" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS 'root.db.**' + +-- 电芯表 +CREATE VIEW viewdb."电芯表" + ("电池站" TAG, + "电池舱" TAG, + "电池堆" TAG, + "电池簇" TAG, + "电芯" TAG, + "电压" DOUBLE FIELD, + "电流" DOUBLE FIELD + ) +RESTRICT +AS root.db.** +``` + +### 3.4 原树模型中一个设备下只有一个测点 + +> 窄表形式 + +#### 3.4.1 所有测点数据类型相同 + +![](/img/tree-to-table-6.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** +``` + +#### 3.4.2 测点的数据类型不相同 +##### 3.4.2.1 为每一种数据类型的测点建一个窄表视图 + +​**优点**​:表视图数量是常数个,仅与系统中的数据类型相关 + +​**缺点**​:查询某一个测点值时,需要提前知道其数据类型,再去决定查询哪张表视图 + +![](/img/tree-to-table-7.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.machine_float + ( + sensor_id STRING TAG, + value FLOAT FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_double + ( + sensor_id STRING TAG, + value DOUBLE FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int32 + ( + sensor_id STRING TAG, + value INT32 FIELD + ) +AS root.db.** + +CREATE VIEW viewdb.machine_int64 + ( + sensor_id STRING TAG, + value INT64 FIELD + ) +AS root.db.** + +... +``` + +##### 3.4.2.2 为每一个测点建一个表 + +​**优点**​:查询某一个测点值时,不需要先查一下数据类型,再去决定查询哪张表,简单便捷 + +​**缺点**​:当测点数量较多时,会引入过多的表视图,需要写大量的建视图语句 + +![](/img/tree-to-table-8.png) + +**表视图的创建 SQL:** + +```SQL +CREATE VIEW viewdb.DCS_PIT_02105A + ( + value FLOAT FIELD + ) +AS root.db.DCS_PIT_02105A.** + +CREATE VIEW viewdb.DCS_PIT_02105B + ( + value DOUBLE FIELD + ) +AS root.db.DCS_PIT_02105B.** + +CREATE VIEW viewdb.DCS_XI_02716A + ( + value INT64 FIELD + ) +AS root.db.DCS_XI_02716A.** + +...... +``` From 45d76283b72cc663b452fc7cd9deb94cb579a103 Mon Sep 17 00:00:00 2001 From: Leto_b Date: Mon, 12 Jan 2026 17:42:16 +0800 Subject: [PATCH 2/5] add Time Series Data Model and Modeling Design Plan to table management, update related document --- src/.vuepress/sidebar/V2.0.x/en-Table.ts | 14 +- src/.vuepress/sidebar/V2.0.x/zh-Table.ts | 14 +- .../sidebar_timecho/V2.0.x/en-Table.ts | 14 +- .../sidebar_timecho/V2.0.x/zh-Table.ts | 14 +- .../Basic-Concept/Database-Management.md | 172 +---- .../Table/Basic-Concept/TTL-Delete-Data.md | 128 +--- .../Table/Basic-Concept/Table-Management.md | 292 +------- .../Basic-Concept/Table-Management_apache.md | 4 +- .../Basic-Concept/Table-Management_timecho.md | 4 +- .../Table/QuickStart/QuickStart_apache.md | 6 +- .../Table/QuickStart/QuickStart_timecho.md | 6 +- .../Master/Table/Reference/System-Tables.md | 583 +--------------- .../SQL-Manual/SQL-Metadata-Operations.md | 287 +------- .../Table/User-Manual/Maintenance-commands.md | 636 +---------------- .../Master/Table/User-Manual/Tree-to-Table.md | 564 +-------------- .../Basic-Concept/Database-Management.md | 172 +---- .../Database-Management_apache.md | 16 +- .../Database-Management_timecho.md | 16 +- .../Basic-Concept/TTL-Delete-Data.md | 128 +--- .../Basic-Concept/TTL-Delete-Data_apache.md | 6 +- .../Basic-Concept/TTL-Delete-Data_timecho.md | 6 +- .../Basic-Concept/Table-Management.md | 292 +------- .../Basic-Concept/Table-Management_apache.md | 4 +- .../Basic-Concept/Table-Management_timecho.md | 4 +- .../QuickStart/QuickStart_apache.md | 6 +- .../QuickStart/QuickStart_timecho.md | 6 +- .../latest-Table/Reference/System-Tables.md | 583 +--------------- .../Reference/System-Tables_apache.md | 4 +- .../Reference/System-Tables_timecho.md | 4 +- .../SQL-Manual/SQL-Metadata-Operations.md | 287 +------- .../SQL-Metadata-Operations_apache.md | 6 +- .../SQL-Metadata-Operations_timecho.md | 6 +- .../User-Manual/Maintenance-commands.md | 636 +---------------- .../Maintenance-commands_apache.md | 2 +- .../Maintenance-commands_timecho.md | 2 +- .../latest-Table/User-Manual/Tree-to-Table.md | 565 +-------------- .../User-Manual/Tree-to-Table_apache.md | 2 +- .../User-Manual/Tree-to-Table_timecho.md | 2 +- .../Basic-Concept/Database-Management.md | 174 +---- .../Table/Basic-Concept/TTL-Delete-Data.md | 124 +--- .../Table/Basic-Concept/Table-Management.md | 298 +------- .../Table/QuickStart/QuickStart_apache.md | 6 +- .../Table/QuickStart/QuickStart_timecho.md | 6 +- .../Master/Table/Reference/System-Tables.md | 576 +--------------- .../SQL-Manual/SQL-Metadata-Operations.md | 287 +------- .../User-Manual/Maintenance-statement.md | 648 +----------------- .../Master/Table/User-Manual/Tree-to-Table.md | 562 +-------------- .../Basic-Concept/Database-Management.md | 174 +---- .../Database-Management_apache.md | 18 +- .../Database-Management_timecho.md | 18 +- .../Basic-Concept/TTL-Delete-Data.md | 124 +--- .../Basic-Concept/TTL-Delete-Data_apache.md | 6 +- .../Basic-Concept/TTL-Delete-Data_timecho.md | 6 +- .../Basic-Concept/Table-Management.md | 298 +------- .../Basic-Concept/Table-Management_apache.md | 2 +- .../QuickStart/QuickStart_apache.md | 6 +- .../QuickStart/QuickStart_timecho.md | 6 +- .../latest-Table/Reference/System-Tables.md | 576 +--------------- .../Reference/System-Tables_apache.md | 4 +- .../Reference/System-Tables_timecho.md | 4 +- .../SQL-Manual/SQL-Metadata-Operations.md | 287 +------- .../SQL-Metadata-Operations_apache.md | 6 +- .../SQL-Metadata-Operations_timecho.md | 6 +- .../User-Manual/Maintenance-statement.md | 647 +---------------- .../Maintenance-statement_apache.md | 2 +- .../Maintenance-statement_timecho.md | 2 +- .../latest-Table/User-Manual/Tree-to-Table.md | 562 +-------------- .../User-Manual/Tree-to-Table_apache.md | 2 +- .../User-Manual/Tree-to-Table_timecho.md | 2 +- 69 files changed, 219 insertions(+), 10713 deletions(-) diff --git a/src/.vuepress/sidebar/V2.0.x/en-Table.ts b/src/.vuepress/sidebar/V2.0.x/en-Table.ts index ed3e53165..33f440e43 100644 --- a/src/.vuepress/sidebar/V2.0.x/en-Table.ts +++ b/src/.vuepress/sidebar/V2.0.x/en-Table.ts @@ -85,8 +85,8 @@ export const enSidebar = { collapsible: true, prefix: 'Basic-Concept/', children: [ - { text: 'Database Management', link: 'Database-Management' }, - { text: 'Table Management', link: 'Table-Management' }, + { text: 'Database Management', link: 'Database-Management_apache' }, + { text: 'Table Management', link: 'Table-Management_apache' }, { text: 'Write&Updata Data', link: 'Write-Updata-Data_apache' }, { text: 'Query Data', link: 'Query-Data_apache' }, { @@ -94,7 +94,7 @@ export const enSidebar = { collapsible: true, children: [ { text: 'Delete Data', link: 'Delete-Data' }, - { text: 'TTL Delete Data', link: 'TTL-Delete-Data' }, + { text: 'TTL Delete Data', link: 'TTL-Delete-Data_apache' }, { text: 'SpaceTL Delete Data', link: 'SpaceTL-Delete' }, ], }, @@ -114,14 +114,14 @@ export const enSidebar = { { text: 'Authority Management', link: 'Authority-Management_apache' }, ], }, - { text: 'Tree-to-Table Mapping', link: 'Tree-to-Table' }, + { text: 'Tree-to-Table Mapping', link: 'Tree-to-Table_apache' }, { text: 'System Maintenance', collapsible: true, children: [ { text: 'Query Performance Analysis', link: 'Query-Performance-Analysis' }, { text: 'Cluster Maintenance', link: 'Load-Balance' }, - { text: 'Maintenance statement', link: 'Maintenance-commands' }, + { text: 'Maintenance statement', link: 'Maintenance-commands_apache' }, ], }, ], @@ -212,7 +212,7 @@ export const enSidebar = { collapsible: true, prefix: 'SQL-Manual/', children: [ - { text: 'Metadata Operations', link: 'SQL-Metadata-Operations' }, + { text: 'Metadata Operations', link: 'SQL-Metadata-Operations_apache' }, { text: 'Data Addition&Deletion', link: 'SQL-Data-Addition-Deletion_apache' }, { text: 'Data Query', @@ -261,7 +261,7 @@ export const enSidebar = { { text: 'Sample Data', link: 'Sample-Data' }, { text: 'Config Manual', link: 'System-Config-Manual' }, { text: 'Status Codes', link: 'Status-Codes' }, - { text: 'System Tables', link: 'System-Tables' }, + { text: 'System Tables', link: 'System-Tables_apache' }, ], }, { diff --git a/src/.vuepress/sidebar/V2.0.x/zh-Table.ts b/src/.vuepress/sidebar/V2.0.x/zh-Table.ts index db5c1f605..7d2d162a7 100644 --- a/src/.vuepress/sidebar/V2.0.x/zh-Table.ts +++ b/src/.vuepress/sidebar/V2.0.x/zh-Table.ts @@ -85,8 +85,8 @@ export const zhSidebar = { collapsible: true, prefix: 'Basic-Concept/', children: [ - { text: '数据库管理', link: 'Database-Management' }, - { text: '表管理', link: 'Table-Management' }, + { text: '数据库管理', link: 'Database-Management_apache' }, + { text: '表管理', link: 'Table-Management_apache' }, { text: '写入&更新', link: 'Write-Updata-Data_apache' }, { text: '数据查询', link: 'Query-Data_apache' }, { @@ -94,7 +94,7 @@ export const zhSidebar = { collapsible: true, children: [ { text: '数据删除', link: 'Delete-Data' }, - { text: '数据保留时间', link: 'TTL-Delete-Data' }, + { text: '数据保留时间', link: 'TTL-Delete-Data_apache' }, { text: 'SpaceTL 删除', link: 'SpaceTL-Delete' }, ], }, @@ -112,14 +112,14 @@ export const zhSidebar = { collapsible: true, children: [{ text: '权限管理', link: 'Authority-Management_apache' }], }, - { text: '树转表视图', link: 'Tree-to-Table' }, + { text: '树转表视图', link: 'Tree-to-Table_apache' }, { text: '系统运维', collapsible: true, children: [ { text: '查询性能分析', link: 'Query-Performance-Analysis' }, { text: '集群维护', link: 'Load-Balance' }, - { text: '运维语句', link: 'Maintenance-statement' }, + { text: '运维语句', link: 'Maintenance-statement_apache' }, ], }, ], @@ -209,7 +209,7 @@ export const zhSidebar = { collapsible: true, prefix: 'SQL-Manual/', children: [ - { text: '元数据操作', link: 'SQL-Metadata-Operations' }, + { text: '元数据操作', link: 'SQL-Metadata-Operations_apache' }, { text: '数据增删', link: 'SQL-Data-Addition-Deletion_apache' }, { text: '数据查询', @@ -258,7 +258,7 @@ export const zhSidebar = { { text: '示例数据', link: 'Sample-Data' }, { text: '配置参数', link: 'System-Config-Manual' }, { text: '状态码', link: 'Status-Codes' }, - { text: '系统表', link: 'System-Tables' }, + { text: '系统表', link: 'System-Tables_apache' }, ], }, { diff --git a/src/.vuepress/sidebar_timecho/V2.0.x/en-Table.ts b/src/.vuepress/sidebar_timecho/V2.0.x/en-Table.ts index 201f6d119..97d48d2b1 100644 --- a/src/.vuepress/sidebar_timecho/V2.0.x/en-Table.ts +++ b/src/.vuepress/sidebar_timecho/V2.0.x/en-Table.ts @@ -102,8 +102,8 @@ export const enSidebar = { collapsible: true, prefix: 'Basic-Concept/', children: [ - { text: 'Database Management', link: 'Database-Management' }, - { text: 'Table Management', link: 'Table-Management' }, + { text: 'Database Management', link: 'Database-Management_timecho' }, + { text: 'Table Management', link: 'Table-Management_timecho' }, { text: 'Write&Updata Data', link: 'Write-Updata-Data_timecho' }, { text: 'Query Data', link: 'Query-Data_timecho' }, { @@ -111,7 +111,7 @@ export const enSidebar = { collapsible: true, children: [ { text: 'Delete Data', link: 'Delete-Data' }, - { text: 'TTL Delete Data', link: 'TTL-Delete-Data' }, + { text: 'TTL Delete Data', link: 'TTL-Delete-Data_timecho' }, { text: 'SpaceTL Delete Data', link: 'SpaceTL-Delete' }, ], }, @@ -133,7 +133,7 @@ export const enSidebar = { ], }, { text: 'Tiered Storage', link: 'Tiered-Storage_timecho' }, - { text: 'Tree-to-Table Mapping', link: 'Tree-to-Table' }, + { text: 'Tree-to-Table Mapping', link: 'Tree-to-Table_timecho' }, { text: 'Timeseries Featured Analysis', link: 'Timeseries-Featured-Analysis_timecho' }, { text: 'System Maintenance', @@ -141,7 +141,7 @@ export const enSidebar = { children: [ { text: 'Query Performance Analysis', link: 'Query-Performance-Analysis' }, { text: 'Cluster Maintenance', link: 'Load-Balance' }, - { text: 'Maintenance statement', link: 'Maintenance-commands' }, + { text: 'Maintenance statement', link: 'Maintenance-commands_timecho' }, ], }, ], @@ -232,7 +232,7 @@ export const enSidebar = { collapsible: true, prefix: 'SQL-Manual/', children: [ - { text: 'Metadata Operations', link: 'SQL-Metadata-Operations' }, + { text: 'Metadata Operations', link: 'SQL-Metadata-Operations_timecho' }, { text: 'Data Addition&Deletion', link: 'SQL-Data-Addition-Deletion_timecho' }, { text: 'Data Query', @@ -282,7 +282,7 @@ export const enSidebar = { { text: 'Sample Data', link: 'Sample-Data' }, { text: 'Config Manual', link: 'System-Config-Manual' }, { text: 'Status Codes', link: 'Status-Codes' }, - { text: 'System Tables', link: 'System-Tables' }, + { text: 'System Tables', link: 'System-Tables_timecho' }, ], }, { diff --git a/src/.vuepress/sidebar_timecho/V2.0.x/zh-Table.ts b/src/.vuepress/sidebar_timecho/V2.0.x/zh-Table.ts index ff6ce3a1c..3924830cd 100644 --- a/src/.vuepress/sidebar_timecho/V2.0.x/zh-Table.ts +++ b/src/.vuepress/sidebar_timecho/V2.0.x/zh-Table.ts @@ -93,8 +93,8 @@ export const zhSidebar = { collapsible: true, prefix: 'Basic-Concept/', children: [ - { text: '数据库管理', link: 'Database-Management' }, - { text: '表管理', link: 'Table-Management' }, + { text: '数据库管理', link: 'Database-Management_timecho' }, + { text: '表管理', link: 'Table-Management_timecho' }, { text: '写入&更新', link: 'Write-Updata-Data_timecho' }, { text: '数据查询', link: 'Query-Data_timecho' }, { @@ -102,7 +102,7 @@ export const zhSidebar = { collapsible: true, children: [ { text: '数据删除', link: 'Delete-Data' }, - { text: '数据保留时间', link: 'TTL-Delete-Data' }, + { text: '数据保留时间', link: 'TTL-Delete-Data_timecho' }, { text: 'SpaceTL 删除', link: 'SpaceTL-Delete' }, ], }, @@ -124,7 +124,7 @@ export const zhSidebar = { ], }, { text: '多级存储', link: 'Tiered-Storage_timecho' }, - { text: '树转表视图', link: 'Tree-to-Table' }, + { text: '树转表视图', link: 'Tree-to-Table_timecho' }, { text: '时序特色分析', link: 'Timeseries-Featured-Analysis_timecho' }, { text: '系统运维', @@ -132,7 +132,7 @@ export const zhSidebar = { children: [ { text: '查询性能分析', link: 'Query-Performance-Analysis' }, { text: '集群维护', link: 'Load-Balance' }, - { text: '运维语句', link: 'Maintenance-statement' }, + { text: '运维语句', link: 'Maintenance-statement_timecho' }, ], }, ], @@ -223,7 +223,7 @@ export const zhSidebar = { collapsible: true, prefix: 'SQL-Manual/', children: [ - { text: '元数据操作', link: 'SQL-Metadata-Operations' }, + { text: '元数据操作', link: 'SQL-Metadata-Operations_timecho' }, { text: '数据增删', link: 'SQL-Data-Addition-Deletion_timecho' }, { text: '数据查询', @@ -273,7 +273,7 @@ export const zhSidebar = { { text: '示例数据', link: 'Sample-Data' }, { text: '配置参数', link: 'System-Config-Manual' }, { text: '状态码', link: 'Status-Codes' }, - { text: '系统表', link: 'System-Tables' }, + { text: '系统表', link: 'System-Tables_timecho' }, ], }, { diff --git a/src/UserGuide/Master/Table/Basic-Concept/Database-Management.md b/src/UserGuide/Master/Table/Basic-Concept/Database-Management.md index a59ce22ae..c2236d44a 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/Database-Management.md +++ b/src/UserGuide/Master/Table/Basic-Concept/Database-Management.md @@ -1,3 +1,6 @@ +--- +redirectTo: Database-Management_apache.html +--- - -# Database Management - -## 1. Database Management - -### 1.1 Create a Database - -This command is used to create a database. - -**Syntax:** - -```SQL - CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? -``` - -**Note: ** - -1. ``: The name of the database, with the following characteristics: - - Case-insensitive. After creation, it will be displayed uniformly in lowercase. - - Can include commas (`,`), underscores (`_`), numbers, letters, and Chinese characters. - - Maximum length is 64 characters. - - Names with special characters or Chinese characters must be enclosed in double quotes (`""`). - -2. `WITH properties`: Property names are case-insensitive. For more details, refer to the case sensitivity rules [case-sensitivity](../SQL-Manual/Identifier.md#2-case-sensitivity)。Configurable properties include: - -| Property | Description | Default Value | -| ----------------------- | ------------------------------------------------------------ | -------------------- | -| TTL | Automatic data expiration time, in milliseconds | `INF` | -| TIME_PARTITION_INTERVAL | Time partition interval for the database, in milliseconds | `604800000` (7 days) | -| SCHEMA_REGION_GROUP_NUM | Number of metadata replica groups; generally does not require modification | `1` | -| DATA_REGION_GROUP_NUM | Number of data replica groups; generally does not require modification | `2` | - -**Examples:** - -```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// Sets TTL to 1 year. -CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); -``` - -### 1.2 Use a Database - -Specify the current database as the namespace for table operations. - -**Syntax:** - -```SQL -USE -``` - -**Example:** - -```SQL -USE database1 -``` - -### 1.3 View the Current Database - -Displays the name of the currently connected database. If no USE statement has been executed, the default is `null`. - -**Syntax:** - -```SQL -SHOW CURRENT_DATABASE -``` - -**Example:** - -```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE test; - -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| iot_database| -+---------------+ -``` - -### 1.4 View All Databases - -Displays all databases and their properties. - -**Syntax:** - -```SQL -SHOW DATABASES (DETAILS)? -``` - -**Columns Explained:** - - -| Column Name | Description | -| ----------------------- | ------------------------------------------------------------ | -| database | Name of the database. | -| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management.md#14-update-tables) . | -| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | -| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | -| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | -| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | - -**Examples:** - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 3| 2| 100000| -| test2| 300| 3| 2| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -|test_prop| 300| 3| 2| 100000| 1| 2| -| test2| 300| 3| 2| 604800000| 1| 2| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -``` - -### 1.5 Update a Database - -Used to modify some attributes in the database. - -**Syntax:** - -```SQL -ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments -``` - -**Note:** - -1. The `ALTER DATABASE` operation currently only supports modifications to the database's `SCHEMA_REGION_GROUP_NUM`, `DATA_REGION_GROUP_NUM`, and `TTL` attributes. - -**Example:** - -```SQL -ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; -``` - -### 1.6 Delete a Database - -Deletes the specified database and all associated tables and data. - -**Syntax:** - -```SQL -DROP DATABASE (IF EXISTS)? -``` - -**Note:** - -1. A database currently in use can still be dropped. -2. Deleting a database removes all its tables and stored data. - -**Example:** - -```SQL -DROP DATABASE IF EXISTS database1 -``` diff --git a/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data.md b/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data.md index 7cc533f63..fde4f19e0 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data.md +++ b/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data.md @@ -1,3 +1,6 @@ +--- +redirectTo: TTL-Delete-Data_apache.html +--- - -# TTL Delete Data - -## 1. Overview - -Time-to-Live (TTL) is a mechanism for defining the lifespan of data in a database. In IoTDB, TTL allows setting table-level expiration policies, enabling the system to automatically delete outdated data periodically. This helps manage disk space efficiently, maintain high query performance, and reduce memory usage. - -TTL values are specified in milliseconds, and once data exceeds its defined lifespan, it becomes unavailable for queries and cannot be written to. However, the physical deletion of expired data occurs later during the compaction process. Note that changes to TTL settings can briefly impact the accessibility of data. - -**Notes:** - -1. TTL defines the expiration time of data in milliseconds, independent of the time precision configuration file. -2. Modifying TTL settings can cause temporary variations in data accessibility. -3. The system eventually removes expired data, though this process may involve some delay.。 -4. The TTL expiration check is based on the data point timestamp, not the write time. - -## 2. Set TTL - -In the table model, IoTDB’s TTL operates at the granularity of individual tables. You can set TTL directly on a table or at the database level. When TTL is configured at the database level, it serves as the default for new tables created within the database. However, each table can still have its own independent TTL settings. - -**Note:** Modifying the database-level TTL does not retroactively affect the TTL settings of existing tables. - -### 2.1 Set TTL for Tables - -If TTL is specified when creating a table using SQL, the table’s TTL takes precedence. Refer to [Table-Management](../Basic-Concept/Table-Management.md)for details. - -Example 1: Setting TTL during table creation: - -```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600) -``` - -Example 2: Changing TTL for an existing table: - -```SQL -ALTER TABLE tableB SET PROPERTIES TTL=3600; -``` - -**Example 3:** If TTL is not specified or set to the default value, it will inherit the database's TTL. By default, the database TTL is `'INF'` (infinite): - -```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("site" string id, "temperature" int32) -ALTER TABLE tableB set properties TTL=DEFAULT -``` - -### 2.2 Set TTL for Databases - -Tables without explicit TTL settings inherit the TTL of their database. Refer to [Database-Management](../Basic-Concept/Database-Management.md)for details. - -Example 4: A database with TTL=3600000 creates tables inheriting this TTL: - -```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) -``` - -Example 5: A database without a TTL setting creates tables without TTL: - -```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) -``` - -Example 6: Setting a table with no TTL explicitly (TTL=INF) in a database with a configured TTL: - -```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') -``` - -## 3. Remove TTL - -To cancel a TTL setting, modify the table's TTL to 'INF'. Note that IoTDB does not currently support modifying the TTL of a database. - -```SQL -ALTER TABLE tableB set properties TTL='INF' -``` - -## 4. View TTL Information - -Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for databases and tables. Refer to [Database-Management](../Basic-Concept/Database-Management.md)、 [Table-Management](../Basic-Concept/Table-Management.md)for details. - -> Note: TTL settings in tree-model will also be shown. - -Example Output: - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 1| 3| 100000| -| test2| 300| 1| 1| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| -+---------+-------+-----------------------+---------------------+---------------------+-----+ -|test_prop| 300| 1| 3| 100000|TABLE| -| test2| 300| 1| 1| 604800000| TREE| -+---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables -+---------+-------+ -|TableName|TTL(ms)| -+---------+-------+ -| grass| 1000| -| bamboo| 300| -| flower| INF| -+---------+-------+ - -IoTDB> show tables details -+---------+-------+----------+ -|TableName|TTL(ms)| Status| -+---------+-------+----------+ -| bean| 300|PRE_CREATE| -| grass| 1000| USING| -| bamboo| 300| USING| -| flower| INF| USING| -+---------+-------+----------+ -``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md b/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md index c78cf2091..cb319a68e 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md +++ b/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md @@ -1,3 +1,6 @@ +--- +redirectTo: Table-Management_apache.html +--- - -# Table Management - -Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: -* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. -* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. - -## 1. Table Management - -### 1.1 Create a Table - -#### 1.1.1 Manually create a table with CREATE - -Manually create a table within the current or specified database.The format is "database name. table name". - -**Syntax:** - -```SQL -createTableStatement - : CREATE TABLE (IF NOT EXISTS)? qualifiedName - '(' (columnDefinition (',' columnDefinition)*)? ')' - charsetDesc? - comment? - (WITH properties)? - ; - -charsetDesc - : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString - ; - -columnDefinition - : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? - | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? - ; - -charsetName - : CHAR SET identifier - | CHARSET identifier - | CHARACTER SET identifier - ; - -comment - : COMMENT string - ; -``` - -**Note:** - -1. If the time column (`TIME`) is not specified, IoTDB automatically adds one. Other columns can be added using the `enable_auto_create_schema` configuration or session interface commands. -2. Column categories default to `FIELD` if not specified. `TAG` and `ATTRIBUTE` columns must be of type `STRING`. -3. Table `TTL` defaults to the database `TTL`. You can omit this property or set it to `default` if the default value is used. -4. ``: - 1. Case-insensitive. After creation, it will be displayed uniformly in lowercase. - 2. Can include special characters such as `~!`"`%`, etc. - 3. Names with special or Chinese characters must be enclosed in double quotes (`""`). - 4. Outer double quotes are not retained in the final table name. For example: `"a""b"` becomes `a"b`. - 5. Note: In SQL, table or column names with special characters or Chinese characters must be wrapped in double quotes. However, in the native API, do not add extra quotes—otherwise, the quotation marks will become part of the name itself. -5. **`columnDefinition`**: Column names share the same characteristics as table names and can include special characters such as `.`. -6. COMMENT adds comments to the table. - -**Examples:** - -```SQL -CREATE TABLE table1 ( - time TIMESTAMP TIME, - region STRING TAG, - plant_id STRING TAG, - device_id STRING TAG, - model_id STRING ATTRIBUTE, - maintenance STRING ATTRIBUTE COMMENT 'maintenance', - temperature FLOAT FIELD COMMENT 'temperature', - humidity FLOAT FIELD COMMENT 'humidity', - status Boolean FIELD COMMENT 'status', - arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' -) COMMENT 'table1' WITH (TTL=31536000000); - - -CREATE TABLE if not exists table2 (); - -CREATE TABLE tableC ( - "Site" STRING TAG, - "Temperature" int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); -``` - -#### 1.1.2 Automatically Create Tables via SESSION - -Tables can be created automatically when inserting data via session. - -**Examples:** - -```Java -try (ITableSession session = - new TableSessionBuilder() - .nodeUrls(Collections.singletonList("127.0.0.1:6667")) - .username("root") - .password("root") - .build()) { - - session.executeNonQueryStatement("CREATE DATABASE db1"); - session.executeNonQueryStatement("use db1"); - - // Insert data without manually creating the table - List columnNameList = - Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); - List dataTypeList = - Arrays.asList( - TSDataType.STRING, - TSDataType.STRING, - TSDataType.STRING, - TSDataType.STRING, - TSDataType.FLOAT, - TSDataType.DOUBLE); - List columnTypeList = - new ArrayList<>( - Arrays.asList( - ColumnCategory.TAG, - ColumnCategory.TAG, - ColumnCategory.TAG, - ColumnCategory.ATTRIBUTE, - ColumnCategory.FIELD, - ColumnCategory.FIELD)); - Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); - for (long timestamp = 0; timestamp < 100; timestamp++) { - int rowIndex = tablet.getRowSize(); - tablet.addTimestamp(rowIndex, timestamp); - tablet.addValue("region_id", rowIndex, "1"); - tablet.addValue("plant_id", rowIndex, "5"); - tablet.addValue("device_id", rowIndex, "3"); - tablet.addValue("model", rowIndex, "A"); - tablet.addValue("temperature", rowIndex, 37.6F); - tablet.addValue("humidity", rowIndex, 111.1); - if (tablet.getRowSize() == tablet.getMaxRowNumber()) { - session.insert(tablet); - tablet.reset(); - } - } - if (tablet.getRowSize() != 0) { - session.insert(tablet); - tablet.reset(); - } -} -``` - -After the code execution is complete, you can use the following statement to verify that the table has been successfully created, including details about the time column, tag columns, attribute columns, and field columns. - -```SQL -IoTDB> desc table1 -+-----------+---------+-----------+-------+ -| ColumnName| DataType| Category|Comment| -+-----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| region_id| STRING| TAG| null| -| plant_id| STRING| TAG| null| -| device_id| STRING| TAG| null| -| model| STRING| ATTRIBUTE| null| -|temperature| FLOAT| FIELD| null| -| humidity| DOUBLE| FIELD| null| -+-----------+---------+-----------+-------+ -``` - -### 1.2 View Tables - -Used to view all tables and their properties in the current or a specified database. - -**Syntax:** - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -**Note:** - -1. If the `FROM` or `IN` clause is specified, the command lists all tables in the specified database. -2. If neither `FROM` nor `IN` is specified, the command lists all tables in the currently selected database. If no database is selected (`USE` statement not executed), an error is returned. -3. When the `DETAILS` option is used, the command shows the current state of each table: - 1. `USING`: The table is available and operational. - 2. `PRE_CREATE`: The table is in the process of being created or the creation has failed; the table is not available. - 3. `PRE_DELETE`: The table is in the process of being deleted or the deletion has failed; the table will remain permanently unavailable. - -**Examples:** - -```SQL -IoTDB> show tables from test_db -+---------+-------+-------+ -|TableName|TTL(ms)|Comment| -+---------+-------+-------+ -| test| INF| TEST| -+---------+-------+-------+ - -IoTDB> show tables details from test_db -+---------+-------+----------+-------+ -|TableName|TTL(ms)| Status|Comment| -+---------+-------+----------+-------+ -| test| INF| USING| TEST| -| turbine| INF|PRE_CREATE| null| -| car| 1000|PRE_DELETE| null| -+---------+-------+----------+-------+ -``` - -### 1.3 View Table Columns - -Used to view column names, data types, categories, and states of a table. - -**Syntax:** - -```SQL -(DESC | DESCRIBE) (DETAILS)? -``` - -**Note:** If the `DETAILS` option is specified, detailed state information of the columns is displayed: - -- `USING`: The column is in normal use. -- `PRE_DELETE`: The column is being deleted or the deletion has failed; it is permanently unavailable. - - - -**Examples:** - -```SQL -IoTDB> desc tableB -+----------+---------+-----------+-------+ -|ColumnName| DataType| Category|Comment| -+----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| a| STRING| TAG| a| -| b| STRING| ATTRIBUTE| b| -| c| INT32| FIELD| c| -+----------+---------+-----------+-------+ - -IoTDB> desc tableB details -+----------+---------+-----------+----------+-------+ -|ColumnName| DataType| Category| Status|Comment| -+----------+---------+-----------+----------+-------+ -| time|TIMESTAMP| TIME| USING| null| -| a| STRING| TAG| USING| a| -| b| STRING| ATTRIBUTE| USING| b| -| c| INT32| FIELD| USING| c| -| d| INT32| FIELD|PRE_DELETE| d| -+----------+---------+-----------+----------+-------+ -``` - -### 1.4 Update Tables - -Used to update a table, including adding or deleting columns and configuring table properties. - -**Syntax:** - -```SQL -ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition #addColumn -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn -// set TTL can use this -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties -| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' -| COMMENT ON COLUMN tableName.column IS 'column_comment' -``` - -**Note::** - -1. The `SET PROPERTIES` operation currently only supports configuring the `TTL` property of a table -2. The delete column function only supports deleting the ATTRIBUTE and FILD columns, and the TAG column does not support deletion. -3. The modified comment will overwrite the original comment. If null is specified, the previous comment will be erased. - -**Example:** - -```SQL -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' -ALTER TABLE tableB set properties TTL=3600 -COMMENT ON TABLE table1 IS 'table1' -COMMENT ON COLUMN table1.a IS null -``` - -### 1.5 Delete Tables - -Used to delete a table. - -**Syntax:** - -```SQL -DROP TABLE (IF EXISTS)? -``` - -**Examples:** - -```SQL -DROP TABLE tableA -DROP TABLE test.tableB -``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md index 9e5d6f433..9cc3cf18a 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md +++ b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md @@ -22,8 +22,8 @@ # Table Management Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: -* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. -* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_apache.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. +* [Timeseries Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. +* [Modeling Scheme Design](../Background-knowledge/Data-Model-and-Terminology_apache.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. ## 1. Table Management diff --git a/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md index c78cf2091..b169d83de 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md +++ b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md @@ -22,8 +22,8 @@ # Table Management Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: -* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. -* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. +* [Timeseries Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. +* [Modeling Scheme Design](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. ## 1. Table Management diff --git a/src/UserGuide/Master/Table/QuickStart/QuickStart_apache.md b/src/UserGuide/Master/Table/QuickStart/QuickStart_apache.md index 612bfbe1a..fe45e3abe 100644 --- a/src/UserGuide/Master/Table/QuickStart/QuickStart_apache.md +++ b/src/UserGuide/Master/Table/QuickStart/QuickStart_apache.md @@ -49,9 +49,9 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - Introduction to Modeling Design:[Data Model and Terminology](../Background-knowledge/Data-Model-and-Terminology_apache.md) - - Introduction to Database:[Database Management](../Basic-Concept/Database-Management.md) + - Introduction to Database:[Database Management](../Basic-Concept/Database-Management_apache.md) - - Introduction to Tables: [Table Management](../Basic-Concept/Table-Management.md) + - Introduction to Tables: [Table Management](../Basic-Concept/Table-Management_apache.md) 2. Data Insertion & Updates: IoTDB provides multiple methods for inserting real-time data, and supports data write-back. For basic data insertion and updating operations, please see [Write&Updata Data](../Basic-Concept/Write-Updata-Data_apache.md) @@ -61,7 +61,7 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - SQL-Based Deletion: For a basic introduction, please refer to [Delete Data](../Basic-Concept/Delete-Data.md) - - Automatic Expiration Deletion (TTL): For a basic introduction, please see [TTL Delete Data](../Basic-Concept/TTL-Delete-Data.md) + - Automatic Expiration Deletion (TTL): For a basic introduction, please see [TTL Delete Data](../Basic-Concept/TTL-Delete-Data_apache.md) 5. Advanced Features: In addition to common database functions such as insertion and querying, IoTDB also supports features like "data synchronization." For specific usage methods, please refer to the respective documents: diff --git a/src/UserGuide/Master/Table/QuickStart/QuickStart_timecho.md b/src/UserGuide/Master/Table/QuickStart/QuickStart_timecho.md index 45bb5644b..e6e165232 100644 --- a/src/UserGuide/Master/Table/QuickStart/QuickStart_timecho.md +++ b/src/UserGuide/Master/Table/QuickStart/QuickStart_timecho.md @@ -56,9 +56,9 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - Introduction to Modeling Design:[Data Model and Terminology](../Background-knowledge/Data-Model-and-Terminology_timecho.md) - - Introduction to Database:[Database Management](../Basic-Concept/Database-Management.md) + - Introduction to Database:[Database Management](../Basic-Concept/Database-Management_timecho.md) - - Introduction to Tables: [Table Management](../Basic-Concept/Table-Management.md) + - Introduction to Tables: [Table Management](../Basic-Concept/Table-Management_timecho.md) 2. Data Insertion & Updates: IoTDB provides multiple methods for inserting real-time data, and supports data write-back. For basic data insertion and updating operations, please see [Write&Updata Data](../Basic-Concept/Write-Updata-Data_timecho.md) @@ -68,7 +68,7 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - SQL-Based Deletion: For a basic introduction, please refer to [Delete Data](../Basic-Concept/Delete-Data.md) - - Automatic Expiration Deletion (TTL): For a basic introduction, please see [TTL Delete Data](../Basic-Concept/TTL-Delete-Data.md) + - Automatic Expiration Deletion (TTL): For a basic introduction, please see [TTL Delete Data](../Basic-Concept/TTL-Delete-Data_timecho.md) 5. Advanced Features: In addition to common database functions such as insertion and querying, IoTDB also supports features like "data synchronization." For specific usage methods, please refer to the respective documents: diff --git a/src/UserGuide/Master/Table/Reference/System-Tables.md b/src/UserGuide/Master/Table/Reference/System-Tables.md index 3d7c27e4a..c8ac85f91 100644 --- a/src/UserGuide/Master/Table/Reference/System-Tables.md +++ b/src/UserGuide/Master/Table/Reference/System-Tables.md @@ -1,3 +1,6 @@ +--- +redirectTo: System-Tables_apache.html +--- - -# System Tables - -IoTDB has a built-in system database called `INFORMATION_SCHEMA`, which contains a series of system tables for storing IoTDB runtime information (such as currently executing SQL statements, etc.). Currently, the `INFORMATION_SCHEMA` database only supports read operations. - -## 1. System Database - -* ​**Name**​: `INFORMATION_SCHEMA` -* ​**Commands**​: Read-only, only supports `Show databases (DETAILS)` / `Show Tables (DETAILS)` / `Use`. Other operations will result in an error: `"The database 'information_schema' can only be queried."` -* ​**Attributes**​:` TTL=INF`, other attributes default to `null ` -* ​**SQL Example**​: - -```sql -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show tables from information_schema -+--------------+-------+ -| TableName|TTL(ms)| -+--------------+-------+ -| columns| INF| -| config_nodes| INF| -|configurations| INF| -| data_nodes| INF| -| databases| INF| -| functions| INF| -| keywords| INF| -| models| INF| -| nodes| INF| -| pipe_plugins| INF| -| pipes| INF| -| queries| INF| -| regions| INF| -| subscriptions| INF| -| tables| INF| -| topics| INF| -| views| INF| -+--------------+-------+ -``` - -## 2. System Tables - -* ​**Names**​: `DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES` (detailed descriptions in later sections) -* ​**Operations**​: Read-only, only supports `SELECT`, `COUNT/SHOW DEVICES`, `DESC`. Any modifications to table structure or content are not allowed and will result in an error: `"The database 'information_schema' can only be queried." ` -* ​**Column Names**​: System table column names are all lowercase by default and separated by underscores (`_`). - -### 2.1 DATABASES - -* Contains information about all databases in the cluster. -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| --------------------------------- | ----------- | ------------- | -------------------------------- | -| `database` | STRING | TAG | Database name | -| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | -| `schema_replication_factor` | INT32 | ATTRIBUTE | Schema replica count | -| `data_replication_factor` | INT32 | ATTRIBUTE | Data replica count | -| `time_partition_interval` | INT64 | ATTRIBUTE | Time partition interval | -| `schema_region_group_num` | INT32 | ATTRIBUTE | Number of schema region groups | -| `data_region_group_num` | INT32 | ATTRIBUTE | Number of data region groups | - -* The query results only display the collection of databases for which you have any permission on the database itself or any table within the database. -* Query Example: - -```sql -IoTDB> select * from information_schema.databases -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -|information_schema| INF| null| null| null| null| null| -| database1| INF| 1| 1| 604800000| 0| 0| -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -``` - -### 2.2 TABLES - -* Contains information about all tables in the cluster. -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ------------------ | ----------- | ------------- | --------------------- | -| `database` | STRING | TAG | Database name | -| `table_name` | STRING | TAG | Table name | -| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | -| `status` | STRING | ATTRIBUTE | Status | -| `comment` | STRING | ATTRIBUTE | Description/comment | - -* Note: Possible values for `status`: `USING`, `PRE_CREATE`, `PRE_DELETE`. For details, refer to the [View Tables](../Basic-Concept/Table-Management.md#12-view-tables) in Table Management documentation -* The query results only display the collection of tables for which you have any permission. -* Query Example: - -```sql -IoTDB> select * from information_schema.tables -+------------------+--------------+-----------+------+-------+-----------+ -| database| table_name| ttl(ms)|status|comment| table_type| -+------------------+--------------+-----------+------+-------+-----------+ -|information_schema| databases| INF| USING| null|SYSTEM VIEW| -|information_schema| models| INF| USING| null|SYSTEM VIEW| -|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| -|information_schema| regions| INF| USING| null|SYSTEM VIEW| -|information_schema| functions| INF| USING| null|SYSTEM VIEW| -|information_schema| keywords| INF| USING| null|SYSTEM VIEW| -|information_schema| columns| INF| USING| null|SYSTEM VIEW| -|information_schema| topics| INF| USING| null|SYSTEM VIEW| -|information_schema|configurations| INF| USING| null|SYSTEM VIEW| -|information_schema| queries| INF| USING| null|SYSTEM VIEW| -|information_schema| tables| INF| USING| null|SYSTEM VIEW| -|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| -|information_schema| nodes| INF| USING| null|SYSTEM VIEW| -|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| -|information_schema| pipes| INF| USING| null|SYSTEM VIEW| -|information_schema| views| INF| USING| null|SYSTEM VIEW| -|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| -| database1| table1|31536000000| USING| null| BASE TABLE| -+------------------+--------------+-----------+------+-------+-----------+ -``` - -### 2.3 REGIONS - -* Contains information about all regions in the cluster. -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ------------------------- | ----------- | ------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `region_id` | INT32 | TAG | Region ID | -| `datanode_id` | INT32 | TAG | DataNode ID | -| `type` | STRING | ATTRIBUTE | Type (`SchemaRegion`/`DataRegion`) | -| `status` | STRING | ATTRIBUTE | Status (`Running`,`Unknown`, etc.) | -| `database` | STRING | ATTRIBUTE | Database name | -| `series_slot_num` | INT32 | ATTRIBUTE | Number of series slots | -| `time_slot_num` | INT64 | ATTRIBUTE | Number of time slots | -| `rpc_address` | STRING | ATTRIBUTE | RPC address | -| `rpc_port` | INT32 | ATTRIBUTE | RPC port | -| `internal_address` | STRING | ATTRIBUTE | Internal communication address | -| `role` | STRING | ATTRIBUTE | Role (`Leader`/`Follower`) | -| `create_time` | TIMESTAMP | ATTRIBUTE | Creation time | -| `tsfile_size_bytes` | INT64 | ATTRIBUTE | - For​**DataRegion with statistics ​**​: Total file size of TsFiles.
- For**DataRegion without statistics**(Unknown):`-1`.
- For​**SchemaRegion**​:`null`. | - -* Only administrators are allowed to perform query operations. -* Query Example: - -```SQL -IoTDB> select * from information_schema.regions -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| -| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| -| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -``` - -### 2.4 QUERIES - -* Contains information about all currently executing queries in the cluster. Can also be queried using the `SHOW QUERIES` syntax. -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| -------------------- | ----------- | ------------- | ------------------------------------------------------------ | -| `query_id` | STRING | TAG | Query ID | -| `start_time` | TIMESTAMP | ATTRIBUTE | Query start timestamp (precision matches system precision) | -| `datanode_id` | INT32 | ATTRIBUTE | DataNode ID that initiated the query | -| `elapsed_time` | FLOAT | ATTRIBUTE | Query execution duration (in seconds) | -| `statement` | STRING | ATTRIBUTE | SQL statement of the query | -| `user` | STRING | ATTRIBUTE | User who initiated the query | - -* For regular users, the query results only display the queries executed by themselves; for administrators, all queries are displayed. -* Query Example: - -```SQL -IoTDB> select * from information_schema.queries -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -| query_id| start_time|datanode_id|elapsed_time| statement|user| -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -``` - -### 2.5 COLUMNS - -* Contains information about all columns in tables across the cluster -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ------------------- | ----------- | ------------- | -------------------- | -| `database` | STRING | TAG | Database name | -| `table_name` | STRING | TAG | Table name | -| `column_name` | STRING | TAG | Column name | -| `datatype` | STRING | ATTRIBUTE | Column data type | -| `category` | STRING | ATTRIBUTE | Column category | -| `status` | STRING | ATTRIBUTE | Column status | -| `comment` | STRING | ATTRIBUTE | Column description | - -Notes: -* Possible values for `status`: `USING`, `PRE_DELETE`. For details, refer to [Viewing Table Columns](../Basic-Concept/Table-Management.html#13-view-table-columns) in Table Management documentation. -* The query results only display the column information of tables for which you have any permission. - -* Query Example: - -```SQL -IoTDB> select * from information_schema.columns where database = 'database1' -+---------+----------+------------+---------+---------+------+-------+ -| database|table_name| column_name| datatype| category|status|comment| -+---------+----------+------------+---------+---------+------+-------+ -|database1| table1| time|TIMESTAMP| TIME| USING| null| -|database1| table1| region| STRING| TAG| USING| null| -|database1| table1| plant_id| STRING| TAG| USING| null| -|database1| table1| device_id| STRING| TAG| USING| null| -|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| -|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| -|database1| table1| temperature| FLOAT| FIELD| USING| null| -|database1| table1| humidity| FLOAT| FIELD| USING| null| -|database1| table1| status| BOOLEAN| FIELD| USING| null| -|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| -+---------+----------+------------+---------+---------+------+-------+ -``` - -### 2.6 PIPES - -* Contains information about all pipes in the cluster -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ----------------------------------- | ----------- | ------------- | ---------------------------------------------------------- | -| `id` | STRING | TAG | Pipe name | -| `creation_time` | TIMESTAMP | ATTRIBUTE | Creation time | -| `state` | STRING | ATTRIBUTE | Pipe status (`RUNNING`/`STOPPED`) | -| `pipe_source` | STRING | ATTRIBUTE | Source plugin parameters | -| `pipe_processor` | STRING | ATTRIBUTE | Processor plugin parameters | -| `pipe_sink` | STRING | ATTRIBUTE | Sink plugin parameters | -| `exception_message` | STRING | ATTRIBUTE | Exception message | -| `remaining_event_count` | INT64 | ATTRIBUTE | Remaining event count (`-1`if Unknown) | -| `estimated_remaining_seconds` | DOUBLE | ATTRIBUTE | Estimated remaining time in seconds (`-1`if Unknown) | - -* Only administrators are allowed to perform operations. -* Query Example: - -```SQL -select * from information_schema.pipes -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -``` - -### 2.7 PIPE\_PLUGINS - -* Contains information about all PIPE plugins in the cluster -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ------------------- | ----------- | ------------- | ----------------------------------------------------- | -| `plugin_name` | STRING | TAG | Plugin name | -| `plugin_type` | STRING | ATTRIBUTE | Plugin type (`Builtin`/`External`) | -| `class_name` | STRING | ATTRIBUTE | Plugin's main class name | -| `plugin_jar` | STRING | ATTRIBUTE | Plugin's JAR file name (`null`for builtin type) | - -* Query Example: - -```SQL -IoTDB> select * from information_schema.pipe_plugins -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -| plugin_name|plugin_type| class_name|plugin_jar| -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| -| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| -| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| -| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| -| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| -| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -``` - -### 2.8 SUBSCRIPTIONS - -* Contains information about all data subscriptions in the cluster -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ---------------------------- | ----------- | ------------- | ------------------------- | -| `topic_name` | STRING | TAG | Subscription topic name | -| `consumer_group_name` | STRING | TAG | Consumer group name | -| `subscribed_consumers` | STRING | ATTRIBUTE | Subscribed consumers | - -* Only administrators are allowed to perform operations. -* Query Example: - -```SQL -IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' -+----------+-------------------+--------------------------------+ -|topic_name|consumer_group_name| subscribed_consumers| -+----------+-------------------+--------------------------------+ -| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| -+----------+-------------------+--------------------------------+ -``` - -### 2.9 TOPICS - -* Contains information about all data subscription topics in the cluster -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| --------------------- | ----------- | ------------- | -------------------------------- | -| `topic_name` | STRING | TAG | Subscription topic name | -| `topic_configs` | STRING | ATTRIBUTE | Topic configuration parameters | - -* Only administrators are allowed to perform operations. -* Query Example: - -```SQL -IoTDB> select * from information_schema.topics -+----------+----------------------------------------------------------------+ -|topic_name| topic_configs| -+----------+----------------------------------------------------------------+ -| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| -+----------+----------------------------------------------------------------+ -``` - -### 2.10 VIEWS Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all table views in the database. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------------ | ----------- | ----------------- | --------------------------------- | -| database | STRING | TAG | Database name | -| table\_name | STRING | TAG | View name | -| view\_definition | STRING | ATTRIBUTE | SQL statement for view creation | - -* The query results only display the collection of views for which you have any permission. -* Query example: - -```SQL -IoTDB> select * from information_schema.views -+---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ -| database|table_name| view_definition| -+---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ -|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| -+---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ -``` - - -### 2.11 MODELS Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all models in the database. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------- | ----------- | ----------------- | ------------------------------------------------------------------------------------------------ | -| model\_id | STRING | TAG | Model name | -| model\_type | STRING | ATTRIBUTE | Model type (Forecast, Anomaly Detection, Custom) | -| state | STRING | ATTRIBUTE | Model status (Available/Unavailable) | -| configs | STRING | ATTRIBUTE | String format of model hyperparameters, consistent with the output of the `show` command | -| notes | STRING | ATTRIBUTE | Model description\* Built-in model: Built-in model in IoTDB\* User-defined model: Custom model | - -* Query example: - -```SQL --- Find all built-in forecast models -IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' -+---------------------+-----------------+------+-------+-----------------------+ -| model_id| model_type| state|configs| notes| -+---------------------+-----------------+------+-------+-----------------------+ -| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -+---------------------+-----------------+------+-------+-----------------------+ -``` - - -### 2.12 FUNCTIONS Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all functions in the database. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------------ | ----------- | ----------------- | -------------------------------------------------------------------------- | -| function\_name | STRING | TAG | Function name | -| function\_type | STRING | ATTRIBUTE | Function type (Built-in/User-defined, Scalar/Aggregation/Table Function) | -| class\_name(udf) | STRING | ATTRIBUTE | Class name if it is a UDF, otherwise null (tentative) | -| state | STRING | ATTRIBUTE | Availability status | - -* Query example: - -```SQL -IoTDB> select * from information_schema.functions where function_type='built-in table function' -+--------------+-----------------------+---------------+---------+ -|function_name | function_type|class_name(udf)| state| -+--------------+-----------------------+---------------+---------+ -| CUMULATE|built-in table function| null|AVAILABLE| -| SESSION|built-in table function| null|AVAILABLE| -| HOP|built-in table function| null|AVAILABLE| -| TUMBLE|built-in table function| null|AVAILABLE| -| FORECAST|built-in table function| null|AVAILABLE| -| VARIATION|built-in table function| null|AVAILABLE| -| CAPACITY|built-in table function| null|AVAILABLE| -+--------------+-----------------------+---------------+---------+ -``` - - -### 2.13 CONFIGURATIONS Table - -> This system table is available starting from version V2.0.5. - -* Contains all configuration properties of the database. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------- | ----------- | ----------------- | ------------------------------ | -| variable | STRING | TAG | Configuration property name | -| value | STRING | ATTRIBUTE | Configuration property value | - -* Only administrators are allowed to perform operations on this table. -* Query example: - -```SQL -IoTDB> select * from information_schema.configurations -+----------------------------------+-----------------------------------------------------------------+ -| variable| value| -+----------------------------------+-----------------------------------------------------------------+ -| ClusterName| defaultCluster| -| DataReplicationFactor| 1| -| SchemaReplicationFactor| 1| -| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| -|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| TimePartitionOrigin| 0| -| TimePartitionInterval| 604800000| -| ReadConsistencyLevel| strong| -| SchemaRegionPerDataNode| 1| -| DataRegionPerDataNode| 0| -| SeriesSlotNum| 1000| -| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| -| DiskSpaceWarningThreshold| 0.05| -| TimestampPrecision| ms| -+----------------------------------+-----------------------------------------------------------------+ -``` - - -### 2.14 KEYWORDS Table - -> This system table is available starting from version V2.0.5. - -* Contains all keywords in the database. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------- | ----------- | ----------------- | ------------------------------------------------- | -| word | STRING | TAG | Keyword | -| reserved | INT32 | ATTRIBUTE | Whether it is a reserved word (1 = Yes, 0 = No) | - -* Query example: - -```SQL -IoTDB> select * from information_schema.keywords limit 10 -+----------+--------+ -| word|reserved| -+----------+--------+ -| ABSENT| 0| -|ACTIVATION| 1| -| ACTIVATE| 1| -| ADD| 0| -| ADMIN| 0| -| AFTER| 0| -| AINODES| 1| -| ALL| 0| -| ALTER| 1| -| ANALYZE| 0| -+----------+--------+ -``` - - -### 2.15 NODES Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all nodes in the database cluster. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| -------------------------------------------- | ----------- | ----------------- | ---------------------- | -| node\_id | INT32 | TAG | Node ID | -| node\_type | STRING | ATTRIBUTE | Node type | -| status | STRING | ATTRIBUTE | Node status | -| internal\_address | STRING | ATTRIBUTE | Internal RPC address | -| internal\_port | INT32 | ATTRIBUTE | Internal port | -| version | STRING | ATTRIBUTE | Version number | -| build\_info | STRING | ATTRIBUTE | Commit ID | -| activate\_status (Enterprise Edition only) | STRING | ATTRIBUTE | Activation status | - -* Only administrators are allowed to perform operations on this table. -* Query example: - -```SQL -IoTDB> select * from information_schema.nodes -+-------+----------+-------+----------------+-------------+-------+----------+ -|node_id| node_type| status|internal_address|internal_port|version|build_info| -+-------+----------+-------+----------------+-------------+-------+----------+ -| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| -| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| -+-------+----------+-------+----------------+-------------+-------+----------+ -``` - - -### 2.16 CONFIG\_NODES Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all ConfigNodes in the cluster. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------------------- | ----------- | ----------------- | --------------------------- | -| node\_id | INT32 | TAG | Node ID | -| config\_consensus\_port | INT32 | ATTRIBUTE | ConfigNode consensus port | -| role | STRING | ATTRIBUTE | ConfigNode role | - -* Only administrators are allowed to perform operations on this table. -* Query example: - -```SQL -IoTDB> select * from information_schema.config_nodes -+-------+---------------------+------+ -|node_id|config_consensus_port| role| -+-------+---------------------+------+ -| 0| 10720|Leader| -+-------+---------------------+------+ -``` - - -### 2.17 DATA\_NODES Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all DataNodes in the cluster. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------------------- | ----------- | ----------------- | ----------------------------- | -| node\_id | INT32 | TAG | Node ID | -| data\_region\_num | INT32 | ATTRIBUTE | Number of DataRegions | -| schema\_region\_num | INT32 | ATTRIBUTE | Number of SchemaRegions | -| rpc\_address | STRING | ATTRIBUTE | RPC address | -| rpc\_port | INT32 | ATTRIBUTE | RPC port | -| mpp\_port | INT32 | ATTRIBUTE | MPP communication port | -| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion consensus port | -| schema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion consensus port | - -* Only administrators are allowed to perform operations on this table. -* Query example: - -```SQL -IoTDB> select * from information_schema.data_nodes -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -``` - -## 3. Permission Description - -* GRANT/REVOKE operations are not supported for the `information_schema` database or any of its tables. -* All users can view `information_schema` database details via the `SHOW DATABASES` statement. -* All users can list system tables via `SHOW TABLES FROM information_schema`. -* All users can inspect system table structures using the `DESC` statement. diff --git a/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations.md b/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations.md index c09789283..6821d5dda 100644 --- a/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations.md +++ b/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations.md @@ -1,3 +1,6 @@ +--- +redirectTo: SQL-Metadata-Operations_apache.html +--- - -# Metadata Operations - -## 1. Database Management - -### 1.1 Create Database - -**Syntax:** - -```SQL -CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? -``` - -[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-1-create-a-database) - -**Examples:** - -```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - --- Create database with 1-year TTL -CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); -``` - -### 1.2 Use Database - -**Syntax:** - -```SQL -USE -``` - -**Examples:** - -```SQL -USE database1 -``` - -### 1.3 View Current Database - -**Syntax:** - -```SQL -SHOW CURRENT_DATABASE -``` - -**Examples:** - -```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE test; - -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| iot_database| -+---------------+ -``` - -### 1.4 List All Databases - -**Syntax:** - -```SQL -SHOW DATABASES (DETAILS)? -``` - -[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-4-view-all-databases) - -**Examples:** - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 3| 2| 100000| -| test2| 300| 3| 2| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -|test_prop| 300| 3| 2| 100000| 1| 2| -| test2| 300| 3| 2| 604800000| 1| 2| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -``` - -### 1.5 Modify Database - -**Syntax:** - -```SQL -ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments -``` - -**Examples:** - -```SQL -ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; -``` - -### 1.6 Drop Database - -**Syntax:** - -```SQL -DROP DATABASE (IF EXISTS)? -``` - -**Examples:** - -```SQL -DROP DATABASE IF EXISTS database1 -``` - -## 2. Table Management - -### 2.1 Create Table - -**Syntax:** - -```SQL -createTableStatement - : CREATE TABLE (IF NOT EXISTS)? qualifiedName - '(' (columnDefinition (',' columnDefinition)*)? ')' - charsetDesc? - comment? - (WITH properties)? - ; - -charsetDesc - : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString - ; - -columnDefinition - : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? - | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? - ; - -charsetName - : CHAR SET identifier - | CHARSET identifier - | CHARACTER SET identifier - ; - -comment - : COMMENT string - ; -``` - -[Detailed syntax reference](../Basic-Concept/Table-Management.md#_1-1-create-a-table) - -**Examples:** - -```SQL -CREATE TABLE table1 ( - time TIMESTAMP TIME, - region STRING TAG, - plant_id STRING TAG, - device_id STRING TAG, - model_id STRING ATTRIBUTE, - maintenance STRING ATTRIBUTE COMMENT 'maintenance', - temperature FLOAT FIELD COMMENT 'temperature', - humidity FLOAT FIELD COMMENT 'humidity', - status BOOLEAN FIELD COMMENT 'status', - arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' -) COMMENT 'table1' WITH (TTL=31536000000); - -CREATE TABLE IF NOT EXISTS table2 (); - -CREATE TABLE tableC ( - "plant" STRING TAG, - "temperature" INT32 FIELD COMMENT 'temperature' -) WITH (TTL=DEFAULT); -``` - -### 2.2 List Tables - -**Syntax:** - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -**Examples:** - -```SQL -IoTDB> show tables from test_db -+---------+-------+-------+ -|TableName|TTL(ms)|Comment| -+---------+-------+-------+ -| test| INF| TEST| -+---------+-------+-------+ - -IoTDB> show tables details from test_db -+---------+-------+----------+-------+ -|TableName|TTL(ms)| Status|Comment| -+---------+-------+----------+-------+ -| test| INF| USING| TEST| -| turbine| INF|PRE_CREATE| null| -| car| 1000|PRE_DELETE| null| -+---------+-------+----------+-------+ -``` - -### 2.3 Describe Table Columns - -**Syntax:** - -```SQL -(DESC | DESCRIBE) (DETAILS)? -``` - -**Examples:** - -```SQL -IoTDB> desc tableB -+----------+---------+-----------+-------+ -|ColumnName| DataType| Category|Comment| -+----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| a| STRING| TAG| a| -| b| STRING| ATTRIBUTE| b| -| c| INT32| FIELD| c| -+----------+---------+-----------+-------+ - -IoTDB> desc tableB details -+----------+---------+-----------+----------+-------+ -|ColumnName| DataType| Category| Status|Comment| -+----------+---------+-----------+----------+-------+ -| time|TIMESTAMP| TIME| USING| null| -| a| STRING| TAG| USING| a| -| b| STRING| ATTRIBUTE| USING| b| -| c| INT32| FIELD| USING| c| -| d| INT32| FIELD|PRE_DELETE| d| -+----------+---------+-----------+----------+-------+ -``` - -### 2.4 Modify Table - -**Syntax:** - -```SQL -ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn -// set TTL can use this -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties -| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' -| COMMENT ON COLUMN tableName.column IS 'column_comment' -``` - -**Examples:** - -```SQL -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' -ALTER TABLE tableB set properties TTL=3600 -COMMENT ON TABLE table1 IS 'table1' -COMMENT ON COLUMN table1.a IS null -``` - -### 2.5 Drop Table - -**Syntax:** - -```SQL -DROP TABLE (IF EXISTS)? -``` - -**Examples:** - -```SQL -DROP TABLE tableA -DROP TABLE test.tableB -``` - - diff --git a/src/UserGuide/Master/Table/User-Manual/Maintenance-commands.md b/src/UserGuide/Master/Table/User-Manual/Maintenance-commands.md index f77af49ce..30e0f15bc 100644 --- a/src/UserGuide/Master/Table/User-Manual/Maintenance-commands.md +++ b/src/UserGuide/Master/Table/User-Manual/Maintenance-commands.md @@ -1,3 +1,6 @@ +--- +redirectTo: Maintenance-statement_apache.html +--- -# Maintenance Statement - -## 1. Status Checking - -### 1.1 Viewing the Connected Model - -**Description**: Returns the current SQL dialect model (`Tree` or `Table`). - -**Syntax**: - -```SQL -showCurrentSqlDialectStatement - : SHOW CURRENT_SQL_DIALECT - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW CURRENT_SQL_DIALECT; -``` - -**Result:** - -```SQL -+-----------------+ -|CurrentSqlDialect| -+-----------------+ -| TABLE| -+-----------------+ -``` - -### 1.2 Viewing the Logged-in Username - -**Description**: Returns the currently logged-in username. - -**Syntax**: - -```SQL -showCurrentUserStatement - : SHOW CURRENT_USER - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW CURRENT_USER; -``` - -**Result**: - -```Plain -+-----------+ -|CurrentUser| -+-----------+ -| root| -+-----------+ -``` - -### 1.3 Viewing the Connected Database Name - -**Description**: Returns the name of the currently connected database. If no `USE` statement has been executed, it returns `null`. - -**Syntax**: - -```SQL -showCurrentDatabaseStatement - : SHOW CURRENT_DATABASE - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW CURRENT_DATABASE; -IoTDB> USE test; -IoTDB> SHOW CURRENT_DATABASE; -``` - -**Result**: - -```Plain -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ -+---------------+ -|CurrentDatabase| -+---------------+ -| test| -+---------------+ -``` - -### 1.4 Viewing the Cluster Version - -**Description**: Returns the current cluster version. - -**Syntax**: - -```SQL -showVersionStatement - : SHOW VERSION - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW VERSION; -``` - -**Result**: - -```Plain -+-------+---------+ -|Version|BuildInfo| -+-------+---------+ -|2.0.1.2| 1ca4008| -+-------+---------+ -``` - -### 1.5 Viewing Cluster Key Parameters - -**Description**: Returns key parameters of the current cluster. - -**Syntax**: - -```SQL -showVariablesStatement - : SHOW VARIABLES - ; -``` - -Key Parameters: - -1. **ClusterName**: The name of the current cluster. -2. **DataReplicationFactor**: Number of data replicas per DataRegion. -3. **SchemaReplicationFactor**: Number of schema replicas per SchemaRegion. -4. **DataRegionConsensusProtocolClass**: Consensus protocol class for DataRegions. -5. **SchemaRegionConsensusProtocolClass**: Consensus protocol class for SchemaRegions. -6. **ConfigNodeConsensusProtocolClass**: Consensus protocol class for ConfigNodes. -7. **TimePartitionOrigin**: The starting timestamp of database time partitions. -8. **TimePartitionInterval**: The interval of database time partitions (in milliseconds). -9. **ReadConsistencyLevel**: The consistency level for read operations. -10. **SchemaRegionPerDataNode**: Number of SchemaRegions per DataNode. -11. **DataRegionPerDataNode**: Number of DataRegions per DataNode. -12. **SeriesSlotNum**: Number of SeriesSlots per DataRegion. -13. **SeriesSlotExecutorClass**: Implementation class for SeriesSlots. -14. **DiskSpaceWarningThreshold**: Disk space warning threshold (in percentage). -15. **TimestampPrecision**: Timestamp precision. - -**Example**: - -```SQL -IoTDB> SHOW VARIABLES; -``` - -**Result**: - -```Plain -+----------------------------------+-----------------------------------------------------------------+ -| Variable| Value| -+----------------------------------+-----------------------------------------------------------------+ -| ClusterName| defaultCluster| -| DataReplicationFactor| 1| -| SchemaReplicationFactor| 1| -| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| -|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| TimePartitionOrigin| 0| -| TimePartitionInterval| 604800000| -| ReadConsistencyLevel| strong| -| SchemaRegionPerDataNode| 1| -| DataRegionPerDataNode| 0| -| SeriesSlotNum| 1000| -| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| -| DiskSpaceWarningThreshold| 0.05| -| TimestampPrecision| ms| -+----------------------------------+-----------------------------------------------------------------+ -``` - -### 1.6 Viewing the Cluster ID - -**Description**: Returns the ID of the current cluster. - -**Syntax**: - -```SQL -showClusterIdStatement - : SHOW (CLUSTERID | CLUSTER_ID) - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW CLUSTER_ID; -``` - -**Result**: - -```Plain -+------------------------------------+ -| ClusterId| -+------------------------------------+ -|40163007-9ec1-4455-aa36-8055d740fcda| -+------------------------------------+ -``` - -### 1.7 Viewing the Timestamp of the Connected DataNode - -**Description**: Returns the current timestamp of the DataNode process directly connected to the client. - -**Syntax**: - -```SQL -showCurrentTimestampStatement - : SHOW CURRENT_TIMESTAMP - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW CURRENT_TIMESTAMP; -``` - -**Result**: - -```Plain -+-----------------------------+ -| CurrentTimestamp| -+-----------------------------+ -|2025-02-17T11:11:52.987+08:00| -+-----------------------------+ -``` - -### 1.8 Viewing Executing Queries - -**Description**: Displays information about all currently executing queries. - -> For more details on how to use system tables, please refer to [System Tables](../Reference/System-Tables.md) - -**Syntax**: - -```SQL -showQueriesStatement - : SHOW (QUERIES | QUERY PROCESSLIST) - (WHERE where=booleanExpression)? - (ORDER BY sortItem (',' sortItem)*)? - limitOffsetClause - ; -``` - -**Parameters**: - -1. **WHERE Clause**: Filters the result set based on specified conditions. -2. **ORDER BY Clause**: Sorts the result set based on specified columns. -3. **limitOffsetClause**: Limits the number of rows returned. - 1. Format: `LIMIT , `. - -**Columns in QUERIES Table**: - -- **query_id**: Unique ID of the query. -- **start_time**: Timestamp when the query started. -- **datanode_id**: ID of the DataNode executing the query. -- **elapsed_time**: Time elapsed since the query started (in seconds). -- **statement**: The SQL statement being executed. -- **user**: The user who initiated the query. - -**Example**: - -```SQL -IoTDB> SHOW QUERIES WHERE elapsed_time > 30; -``` - -**Result**: - -```Plain -+-----------------------+-----------------------------+-----------+------------+------------+----+ -| query_id| start_time|datanode_id|elapsed_time| statement|user| -+-----------------------+-----------------------------+-----------+------------+------------+----+ -|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| -+-----------------------+-----------------------------+-----------+------------+------------+----+ -``` - - -### 1.9 Viewing Region Information - -**Description**: Displays regions' information of the current cluster. - -**Syntax**: - -```SQL -showRegionsStatement - : SHOW REGIONS - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW REGIONS -``` - -**Result**: - -```SQL -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | -| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| -| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -``` - - -## 2. Status Setting - -### 2.1 Setting the Connected Model - -**Description**: Sets the current SQL dialect model to `Tree` or `Table` which can be used in both tree and table models. - -**Syntax**: - -```SQL -SET SQL_DIALECT = (TABLE | TREE); -``` - -**Example**: - -```SQL -IoTDB> SET SQL_DIALECT=TABLE; -IoTDB> SHOW CURRENT_SQL_DIALECT; -``` - -**Result**: - -```SQL -+-----------------+ -|CurrentSqlDialect| -+-----------------+ -| TABLE| -+-----------------+ -``` - -### 2.2 Updating Configuration Items - -**Description**: Updates configuration items. Changes take effect immediately without restarting if the items support hot modification. - -**Syntax**: - -```SQL -setConfigurationStatement - : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? - ; - -propertyAssignments - : property (',' property)* - ; - -property - : identifier EQ propertyValue - ; - -propertyValue - : DEFAULT - | expression - ; -``` - -**Parameters**: - -1. **propertyAssignments**: A list of properties to update. - 1. Format: `property (',' property)*`. - 2. Values: - - `DEFAULT`: Resets the configuration to its default value. - - `expression`: A specific value (must be a string). -2. **ON INTEGER_VALUE** **(Optional):** Specifies the node ID to update. - 1. If not specified or set to a negative value, updates all ConfigNodes and DataNodes. - -**Example**: - -```SQL -IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; -``` - -### 2.3 Loading Manually Modified Configuration Files - -**Description**: Loads manually modified configuration files and hot-loads the changes. Configuration items that support hot modification take effect immediately. - -**Syntax**: - -```SQL -loadConfigurationStatement - : LOAD CONFIGURATION localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **localOrClusterMode** **(Optional):** - 1. Specifies the scope of configuration loading. - 2. Default: `CLUSTER`. - 3. Values: - - `LOCAL`: Loads configuration only on the DataNode directly connected to the client. - - `CLUSTER`: Loads configuration on all DataNodes in the cluster. - -**Example**: - -```SQL -IoTDB> LOAD CONFIGURATION ON LOCAL; -``` - -### 2.4 Setting the System Status - -**Description**: Sets the system status to either `READONLY` or `RUNNING`. - -**Syntax**: - -```SQL -setSystemStatusStatement - : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **RUNNING |** **READONLY**: - 1. **RUNNING**: Sets the system to running mode, allowing both read and write operations. - 2. **READONLY**: Sets the system to read-only mode, allowing only read operations and prohibiting writes. -2. **localOrClusterMode** **(Optional):** - 1. **LOCAL**: Applies the status change only to the DataNode directly connected to the client. - 2. **CLUSTER**: Applies the status change to all DataNodes in the cluster. - 3. **Default**: `ON CLUSTER`. - -**Example**: - -```SQL -IoTDB> SET SYSTEM TO READONLY ON CLUSTER; -``` - -## 3. Data Management - -### 3.1 Flushing Data from Memory to Disk - -**Description**: Flushes data from the memory table to disk. - -**Syntax**: - -```SQL -flushStatement - : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? - ; - -booleanValue - : TRUE | FALSE - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **identifier** **(Optional):** - 1. Specifies the name of the database to flush. - 2. If not specified, all databases are flushed. - 3. **Multiple Databases**: Multiple database names can be specified, separated by commas (e.g., `FLUSH test_db1, test_db2`). -2. **booleanValue** **(****Optional****)**: - 1. Specifies the type of data to flush. - 2. **TRUE**: Flushes only the sequential memory table. - 3. **FALSE**: Flushes only the unsequential MemTable. - 4. **Default**: Flushes both sequential and unsequential memory tables. -3. **localOrClusterMode** **(****Optional****)**: - 1. **ON LOCAL**: Flushes only the memory tables on the DataNode directly connected to the client. - 2. **ON CLUSTER**: Flushes memory tables on all DataNodes in the cluster. - 3. **Default:** `ON CLUSTER`. - -**Example**: - -```SQL -IoTDB> FLUSH test_db TRUE ON LOCAL; -``` - -### 3.2 Clearing Cache on DataNode - -**Description**: Clears a specific type of cache on DataNode. - -**Syntax**: - -```SQL -clearCacheStatement - : CLEAR clearCacheOptions? CACHE localOrClusterMode? - ; - -clearCacheOptions - : ATTRIBUTE - | QUERY - | ALL - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **clearCacheOptions(Optional)**: - 1. Specifies the type of cache to clear. - 2. **ATTRIBUTE**: Clears device attribute cache. - 3. **QUERY**: Clears query cache in the storage engine. - 4. **ALL**: Clears all caches, including device attribute cache, query cache, and schema cache in the tree model. - 5. **Default**: `QUERY`. -2. **localOrClusterMode(Optional)**: - 1. **ON LOCAL**: Clears cache only on the DataNode directly connected to the client. - 2. **ON CLUSTER**: Clears cache on all DataNodes in the cluster. - 3. **Default:** `ON CLUSTER`. - -**Example**: - -```SQL -IoTDB> CLEAR ALL CACHE ON LOCAL; -``` - -## 4. Data Repair - -### 4.1 Starting Background Scan and Repair of TsFiles - -**Description**: Starts a background task to scan and repair TsFiles, fixing issues such as timestamp disorder within data files. - -**Syntax**: - -```SQL -startRepairDataStatement - : START REPAIR DATA localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **localOrClusterMode(Optional)**: - 1. **ON LOCAL**: Executes the repair task only on the DataNode directly connected to the client. - 2. **ON CLUSTER**: Executes the repair task on all DataNodes in the cluster. - 3. **Default:** `ON CLUSTER`. - -**Example**: - -```SQL -IoTDB> START REPAIR DATA ON CLUSTER; -``` - -### 4.2 Pausing Background TsFile Repair Task - -**Description**: Pauses the background repair task. The paused task can be resumed by executing the `START REPAIR DATA` command again. - -**Syntax**: - -```SQL -stopRepairDataStatement - : STOP REPAIR DATA localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **localOrClusterMode** **(Optional):** - 1. **ON LOCAL**: Executes the pause command only on the DataNode directly connected to the client. - 2. **ON CLUSTER**: Executes the pause command on all DataNodes in the cluster. - 3. **Default:** `ON CLUSTER`. - -**Example**: - -```SQL -IoTDB> STOP REPAIR DATA ON CLUSTER; -``` - -## 5. Query Termination - -### 5.1 Terminating Queries - -**Description**: Terminates one or more running queries. - -**Syntax**: - -```SQL -killQueryStatement - : KILL (QUERY queryId=string | ALL QUERIES) - ; -``` - -**Parameters**: - -1. **QUERY** **queryId:** Specifies the ID of the query to terminate. - -- To obtain the `queryId`, use the `SHOW QUERIES` command. - -2. **ALL QUERIES:** Terminates all currently running queries. - -**Example**: - -Terminate a specific query: - -```SQL -IoTDB> KILL QUERY 20250108_101015_00000_1; -``` - -Terminate all queries: - -```SQL -IoTDB> KILL ALL QUERIES; -``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/User-Manual/Tree-to-Table.md b/src/UserGuide/Master/Table/User-Manual/Tree-to-Table.md index 6a155042f..4b9eaa718 100644 --- a/src/UserGuide/Master/Table/User-Manual/Tree-to-Table.md +++ b/src/UserGuide/Master/Table/User-Manual/Tree-to-Table.md @@ -1,3 +1,6 @@ +--- +redirectTo: Tree-to-Table_apache.html +--- -# Tree-to-Table Mapping - -## 1. Functional Overview - -IoTDB introduces a tree-to-table function, which enables the creation of table views from existing tree-model data. This allows querying via table views, achieving collaborative processing of both tree and table models for the same dataset: - -* During the data writing phase, the tree-model syntax is used, supporting flexible data ingestion and expansion. -* During the data analysis phase, the table-model syntax is adopted, allowing complex data analysis through standard SQL queries. - -![](/img/tree-to-table-en-1.png) - -> * This feature supports from version V2.0.5. -> * Table views are read-only, so data cannot be written through them. - - ## 2. Feature Description -### 2.1 Creating a Table View -#### 2.1.1 Syntax Definition - -```SQL --- create (or replace) view on tree -CREATE - [OR REPLACE] - VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) - [comment] - [RESTRICT] - [WITH properties] - AS prefixPath - -viewColumnDefinition - : column_name [dataType] TAG [comment] # tagColumn - | column_name [dataType] TIME [comment] # timeColumn - | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn - ; - -comment - : COMMENT string - ; -``` - -> Note: Columns only support tags, fields, or time; attributes are not supported. - -#### 2.1.2 Syntax Explanation -1. **`prefixPath`** - -Corresponds to the path in the tree model. The last level of the path must be `**`, and no other levels can contain `*`or `**`. This path determines the subtree corresponding to the VIEW. - -2. **`view_name`** - -The name of the view, which follows the same rules as a table name (for specific constraints, refer to [Create Table](../Basic-Concept/Table-Management.md#\_1-1-create-a-table)), e.g., `db.view`. - -3. **`viewColumnDefinition`** - -* `TAG`: Each TAG column corresponds, in order, to the path nodes at the levels following the `prefixPath`. -* `FIELD`: A FIELD column corresponds to a measurement (leaf node) in the tree model. - * If a FIELD column is specified, the column name uses the declared `column_name`. - * If `original_measurement`is declared, it maps directly to that measurement in the tree model. Otherwise, the lowercase `column_name`is used as the measurement name for mapping. - * Mapping multiple FIELD columns to the same measurement name in the tree model is not supported. - * If the `dataType`for a FIELD column is not specified, the system defaults to the data type of the mapped measurement in the tree model. - * If a device in the tree model does not contain certain declared FIELD columns, or if their data types are inconsistent with the declared FIELD columns, the value for that FIELD column will always be `NULL`when querying that device. - * If no FIELD columns are specified, the system automatically scans for all measurements under the `prefixPath`subtree (including all ordinary sequence measurements and measurements defined in any templates whose mounted paths overlap with the `prefixPath`) during creation. The column names will use the measurement names from the tree model. - * The tree model cannot have measurements with the same name (case-insensitive) but different data types. - -4. **`WITH properties`** - -Currently, only TTL is supported. It indicates that data older than TTL (in milliseconds) will not be displayed in query results, i.e., effectively `WHERE time > now() - TTL`. If a TTL is also set in the tree model, the query uses the smaller value of the two. - -> Note: The table view's TTL does not affect the actual TTL of the devices in the tree model. When data reaches the TTL set in the tree model, it will be physically deleted by the system. - -5. **`OR REPLACE`** - -A table and a view cannot have the same name. If a table with the same name already exists during creation, an error will be reported. If a view with the same name already exists, it will be replaced. - -6. **`RESTRICT`** - -This constrains the number of levels of the tree model devices that are matched (starting from the level below the `prefixPath`). If the `RESTRICT`keyword is present, only devices whose level count exactly equals the number of TAG columns are matched. Otherwise, devices whose level count is less than or equal to the number of TAG columns are matched. The default behavior is non-RESTRICT, meaning devices with a level count less than or equal to the number of TAG columns are matched. - -#### 2.1.3 Usage Example -1. Tree Model and Table View Schema - -![](/img/tree-to-table-en-2.png) - -2. Creating the Table View - -* Creation Statement: - -```SQL -CREATE OR REPLACE VIEW viewdb."wind_turbine" - (wind_turbine_group String TAG, - wind_turbine_number String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -with (ttl=604800000) -AS root.db.** -``` - -* Detailed Explanation - -This statement creates a view named `viewdb.wind_turbine`(an error will occur if `viewdb`does not exist). If the view already exists, it will be replaced. - -* It creates a table view for the time series mounted under the tree model path `root.db.**`. -* It has two `TAG` columns, `wind_turbine_group `and `wind_turbine_number`, so the table view will only include devices from the 3rd level of the original tree model. -* It has two `FIELD`columns, `voltage` and `current`. Here, these `FIELD` columns correspond to measurement names in the tree model that are also `voltage` and `current`, and only select time series of type `DOUBLE`. - -**Renaming measurement requirement:** - -If the measurement name in the tree model is `current_new`, but you want the corresponding `FIELD` column name in the table view to be `current`, the SQL should be changed as follows: - -```SQL -CREATE OR REPLACE VIEW viewdb."wind_turbine" - (wind_turbine_group String TAG, - wind_turbine_number String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD FROM current_new - ) -with (ttl=604800000) -AS root.db.** -``` - -### 2.2 Modifying a Table View -#### 2.2.1 Syntax Definition - -The ALTER VIEW function supports modifying the view name, adding columns, renaming columns, deleting columns, setting the view's TTL property, and adding comments via COMMENT. - -```SQL --- Rename view -ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier - --- Add a column to the view -ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition -viewColumnDefinition - : column_name [dataType] TAG # tagColumn - | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn - --- Rename a column in the view -ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName - --- Delete a column from the view -ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName - --- Modify the view's TTL -ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments - --- Add comments -COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView -COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn -``` - -#### 2.2.2 Syntax Explanation -1. The `SET PROPERTIES`operation currently only supports configuring the TTL property for the table view. -2. The `DROP COLUMN`function only supports deleting FIELD columns; TAG columns cannot be deleted. -3. Modifying the comment will overwrite the original comment. If set to `null`, the previous comment will be erased. -#### 2.2.3 Usage Examples - -```SQL --- Rename view -ALTER VIEW IF EXISTS tableview1 RENAME TO tableview - --- Add a column to the view -ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field - --- Rename a column in the view -ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp - --- Delete a column from the view -ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp - --- Modify the view's TTL -ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 - --- Add comments -COMMENT ON VIEW tableview IS 'Tree to Table' -COMMENT ON COLUMN tableview.status is Null -``` - -### 2.3 Deleting a Table View -#### 2.3.1 Syntax Definition - -```SQL -DROP VIEW [IF EXISTS] viewName -``` - -#### 2.3.2 Usage Example - -```SQL -DROP VIEW IF EXISTS tableview -``` - -### 2.4 Viewing Table Views -#### 2.4.1 **`Show Tables`** -1. Syntax Definition - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -2. Syntax Explanation - -The `SHOW TABLES (DETAILS)`statement displays the type information of tables or views through the `TABLE_TYPE`field in the result set: - -| Type | `TABLE_TYPE`Field Value | -| -------------------------------------------- | ----------------------------- | -| Ordinary Table(Table) | `BASE TABLE` | -| Tree-to-Table View (Tree View) | `VIEW FROM TREE` | -| System Table(Iinformation\_schema.Tables) | `SYSTEM VIEW` | - -3. Usage Examples - -```SQL -IoTDB> show tables details from database1 -+-----------+-----------+------+---------------+--------------+ -| TableName| TTL(ms)|Status| Comment| TableType| -+-----------+-----------+------+---------------+--------------+ -| tableview| INF| USING| Tree to Table |VIEW FROM TREE| -| table1|31536000000| USING| null| BASE TABLE| -| table2|31536000000| USING| null| BASE TABLE| -+-----------+-----------+------+---------------+--------------+ - -IoTDB> show tables details from information_schema -+--------------+-------+------+-------+-----------+ -| TableName|TTL(ms)|Status|Comment| TableType| -+--------------+-------+------+-------+-----------+ -| columns| INF| USING| null|SYSTEM VIEW| -| config_nodes| INF| USING| null|SYSTEM VIEW| -|configurations| INF| USING| null|SYSTEM VIEW| -| data_nodes| INF| USING| null|SYSTEM VIEW| -| databases| INF| USING| null|SYSTEM VIEW| -| functions| INF| USING| null|SYSTEM VIEW| -| keywords| INF| USING| null|SYSTEM VIEW| -| models| INF| USING| null|SYSTEM VIEW| -| nodes| INF| USING| null|SYSTEM VIEW| -| pipe_plugins| INF| USING| null|SYSTEM VIEW| -| pipes| INF| USING| null|SYSTEM VIEW| -| queries| INF| USING| null|SYSTEM VIEW| -| regions| INF| USING| null|SYSTEM VIEW| -| subscriptions| INF| USING| null|SYSTEM VIEW| -| tables| INF| USING| null|SYSTEM VIEW| -| topics| INF| USING| null|SYSTEM VIEW| -| views| INF| USING| null|SYSTEM VIEW| -+--------------+-------+------+-------+-----------+ -``` - -#### 2.4.2 **`Show Create Table/View`** -1. Syntax Definition - -```SQL -SHOW CREATE TABLE|VIEW viewname; -``` - -2. Syntax Explanation - -* The `SHOW CREATE TABLE`statement can be used to display the complete creation information for ordinary tables or views. -* The `SHOW CREATE VIEW`statement can only be used to display the complete creation information for views. -* Neither statement can be used to display system tables. - -3. Usage Examples - -```SQL -IoTDB> show create table tableview -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| View| Create View| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ - -IoTDB> show create view tableview -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| View| Create View| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -``` - -### 2.5 Query Differences Between Non-aligned and Aligned Devices - -Queries on tree-to-table views may yield different results compared to equivalent tree model `ALIGN BY DEVICE`queries when dealing with null values in aligned and non-aligned devices. - -* Aligned Devices - * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. - * Table View Query Behavior:Consistent with the table model, rows where all selected fields are null are retained. -* Non-aligned Devices - * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. - * Table View Query Behavior:Consistent with the tree model, rows where all selected fields are null are not retained. -* Explanation Example - * Aligned - - ```SQL - -- Write data in tree model (aligned) - CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) - INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) - INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) - - -- Create VIEW statement - CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** - - -- Query - IoTDB> select voltage from view1 - +-------+ - |voltage| - +-------+ - | 1| - | null| - +-------+ - Total line number = 2 - ``` - - * Non-aligned - - ```SQL - -- Write data in tree model (non-aligned) - CREATE TIMESERIES root.db.battery.b1.voltage INT32 - CREATE TIMESERIES root.db.battery.b1.current FLOAT - INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) - INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) - - -- Create VIEW statement - CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** - - -- Query - IoTDB> select voltage from view1 - +-------+ - |voltage| - +-------+ - | 1| - +-------+ - Total line number = 1 - - -- Can only ensure all rows are retrieved if the query specifies all FIELD columns, or only non-FIELD columns - IoTDB> select voltage,current from view1 - +-------+-------+ - |voltage|current| - +-------+-------+ - | 1| 1.0| - | null| 1.0| - +-------+-------+ - Total line number = 2 - - IoTDB> select battery_id from view1 - +-----------+ - |battery_id| - +-----------+ - | b1| - | b1| - +-----------+ - Total line number = 2 - - -- If the query involves only some FIELD columns, the final number of rows depends on the number of rows after aligning the specified FIELD columns by timestamp. - IoTDB> select time,voltage from view1 - +-----------------------------+-------+ - | time|voltage| - +-----------------------------+-------+ - |1970-01-01T08:00:00.001+08:00| 1| - +-----------------------------+-------+ - Total line number = 1 - ``` - -## 3. Scenario Examples -### 3.1 Managing Multiple Device Types in the Original Tree Model - -* The scenario involves managing different types of devices, each with its own hierarchical path and set of measurements. -* During Data Writing: Create branches under the database node according to device type. Each device type can have a different measurement structure. -* During Querying: Create a separate table for each device type. Each table will have different tags and sets of measurements. - -![](/img/tree-to-table-en-3.png) - -**SQL for Creating a Table View:** - -```SQL --- Wind Turbine Table -CREATE VIEW viewdb.wind_turbine - (wind_turbine_group String TAG, - wind_turbine_number String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -AS root.db.wind_turbine.** - --- Motor Table -CREATE VIEW viewdb.motor - ( motor_group String TAG, - motor_number String TAG, - power FLOAT FIELD, - electricity FLOAT FIELD, - temperature FLOAT FIELD - ) -AS root.db.motor.** -``` - -### 3.2 Original Tree Model Contains Only Measurements, No Devices - -This scenario occurs in systems like station monitoring where each measurement has a unique identifier but cannot be mapped to specific physical devices. - -> Wide Table Form - -![](/img/tree-to-table-en-4.png) - -**SQL for Creating a Table View:** - -```SQL -CREATE VIEW viewdb.machine - (DCS_PIT_02105A DOUBLE FIELD, - DCS_PIT_02105B DOUBLE FIELD, - DCS_PIT_02105C DOUBLE FIELD, - ... - DCS_XI_02716A DOUBLE FIELD - ) -AS root.db.** -``` - -### 3.3 Original Tree Model Where a Device Has Both Sub-devices and Measurements - -This scenario is common in energy storage systems where each hierarchical level requires monitoring of parameters like voltage and current. - -* Writing Phase: Model according to physical monitoring points at each hierarchical level -* Querying Phase: Create multiple tables based on device categories to manage information at each structural level - -![](/img/tree-to-table-en-5.png) - -**SQL for Creating a Table View:** - -```SQL --- Battery Compartment -CREATE VIEW viewdb.battery_compartment - (station String TAG, - batter_compartment String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -RESTRICT -AS root.db.** - --- Battery Stack -CREATE VIEW viewdb.battery_stack - (station String TAG, - batter_compartment String TAG, - battery_stack String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -RESTRICT -AS root.db.** - --- Battery Cluster -CREATE VIEW viewdb.battery_cluster - (station String TAG, - batter_compartment String TAG, - battery_stackString TAG, - battery_cluster String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -RESTRICT -AS 'root.db.**' - --- Battery Ceil -CREATE VIEW viewdb.battery_ceil - (station String TAG, - batter_compartment String TAG, - battery_cluster String TAG, - battery_cluster String TAG, - battery_ceil String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -RESTRICT -AS root.db.** -``` - -### 3.4 Original Tree Model Where a Device Has Only One Measurement Under It - -> Narrow Table Form - -#### 3.4.1 All Measurements Have the Same Data Type - -![](/img/tree-to-table-en-6.png) - -**SQL for Creating a Table View:** - -```SQL -CREATE VIEW viewdb.machine - ( - sensor_id STRING TAG, - value DOUBLE FIELD - ) -AS root.db.** -``` - -#### 3.4.2 Measurements Have Different Data Types -##### 3.4.2.1 Create a Narrow Table View for Each Data Type of Measurement - -**Advantage: ​**The number of table views is constant, only related to the data types in the system. - -**Disadvantage: ​**When querying the value of a specific measurement, its data type must be known in advance to determine which table view to query. - -![](/img/tree-to-table-en-7.png) - -**SQL for Creating a Table View:** - -```SQL -CREATE VIEW viewdb.machine_float - ( - sensor_id STRING TAG, - value FLOAT FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_double - ( - sensor_id STRING TAG, - value DOUBLE FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_int32 - ( - sensor_id STRING TAG, - value INT32 FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_int64 - ( - sensor_id STRING TAG, - value INT64 FIELD - ) -AS root.db.** - -... -``` - -##### 3.4.2.2 Create a Table for Each Measurement - -**Advantage: ​**When querying the value of a specific measurement, there's no need to first check its data type to determine which table to query, making the process simple and convenient. - -**Disadvantage: ​**When there are a large number of measurements, it will introduce too many table views, requiring the writing of a large number of view creation statements. - -![](/img/tree-to-table-en-8.png) - -**SQL for Creating a Table View:** - -```SQL -CREATE VIEW viewdb.DCS_PIT_02105A - ( - value FLOAT FIELD - ) -AS root.db.DCS_PIT_02105A.** - -CREATE VIEW viewdb.DCS_PIT_02105B - ( - value DOUBLE FIELD - ) -AS root.db.DCS_PIT_02105B.** - -CREATE VIEW viewdb.DCS_XI_02716A - ( - value INT64 FIELD - ) -AS root.db.DCS_XI_02716A.** - -...... -``` diff --git a/src/UserGuide/latest-Table/Basic-Concept/Database-Management.md b/src/UserGuide/latest-Table/Basic-Concept/Database-Management.md index a59ce22ae..c2236d44a 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Database-Management.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Database-Management.md @@ -1,3 +1,6 @@ +--- +redirectTo: Database-Management_apache.html +--- - -# Database Management - -## 1. Database Management - -### 1.1 Create a Database - -This command is used to create a database. - -**Syntax:** - -```SQL - CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? -``` - -**Note: ** - -1. ``: The name of the database, with the following characteristics: - - Case-insensitive. After creation, it will be displayed uniformly in lowercase. - - Can include commas (`,`), underscores (`_`), numbers, letters, and Chinese characters. - - Maximum length is 64 characters. - - Names with special characters or Chinese characters must be enclosed in double quotes (`""`). - -2. `WITH properties`: Property names are case-insensitive. For more details, refer to the case sensitivity rules [case-sensitivity](../SQL-Manual/Identifier.md#2-case-sensitivity)。Configurable properties include: - -| Property | Description | Default Value | -| ----------------------- | ------------------------------------------------------------ | -------------------- | -| TTL | Automatic data expiration time, in milliseconds | `INF` | -| TIME_PARTITION_INTERVAL | Time partition interval for the database, in milliseconds | `604800000` (7 days) | -| SCHEMA_REGION_GROUP_NUM | Number of metadata replica groups; generally does not require modification | `1` | -| DATA_REGION_GROUP_NUM | Number of data replica groups; generally does not require modification | `2` | - -**Examples:** - -```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// Sets TTL to 1 year. -CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); -``` - -### 1.2 Use a Database - -Specify the current database as the namespace for table operations. - -**Syntax:** - -```SQL -USE -``` - -**Example:** - -```SQL -USE database1 -``` - -### 1.3 View the Current Database - -Displays the name of the currently connected database. If no USE statement has been executed, the default is `null`. - -**Syntax:** - -```SQL -SHOW CURRENT_DATABASE -``` - -**Example:** - -```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE test; - -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| iot_database| -+---------------+ -``` - -### 1.4 View All Databases - -Displays all databases and their properties. - -**Syntax:** - -```SQL -SHOW DATABASES (DETAILS)? -``` - -**Columns Explained:** - - -| Column Name | Description | -| ----------------------- | ------------------------------------------------------------ | -| database | Name of the database. | -| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management.md#14-update-tables) . | -| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | -| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | -| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | -| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | - -**Examples:** - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 3| 2| 100000| -| test2| 300| 3| 2| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -|test_prop| 300| 3| 2| 100000| 1| 2| -| test2| 300| 3| 2| 604800000| 1| 2| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -``` - -### 1.5 Update a Database - -Used to modify some attributes in the database. - -**Syntax:** - -```SQL -ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments -``` - -**Note:** - -1. The `ALTER DATABASE` operation currently only supports modifications to the database's `SCHEMA_REGION_GROUP_NUM`, `DATA_REGION_GROUP_NUM`, and `TTL` attributes. - -**Example:** - -```SQL -ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; -``` - -### 1.6 Delete a Database - -Deletes the specified database and all associated tables and data. - -**Syntax:** - -```SQL -DROP DATABASE (IF EXISTS)? -``` - -**Note:** - -1. A database currently in use can still be dropped. -2. Deleting a database removes all its tables and stored data. - -**Example:** - -```SQL -DROP DATABASE IF EXISTS database1 -``` diff --git a/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md index a59ce22ae..d4414a17e 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md @@ -119,14 +119,14 @@ SHOW DATABASES (DETAILS)? **Columns Explained:** -| Column Name | Description | -| ----------------------- | ------------------------------------------------------------ | -| database | Name of the database. | -| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management.md#14-update-tables) . | -| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | -| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | -| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | -| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | +| Column Name | Description | +| ----------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| database | Name of the database. | +| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management_apache.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management_apache.md#14-update-tables) . | +| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | +| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | +| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | +| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | **Examples:** diff --git a/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md index a59ce22ae..d24e95e28 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md @@ -119,14 +119,14 @@ SHOW DATABASES (DETAILS)? **Columns Explained:** -| Column Name | Description | -| ----------------------- | ------------------------------------------------------------ | -| database | Name of the database. | -| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management.md#14-update-tables) . | -| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | -| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | -| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | -| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | +| Column Name | Description | +| ----------------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| database | Name of the database. | +| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management_timecho.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management_timecho.md#14-update-tables) . | +| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | +| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | +| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | +| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | **Examples:** diff --git a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data.md b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data.md index 7cc533f63..fde4f19e0 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data.md +++ b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data.md @@ -1,3 +1,6 @@ +--- +redirectTo: TTL-Delete-Data_apache.html +--- - -# TTL Delete Data - -## 1. Overview - -Time-to-Live (TTL) is a mechanism for defining the lifespan of data in a database. In IoTDB, TTL allows setting table-level expiration policies, enabling the system to automatically delete outdated data periodically. This helps manage disk space efficiently, maintain high query performance, and reduce memory usage. - -TTL values are specified in milliseconds, and once data exceeds its defined lifespan, it becomes unavailable for queries and cannot be written to. However, the physical deletion of expired data occurs later during the compaction process. Note that changes to TTL settings can briefly impact the accessibility of data. - -**Notes:** - -1. TTL defines the expiration time of data in milliseconds, independent of the time precision configuration file. -2. Modifying TTL settings can cause temporary variations in data accessibility. -3. The system eventually removes expired data, though this process may involve some delay.。 -4. The TTL expiration check is based on the data point timestamp, not the write time. - -## 2. Set TTL - -In the table model, IoTDB’s TTL operates at the granularity of individual tables. You can set TTL directly on a table or at the database level. When TTL is configured at the database level, it serves as the default for new tables created within the database. However, each table can still have its own independent TTL settings. - -**Note:** Modifying the database-level TTL does not retroactively affect the TTL settings of existing tables. - -### 2.1 Set TTL for Tables - -If TTL is specified when creating a table using SQL, the table’s TTL takes precedence. Refer to [Table-Management](../Basic-Concept/Table-Management.md)for details. - -Example 1: Setting TTL during table creation: - -```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600) -``` - -Example 2: Changing TTL for an existing table: - -```SQL -ALTER TABLE tableB SET PROPERTIES TTL=3600; -``` - -**Example 3:** If TTL is not specified or set to the default value, it will inherit the database's TTL. By default, the database TTL is `'INF'` (infinite): - -```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("site" string id, "temperature" int32) -ALTER TABLE tableB set properties TTL=DEFAULT -``` - -### 2.2 Set TTL for Databases - -Tables without explicit TTL settings inherit the TTL of their database. Refer to [Database-Management](../Basic-Concept/Database-Management.md)for details. - -Example 4: A database with TTL=3600000 creates tables inheriting this TTL: - -```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) -``` - -Example 5: A database without a TTL setting creates tables without TTL: - -```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) -``` - -Example 6: Setting a table with no TTL explicitly (TTL=INF) in a database with a configured TTL: - -```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') -``` - -## 3. Remove TTL - -To cancel a TTL setting, modify the table's TTL to 'INF'. Note that IoTDB does not currently support modifying the TTL of a database. - -```SQL -ALTER TABLE tableB set properties TTL='INF' -``` - -## 4. View TTL Information - -Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for databases and tables. Refer to [Database-Management](../Basic-Concept/Database-Management.md)、 [Table-Management](../Basic-Concept/Table-Management.md)for details. - -> Note: TTL settings in tree-model will also be shown. - -Example Output: - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 1| 3| 100000| -| test2| 300| 1| 1| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| -+---------+-------+-----------------------+---------------------+---------------------+-----+ -|test_prop| 300| 1| 3| 100000|TABLE| -| test2| 300| 1| 1| 604800000| TREE| -+---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables -+---------+-------+ -|TableName|TTL(ms)| -+---------+-------+ -| grass| 1000| -| bamboo| 300| -| flower| INF| -+---------+-------+ - -IoTDB> show tables details -+---------+-------+----------+ -|TableName|TTL(ms)| Status| -+---------+-------+----------+ -| bean| 300|PRE_CREATE| -| grass| 1000| USING| -| bamboo| 300| USING| -| flower| INF| USING| -+---------+-------+----------+ -``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md index 7cc533f63..23789deec 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md +++ b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md @@ -42,7 +42,7 @@ In the table model, IoTDB’s TTL operates at the granularity of individual tabl ### 2.1 Set TTL for Tables -If TTL is specified when creating a table using SQL, the table’s TTL takes precedence. Refer to [Table-Management](../Basic-Concept/Table-Management.md)for details. +If TTL is specified when creating a table using SQL, the table’s TTL takes precedence. Refer to [Table-Management](../Basic-Concept/Table-Management_apache.md)for details. Example 1: Setting TTL during table creation: @@ -66,7 +66,7 @@ ALTER TABLE tableB set properties TTL=DEFAULT ### 2.2 Set TTL for Databases -Tables without explicit TTL settings inherit the TTL of their database. Refer to [Database-Management](../Basic-Concept/Database-Management.md)for details. +Tables without explicit TTL settings inherit the TTL of their database. Refer to [Database-Management](../Basic-Concept/Database-Management_apache.md)for details. Example 4: A database with TTL=3600000 creates tables inheriting this TTL: @@ -102,7 +102,7 @@ ALTER TABLE tableB set properties TTL='INF' ## 4. View TTL Information -Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for databases and tables. Refer to [Database-Management](../Basic-Concept/Database-Management.md)、 [Table-Management](../Basic-Concept/Table-Management.md)for details. +Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for databases and tables. Refer to [Database-Management](../Basic-Concept/Database-Management_apache.md)、 [Table-Management](../Basic-Concept/Table-Management_apache.md)for details. > Note: TTL settings in tree-model will also be shown. diff --git a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md index 7cc533f63..c29379e6b 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md +++ b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md @@ -42,7 +42,7 @@ In the table model, IoTDB’s TTL operates at the granularity of individual tabl ### 2.1 Set TTL for Tables -If TTL is specified when creating a table using SQL, the table’s TTL takes precedence. Refer to [Table-Management](../Basic-Concept/Table-Management.md)for details. +If TTL is specified when creating a table using SQL, the table’s TTL takes precedence. Refer to [Table-Management](../Basic-Concept/Table-Management_timecho.md)for details. Example 1: Setting TTL during table creation: @@ -66,7 +66,7 @@ ALTER TABLE tableB set properties TTL=DEFAULT ### 2.2 Set TTL for Databases -Tables without explicit TTL settings inherit the TTL of their database. Refer to [Database-Management](../Basic-Concept/Database-Management.md)for details. +Tables without explicit TTL settings inherit the TTL of their database. Refer to [Database-Management](../Basic-Concept/Database-Management_timecho.md)for details. Example 4: A database with TTL=3600000 creates tables inheriting this TTL: @@ -102,7 +102,7 @@ ALTER TABLE tableB set properties TTL='INF' ## 4. View TTL Information -Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for databases and tables. Refer to [Database-Management](../Basic-Concept/Database-Management.md)、 [Table-Management](../Basic-Concept/Table-Management.md)for details. +Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for databases and tables. Refer to [Database-Management](../Basic-Concept/Database-Management_timecho.md)、 [Table-Management](../Basic-Concept/Table-Management_timecho.md)for details. > Note: TTL settings in tree-model will also be shown. diff --git a/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md b/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md index c78cf2091..cb319a68e 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md @@ -1,3 +1,6 @@ +--- +redirectTo: Table-Management_apache.html +--- - -# Table Management - -Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: -* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. -* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. - -## 1. Table Management - -### 1.1 Create a Table - -#### 1.1.1 Manually create a table with CREATE - -Manually create a table within the current or specified database.The format is "database name. table name". - -**Syntax:** - -```SQL -createTableStatement - : CREATE TABLE (IF NOT EXISTS)? qualifiedName - '(' (columnDefinition (',' columnDefinition)*)? ')' - charsetDesc? - comment? - (WITH properties)? - ; - -charsetDesc - : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString - ; - -columnDefinition - : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? - | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? - ; - -charsetName - : CHAR SET identifier - | CHARSET identifier - | CHARACTER SET identifier - ; - -comment - : COMMENT string - ; -``` - -**Note:** - -1. If the time column (`TIME`) is not specified, IoTDB automatically adds one. Other columns can be added using the `enable_auto_create_schema` configuration or session interface commands. -2. Column categories default to `FIELD` if not specified. `TAG` and `ATTRIBUTE` columns must be of type `STRING`. -3. Table `TTL` defaults to the database `TTL`. You can omit this property or set it to `default` if the default value is used. -4. ``: - 1. Case-insensitive. After creation, it will be displayed uniformly in lowercase. - 2. Can include special characters such as `~!`"`%`, etc. - 3. Names with special or Chinese characters must be enclosed in double quotes (`""`). - 4. Outer double quotes are not retained in the final table name. For example: `"a""b"` becomes `a"b`. - 5. Note: In SQL, table or column names with special characters or Chinese characters must be wrapped in double quotes. However, in the native API, do not add extra quotes—otherwise, the quotation marks will become part of the name itself. -5. **`columnDefinition`**: Column names share the same characteristics as table names and can include special characters such as `.`. -6. COMMENT adds comments to the table. - -**Examples:** - -```SQL -CREATE TABLE table1 ( - time TIMESTAMP TIME, - region STRING TAG, - plant_id STRING TAG, - device_id STRING TAG, - model_id STRING ATTRIBUTE, - maintenance STRING ATTRIBUTE COMMENT 'maintenance', - temperature FLOAT FIELD COMMENT 'temperature', - humidity FLOAT FIELD COMMENT 'humidity', - status Boolean FIELD COMMENT 'status', - arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' -) COMMENT 'table1' WITH (TTL=31536000000); - - -CREATE TABLE if not exists table2 (); - -CREATE TABLE tableC ( - "Site" STRING TAG, - "Temperature" int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); -``` - -#### 1.1.2 Automatically Create Tables via SESSION - -Tables can be created automatically when inserting data via session. - -**Examples:** - -```Java -try (ITableSession session = - new TableSessionBuilder() - .nodeUrls(Collections.singletonList("127.0.0.1:6667")) - .username("root") - .password("root") - .build()) { - - session.executeNonQueryStatement("CREATE DATABASE db1"); - session.executeNonQueryStatement("use db1"); - - // Insert data without manually creating the table - List columnNameList = - Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); - List dataTypeList = - Arrays.asList( - TSDataType.STRING, - TSDataType.STRING, - TSDataType.STRING, - TSDataType.STRING, - TSDataType.FLOAT, - TSDataType.DOUBLE); - List columnTypeList = - new ArrayList<>( - Arrays.asList( - ColumnCategory.TAG, - ColumnCategory.TAG, - ColumnCategory.TAG, - ColumnCategory.ATTRIBUTE, - ColumnCategory.FIELD, - ColumnCategory.FIELD)); - Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); - for (long timestamp = 0; timestamp < 100; timestamp++) { - int rowIndex = tablet.getRowSize(); - tablet.addTimestamp(rowIndex, timestamp); - tablet.addValue("region_id", rowIndex, "1"); - tablet.addValue("plant_id", rowIndex, "5"); - tablet.addValue("device_id", rowIndex, "3"); - tablet.addValue("model", rowIndex, "A"); - tablet.addValue("temperature", rowIndex, 37.6F); - tablet.addValue("humidity", rowIndex, 111.1); - if (tablet.getRowSize() == tablet.getMaxRowNumber()) { - session.insert(tablet); - tablet.reset(); - } - } - if (tablet.getRowSize() != 0) { - session.insert(tablet); - tablet.reset(); - } -} -``` - -After the code execution is complete, you can use the following statement to verify that the table has been successfully created, including details about the time column, tag columns, attribute columns, and field columns. - -```SQL -IoTDB> desc table1 -+-----------+---------+-----------+-------+ -| ColumnName| DataType| Category|Comment| -+-----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| region_id| STRING| TAG| null| -| plant_id| STRING| TAG| null| -| device_id| STRING| TAG| null| -| model| STRING| ATTRIBUTE| null| -|temperature| FLOAT| FIELD| null| -| humidity| DOUBLE| FIELD| null| -+-----------+---------+-----------+-------+ -``` - -### 1.2 View Tables - -Used to view all tables and their properties in the current or a specified database. - -**Syntax:** - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -**Note:** - -1. If the `FROM` or `IN` clause is specified, the command lists all tables in the specified database. -2. If neither `FROM` nor `IN` is specified, the command lists all tables in the currently selected database. If no database is selected (`USE` statement not executed), an error is returned. -3. When the `DETAILS` option is used, the command shows the current state of each table: - 1. `USING`: The table is available and operational. - 2. `PRE_CREATE`: The table is in the process of being created or the creation has failed; the table is not available. - 3. `PRE_DELETE`: The table is in the process of being deleted or the deletion has failed; the table will remain permanently unavailable. - -**Examples:** - -```SQL -IoTDB> show tables from test_db -+---------+-------+-------+ -|TableName|TTL(ms)|Comment| -+---------+-------+-------+ -| test| INF| TEST| -+---------+-------+-------+ - -IoTDB> show tables details from test_db -+---------+-------+----------+-------+ -|TableName|TTL(ms)| Status|Comment| -+---------+-------+----------+-------+ -| test| INF| USING| TEST| -| turbine| INF|PRE_CREATE| null| -| car| 1000|PRE_DELETE| null| -+---------+-------+----------+-------+ -``` - -### 1.3 View Table Columns - -Used to view column names, data types, categories, and states of a table. - -**Syntax:** - -```SQL -(DESC | DESCRIBE) (DETAILS)? -``` - -**Note:** If the `DETAILS` option is specified, detailed state information of the columns is displayed: - -- `USING`: The column is in normal use. -- `PRE_DELETE`: The column is being deleted or the deletion has failed; it is permanently unavailable. - - - -**Examples:** - -```SQL -IoTDB> desc tableB -+----------+---------+-----------+-------+ -|ColumnName| DataType| Category|Comment| -+----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| a| STRING| TAG| a| -| b| STRING| ATTRIBUTE| b| -| c| INT32| FIELD| c| -+----------+---------+-----------+-------+ - -IoTDB> desc tableB details -+----------+---------+-----------+----------+-------+ -|ColumnName| DataType| Category| Status|Comment| -+----------+---------+-----------+----------+-------+ -| time|TIMESTAMP| TIME| USING| null| -| a| STRING| TAG| USING| a| -| b| STRING| ATTRIBUTE| USING| b| -| c| INT32| FIELD| USING| c| -| d| INT32| FIELD|PRE_DELETE| d| -+----------+---------+-----------+----------+-------+ -``` - -### 1.4 Update Tables - -Used to update a table, including adding or deleting columns and configuring table properties. - -**Syntax:** - -```SQL -ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition #addColumn -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn -// set TTL can use this -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties -| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' -| COMMENT ON COLUMN tableName.column IS 'column_comment' -``` - -**Note::** - -1. The `SET PROPERTIES` operation currently only supports configuring the `TTL` property of a table -2. The delete column function only supports deleting the ATTRIBUTE and FILD columns, and the TAG column does not support deletion. -3. The modified comment will overwrite the original comment. If null is specified, the previous comment will be erased. - -**Example:** - -```SQL -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' -ALTER TABLE tableB set properties TTL=3600 -COMMENT ON TABLE table1 IS 'table1' -COMMENT ON COLUMN table1.a IS null -``` - -### 1.5 Delete Tables - -Used to delete a table. - -**Syntax:** - -```SQL -DROP TABLE (IF EXISTS)? -``` - -**Examples:** - -```SQL -DROP TABLE tableA -DROP TABLE test.tableB -``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md index c78cf2091..9cc3cf18a 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md @@ -22,8 +22,8 @@ # Table Management Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: -* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. -* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. +* [Timeseries Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. +* [Modeling Scheme Design](../Background-knowledge/Data-Model-and-Terminology_apache.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. ## 1. Table Management diff --git a/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md index c78cf2091..b169d83de 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md @@ -22,8 +22,8 @@ # Table Management Before starting to use the table management functionality, we recommend familiarizing yourself with the following related background knowledge for a better understanding and application of the table management features: -* [Time Series Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. -* [Modeling Design Plan](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. +* [Timeseries Data Model](../Background-knowledge/Navigating_Time_Series_Data.md): Understand the basic concepts and characteristics of time series data to establish a foundation for data modeling. +* [Modeling Scheme Design](../Background-knowledge/Data-Model-and-Terminology_timecho.md): Master the IoTDB time series model and its applicable scenarios to provide a design basis for table management. ## 1. Table Management diff --git a/src/UserGuide/latest-Table/QuickStart/QuickStart_apache.md b/src/UserGuide/latest-Table/QuickStart/QuickStart_apache.md index 612bfbe1a..fe45e3abe 100644 --- a/src/UserGuide/latest-Table/QuickStart/QuickStart_apache.md +++ b/src/UserGuide/latest-Table/QuickStart/QuickStart_apache.md @@ -49,9 +49,9 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - Introduction to Modeling Design:[Data Model and Terminology](../Background-knowledge/Data-Model-and-Terminology_apache.md) - - Introduction to Database:[Database Management](../Basic-Concept/Database-Management.md) + - Introduction to Database:[Database Management](../Basic-Concept/Database-Management_apache.md) - - Introduction to Tables: [Table Management](../Basic-Concept/Table-Management.md) + - Introduction to Tables: [Table Management](../Basic-Concept/Table-Management_apache.md) 2. Data Insertion & Updates: IoTDB provides multiple methods for inserting real-time data, and supports data write-back. For basic data insertion and updating operations, please see [Write&Updata Data](../Basic-Concept/Write-Updata-Data_apache.md) @@ -61,7 +61,7 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - SQL-Based Deletion: For a basic introduction, please refer to [Delete Data](../Basic-Concept/Delete-Data.md) - - Automatic Expiration Deletion (TTL): For a basic introduction, please see [TTL Delete Data](../Basic-Concept/TTL-Delete-Data.md) + - Automatic Expiration Deletion (TTL): For a basic introduction, please see [TTL Delete Data](../Basic-Concept/TTL-Delete-Data_apache.md) 5. Advanced Features: In addition to common database functions such as insertion and querying, IoTDB also supports features like "data synchronization." For specific usage methods, please refer to the respective documents: diff --git a/src/UserGuide/latest-Table/QuickStart/QuickStart_timecho.md b/src/UserGuide/latest-Table/QuickStart/QuickStart_timecho.md index 45bb5644b..e6e165232 100644 --- a/src/UserGuide/latest-Table/QuickStart/QuickStart_timecho.md +++ b/src/UserGuide/latest-Table/QuickStart/QuickStart_timecho.md @@ -56,9 +56,9 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - Introduction to Modeling Design:[Data Model and Terminology](../Background-knowledge/Data-Model-and-Terminology_timecho.md) - - Introduction to Database:[Database Management](../Basic-Concept/Database-Management.md) + - Introduction to Database:[Database Management](../Basic-Concept/Database-Management_timecho.md) - - Introduction to Tables: [Table Management](../Basic-Concept/Table-Management.md) + - Introduction to Tables: [Table Management](../Basic-Concept/Table-Management_timecho.md) 2. Data Insertion & Updates: IoTDB provides multiple methods for inserting real-time data, and supports data write-back. For basic data insertion and updating operations, please see [Write&Updata Data](../Basic-Concept/Write-Updata-Data_timecho.md) @@ -68,7 +68,7 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - SQL-Based Deletion: For a basic introduction, please refer to [Delete Data](../Basic-Concept/Delete-Data.md) - - Automatic Expiration Deletion (TTL): For a basic introduction, please see [TTL Delete Data](../Basic-Concept/TTL-Delete-Data.md) + - Automatic Expiration Deletion (TTL): For a basic introduction, please see [TTL Delete Data](../Basic-Concept/TTL-Delete-Data_timecho.md) 5. Advanced Features: In addition to common database functions such as insertion and querying, IoTDB also supports features like "data synchronization." For specific usage methods, please refer to the respective documents: diff --git a/src/UserGuide/latest-Table/Reference/System-Tables.md b/src/UserGuide/latest-Table/Reference/System-Tables.md index 3d7c27e4a..c8ac85f91 100644 --- a/src/UserGuide/latest-Table/Reference/System-Tables.md +++ b/src/UserGuide/latest-Table/Reference/System-Tables.md @@ -1,3 +1,6 @@ +--- +redirectTo: System-Tables_apache.html +--- - -# System Tables - -IoTDB has a built-in system database called `INFORMATION_SCHEMA`, which contains a series of system tables for storing IoTDB runtime information (such as currently executing SQL statements, etc.). Currently, the `INFORMATION_SCHEMA` database only supports read operations. - -## 1. System Database - -* ​**Name**​: `INFORMATION_SCHEMA` -* ​**Commands**​: Read-only, only supports `Show databases (DETAILS)` / `Show Tables (DETAILS)` / `Use`. Other operations will result in an error: `"The database 'information_schema' can only be queried."` -* ​**Attributes**​:` TTL=INF`, other attributes default to `null ` -* ​**SQL Example**​: - -```sql -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show tables from information_schema -+--------------+-------+ -| TableName|TTL(ms)| -+--------------+-------+ -| columns| INF| -| config_nodes| INF| -|configurations| INF| -| data_nodes| INF| -| databases| INF| -| functions| INF| -| keywords| INF| -| models| INF| -| nodes| INF| -| pipe_plugins| INF| -| pipes| INF| -| queries| INF| -| regions| INF| -| subscriptions| INF| -| tables| INF| -| topics| INF| -| views| INF| -+--------------+-------+ -``` - -## 2. System Tables - -* ​**Names**​: `DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES` (detailed descriptions in later sections) -* ​**Operations**​: Read-only, only supports `SELECT`, `COUNT/SHOW DEVICES`, `DESC`. Any modifications to table structure or content are not allowed and will result in an error: `"The database 'information_schema' can only be queried." ` -* ​**Column Names**​: System table column names are all lowercase by default and separated by underscores (`_`). - -### 2.1 DATABASES - -* Contains information about all databases in the cluster. -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| --------------------------------- | ----------- | ------------- | -------------------------------- | -| `database` | STRING | TAG | Database name | -| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | -| `schema_replication_factor` | INT32 | ATTRIBUTE | Schema replica count | -| `data_replication_factor` | INT32 | ATTRIBUTE | Data replica count | -| `time_partition_interval` | INT64 | ATTRIBUTE | Time partition interval | -| `schema_region_group_num` | INT32 | ATTRIBUTE | Number of schema region groups | -| `data_region_group_num` | INT32 | ATTRIBUTE | Number of data region groups | - -* The query results only display the collection of databases for which you have any permission on the database itself or any table within the database. -* Query Example: - -```sql -IoTDB> select * from information_schema.databases -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -|information_schema| INF| null| null| null| null| null| -| database1| INF| 1| 1| 604800000| 0| 0| -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -``` - -### 2.2 TABLES - -* Contains information about all tables in the cluster. -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ------------------ | ----------- | ------------- | --------------------- | -| `database` | STRING | TAG | Database name | -| `table_name` | STRING | TAG | Table name | -| `ttl(ms)` | STRING | ATTRIBUTE | Data retention time | -| `status` | STRING | ATTRIBUTE | Status | -| `comment` | STRING | ATTRIBUTE | Description/comment | - -* Note: Possible values for `status`: `USING`, `PRE_CREATE`, `PRE_DELETE`. For details, refer to the [View Tables](../Basic-Concept/Table-Management.md#12-view-tables) in Table Management documentation -* The query results only display the collection of tables for which you have any permission. -* Query Example: - -```sql -IoTDB> select * from information_schema.tables -+------------------+--------------+-----------+------+-------+-----------+ -| database| table_name| ttl(ms)|status|comment| table_type| -+------------------+--------------+-----------+------+-------+-----------+ -|information_schema| databases| INF| USING| null|SYSTEM VIEW| -|information_schema| models| INF| USING| null|SYSTEM VIEW| -|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| -|information_schema| regions| INF| USING| null|SYSTEM VIEW| -|information_schema| functions| INF| USING| null|SYSTEM VIEW| -|information_schema| keywords| INF| USING| null|SYSTEM VIEW| -|information_schema| columns| INF| USING| null|SYSTEM VIEW| -|information_schema| topics| INF| USING| null|SYSTEM VIEW| -|information_schema|configurations| INF| USING| null|SYSTEM VIEW| -|information_schema| queries| INF| USING| null|SYSTEM VIEW| -|information_schema| tables| INF| USING| null|SYSTEM VIEW| -|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| -|information_schema| nodes| INF| USING| null|SYSTEM VIEW| -|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| -|information_schema| pipes| INF| USING| null|SYSTEM VIEW| -|information_schema| views| INF| USING| null|SYSTEM VIEW| -|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| -| database1| table1|31536000000| USING| null| BASE TABLE| -+------------------+--------------+-----------+------+-------+-----------+ -``` - -### 2.3 REGIONS - -* Contains information about all regions in the cluster. -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ------------------------- | ----------- | ------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `region_id` | INT32 | TAG | Region ID | -| `datanode_id` | INT32 | TAG | DataNode ID | -| `type` | STRING | ATTRIBUTE | Type (`SchemaRegion`/`DataRegion`) | -| `status` | STRING | ATTRIBUTE | Status (`Running`,`Unknown`, etc.) | -| `database` | STRING | ATTRIBUTE | Database name | -| `series_slot_num` | INT32 | ATTRIBUTE | Number of series slots | -| `time_slot_num` | INT64 | ATTRIBUTE | Number of time slots | -| `rpc_address` | STRING | ATTRIBUTE | RPC address | -| `rpc_port` | INT32 | ATTRIBUTE | RPC port | -| `internal_address` | STRING | ATTRIBUTE | Internal communication address | -| `role` | STRING | ATTRIBUTE | Role (`Leader`/`Follower`) | -| `create_time` | TIMESTAMP | ATTRIBUTE | Creation time | -| `tsfile_size_bytes` | INT64 | ATTRIBUTE | - For​**DataRegion with statistics ​**​: Total file size of TsFiles.
- For**DataRegion without statistics**(Unknown):`-1`.
- For​**SchemaRegion**​:`null`. | - -* Only administrators are allowed to perform query operations. -* Query Example: - -```SQL -IoTDB> select * from information_schema.regions -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| -| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| -| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -``` - -### 2.4 QUERIES - -* Contains information about all currently executing queries in the cluster. Can also be queried using the `SHOW QUERIES` syntax. -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| -------------------- | ----------- | ------------- | ------------------------------------------------------------ | -| `query_id` | STRING | TAG | Query ID | -| `start_time` | TIMESTAMP | ATTRIBUTE | Query start timestamp (precision matches system precision) | -| `datanode_id` | INT32 | ATTRIBUTE | DataNode ID that initiated the query | -| `elapsed_time` | FLOAT | ATTRIBUTE | Query execution duration (in seconds) | -| `statement` | STRING | ATTRIBUTE | SQL statement of the query | -| `user` | STRING | ATTRIBUTE | User who initiated the query | - -* For regular users, the query results only display the queries executed by themselves; for administrators, all queries are displayed. -* Query Example: - -```SQL -IoTDB> select * from information_schema.queries -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -| query_id| start_time|datanode_id|elapsed_time| statement|user| -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -``` - -### 2.5 COLUMNS - -* Contains information about all columns in tables across the cluster -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ------------------- | ----------- | ------------- | -------------------- | -| `database` | STRING | TAG | Database name | -| `table_name` | STRING | TAG | Table name | -| `column_name` | STRING | TAG | Column name | -| `datatype` | STRING | ATTRIBUTE | Column data type | -| `category` | STRING | ATTRIBUTE | Column category | -| `status` | STRING | ATTRIBUTE | Column status | -| `comment` | STRING | ATTRIBUTE | Column description | - -Notes: -* Possible values for `status`: `USING`, `PRE_DELETE`. For details, refer to [Viewing Table Columns](../Basic-Concept/Table-Management.html#13-view-table-columns) in Table Management documentation. -* The query results only display the column information of tables for which you have any permission. - -* Query Example: - -```SQL -IoTDB> select * from information_schema.columns where database = 'database1' -+---------+----------+------------+---------+---------+------+-------+ -| database|table_name| column_name| datatype| category|status|comment| -+---------+----------+------------+---------+---------+------+-------+ -|database1| table1| time|TIMESTAMP| TIME| USING| null| -|database1| table1| region| STRING| TAG| USING| null| -|database1| table1| plant_id| STRING| TAG| USING| null| -|database1| table1| device_id| STRING| TAG| USING| null| -|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| -|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| -|database1| table1| temperature| FLOAT| FIELD| USING| null| -|database1| table1| humidity| FLOAT| FIELD| USING| null| -|database1| table1| status| BOOLEAN| FIELD| USING| null| -|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| -+---------+----------+------------+---------+---------+------+-------+ -``` - -### 2.6 PIPES - -* Contains information about all pipes in the cluster -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ----------------------------------- | ----------- | ------------- | ---------------------------------------------------------- | -| `id` | STRING | TAG | Pipe name | -| `creation_time` | TIMESTAMP | ATTRIBUTE | Creation time | -| `state` | STRING | ATTRIBUTE | Pipe status (`RUNNING`/`STOPPED`) | -| `pipe_source` | STRING | ATTRIBUTE | Source plugin parameters | -| `pipe_processor` | STRING | ATTRIBUTE | Processor plugin parameters | -| `pipe_sink` | STRING | ATTRIBUTE | Sink plugin parameters | -| `exception_message` | STRING | ATTRIBUTE | Exception message | -| `remaining_event_count` | INT64 | ATTRIBUTE | Remaining event count (`-1`if Unknown) | -| `estimated_remaining_seconds` | DOUBLE | ATTRIBUTE | Estimated remaining time in seconds (`-1`if Unknown) | - -* Only administrators are allowed to perform operations. -* Query Example: - -```SQL -select * from information_schema.pipes -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -``` - -### 2.7 PIPE\_PLUGINS - -* Contains information about all PIPE plugins in the cluster -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ------------------- | ----------- | ------------- | ----------------------------------------------------- | -| `plugin_name` | STRING | TAG | Plugin name | -| `plugin_type` | STRING | ATTRIBUTE | Plugin type (`Builtin`/`External`) | -| `class_name` | STRING | ATTRIBUTE | Plugin's main class name | -| `plugin_jar` | STRING | ATTRIBUTE | Plugin's JAR file name (`null`for builtin type) | - -* Query Example: - -```SQL -IoTDB> select * from information_schema.pipe_plugins -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -| plugin_name|plugin_type| class_name|plugin_jar| -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| -| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| -| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| -| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| -| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| -| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -``` - -### 2.8 SUBSCRIPTIONS - -* Contains information about all data subscriptions in the cluster -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| ---------------------------- | ----------- | ------------- | ------------------------- | -| `topic_name` | STRING | TAG | Subscription topic name | -| `consumer_group_name` | STRING | TAG | Consumer group name | -| `subscribed_consumers` | STRING | ATTRIBUTE | Subscribed consumers | - -* Only administrators are allowed to perform operations. -* Query Example: - -```SQL -IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' -+----------+-------------------+--------------------------------+ -|topic_name|consumer_group_name| subscribed_consumers| -+----------+-------------------+--------------------------------+ -| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| -+----------+-------------------+--------------------------------+ -``` - -### 2.9 TOPICS - -* Contains information about all data subscription topics in the cluster -* Table structure is as follows: - -| Column Name | Data Type | Column Type | Description | -| --------------------- | ----------- | ------------- | -------------------------------- | -| `topic_name` | STRING | TAG | Subscription topic name | -| `topic_configs` | STRING | ATTRIBUTE | Topic configuration parameters | - -* Only administrators are allowed to perform operations. -* Query Example: - -```SQL -IoTDB> select * from information_schema.topics -+----------+----------------------------------------------------------------+ -|topic_name| topic_configs| -+----------+----------------------------------------------------------------+ -| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| -+----------+----------------------------------------------------------------+ -``` - -### 2.10 VIEWS Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all table views in the database. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------------ | ----------- | ----------------- | --------------------------------- | -| database | STRING | TAG | Database name | -| table\_name | STRING | TAG | View name | -| view\_definition | STRING | ATTRIBUTE | SQL statement for view creation | - -* The query results only display the collection of views for which you have any permission. -* Query example: - -```SQL -IoTDB> select * from information_schema.views -+---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ -| database|table_name| view_definition| -+---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ -|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| -+---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ -``` - - -### 2.11 MODELS Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all models in the database. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------- | ----------- | ----------------- | ------------------------------------------------------------------------------------------------ | -| model\_id | STRING | TAG | Model name | -| model\_type | STRING | ATTRIBUTE | Model type (Forecast, Anomaly Detection, Custom) | -| state | STRING | ATTRIBUTE | Model status (Available/Unavailable) | -| configs | STRING | ATTRIBUTE | String format of model hyperparameters, consistent with the output of the `show` command | -| notes | STRING | ATTRIBUTE | Model description\* Built-in model: Built-in model in IoTDB\* User-defined model: Custom model | - -* Query example: - -```SQL --- Find all built-in forecast models -IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' -+---------------------+-----------------+------+-------+-----------------------+ -| model_id| model_type| state|configs| notes| -+---------------------+-----------------+------+-------+-----------------------+ -| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -+---------------------+-----------------+------+-------+-----------------------+ -``` - - -### 2.12 FUNCTIONS Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all functions in the database. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------------ | ----------- | ----------------- | -------------------------------------------------------------------------- | -| function\_name | STRING | TAG | Function name | -| function\_type | STRING | ATTRIBUTE | Function type (Built-in/User-defined, Scalar/Aggregation/Table Function) | -| class\_name(udf) | STRING | ATTRIBUTE | Class name if it is a UDF, otherwise null (tentative) | -| state | STRING | ATTRIBUTE | Availability status | - -* Query example: - -```SQL -IoTDB> select * from information_schema.functions where function_type='built-in table function' -+--------------+-----------------------+---------------+---------+ -|function_name | function_type|class_name(udf)| state| -+--------------+-----------------------+---------------+---------+ -| CUMULATE|built-in table function| null|AVAILABLE| -| SESSION|built-in table function| null|AVAILABLE| -| HOP|built-in table function| null|AVAILABLE| -| TUMBLE|built-in table function| null|AVAILABLE| -| FORECAST|built-in table function| null|AVAILABLE| -| VARIATION|built-in table function| null|AVAILABLE| -| CAPACITY|built-in table function| null|AVAILABLE| -+--------------+-----------------------+---------------+---------+ -``` - - -### 2.13 CONFIGURATIONS Table - -> This system table is available starting from version V2.0.5. - -* Contains all configuration properties of the database. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------- | ----------- | ----------------- | ------------------------------ | -| variable | STRING | TAG | Configuration property name | -| value | STRING | ATTRIBUTE | Configuration property value | - -* Only administrators are allowed to perform operations on this table. -* Query example: - -```SQL -IoTDB> select * from information_schema.configurations -+----------------------------------+-----------------------------------------------------------------+ -| variable| value| -+----------------------------------+-----------------------------------------------------------------+ -| ClusterName| defaultCluster| -| DataReplicationFactor| 1| -| SchemaReplicationFactor| 1| -| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| -|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| TimePartitionOrigin| 0| -| TimePartitionInterval| 604800000| -| ReadConsistencyLevel| strong| -| SchemaRegionPerDataNode| 1| -| DataRegionPerDataNode| 0| -| SeriesSlotNum| 1000| -| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| -| DiskSpaceWarningThreshold| 0.05| -| TimestampPrecision| ms| -+----------------------------------+-----------------------------------------------------------------+ -``` - - -### 2.14 KEYWORDS Table - -> This system table is available starting from version V2.0.5. - -* Contains all keywords in the database. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------- | ----------- | ----------------- | ------------------------------------------------- | -| word | STRING | TAG | Keyword | -| reserved | INT32 | ATTRIBUTE | Whether it is a reserved word (1 = Yes, 0 = No) | - -* Query example: - -```SQL -IoTDB> select * from information_schema.keywords limit 10 -+----------+--------+ -| word|reserved| -+----------+--------+ -| ABSENT| 0| -|ACTIVATION| 1| -| ACTIVATE| 1| -| ADD| 0| -| ADMIN| 0| -| AFTER| 0| -| AINODES| 1| -| ALL| 0| -| ALTER| 1| -| ANALYZE| 0| -+----------+--------+ -``` - - -### 2.15 NODES Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all nodes in the database cluster. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| -------------------------------------------- | ----------- | ----------------- | ---------------------- | -| node\_id | INT32 | TAG | Node ID | -| node\_type | STRING | ATTRIBUTE | Node type | -| status | STRING | ATTRIBUTE | Node status | -| internal\_address | STRING | ATTRIBUTE | Internal RPC address | -| internal\_port | INT32 | ATTRIBUTE | Internal port | -| version | STRING | ATTRIBUTE | Version number | -| build\_info | STRING | ATTRIBUTE | Commit ID | -| activate\_status (Enterprise Edition only) | STRING | ATTRIBUTE | Activation status | - -* Only administrators are allowed to perform operations on this table. -* Query example: - -```SQL -IoTDB> select * from information_schema.nodes -+-------+----------+-------+----------------+-------------+-------+----------+ -|node_id| node_type| status|internal_address|internal_port|version|build_info| -+-------+----------+-------+----------------+-------------+-------+----------+ -| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| -| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| -+-------+----------+-------+----------------+-------------+-------+----------+ -``` - - -### 2.16 CONFIG\_NODES Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all ConfigNodes in the cluster. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------------------- | ----------- | ----------------- | --------------------------- | -| node\_id | INT32 | TAG | Node ID | -| config\_consensus\_port | INT32 | ATTRIBUTE | ConfigNode consensus port | -| role | STRING | ATTRIBUTE | ConfigNode role | - -* Only administrators are allowed to perform operations on this table. -* Query example: - -```SQL -IoTDB> select * from information_schema.config_nodes -+-------+---------------------+------+ -|node_id|config_consensus_port| role| -+-------+---------------------+------+ -| 0| 10720|Leader| -+-------+---------------------+------+ -``` - - -### 2.17 DATA\_NODES Table - -> This system table is available starting from version V2.0.5. - -* Contains information about all DataNodes in the cluster. -* The table structure is as follows: - -| Column Name | Data Type | Column Category | Description | -| ------------------------- | ----------- | ----------------- | ----------------------------- | -| node\_id | INT32 | TAG | Node ID | -| data\_region\_num | INT32 | ATTRIBUTE | Number of DataRegions | -| schema\_region\_num | INT32 | ATTRIBUTE | Number of SchemaRegions | -| rpc\_address | STRING | ATTRIBUTE | RPC address | -| rpc\_port | INT32 | ATTRIBUTE | RPC port | -| mpp\_port | INT32 | ATTRIBUTE | MPP communication port | -| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion consensus port | -| schema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion consensus port | - -* Only administrators are allowed to perform operations on this table. -* Query example: - -```SQL -IoTDB> select * from information_schema.data_nodes -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -``` - -## 3. Permission Description - -* GRANT/REVOKE operations are not supported for the `information_schema` database or any of its tables. -* All users can view `information_schema` database details via the `SHOW DATABASES` statement. -* All users can list system tables via `SHOW TABLES FROM information_schema`. -* All users can inspect system table structures using the `DESC` statement. diff --git a/src/UserGuide/latest-Table/Reference/System-Tables_apache.md b/src/UserGuide/latest-Table/Reference/System-Tables_apache.md index 3d7c27e4a..2f914109d 100644 --- a/src/UserGuide/latest-Table/Reference/System-Tables_apache.md +++ b/src/UserGuide/latest-Table/Reference/System-Tables_apache.md @@ -109,7 +109,7 @@ IoTDB> select * from information_schema.databases | `status` | STRING | ATTRIBUTE | Status | | `comment` | STRING | ATTRIBUTE | Description/comment | -* Note: Possible values for `status`: `USING`, `PRE_CREATE`, `PRE_DELETE`. For details, refer to the [View Tables](../Basic-Concept/Table-Management.md#12-view-tables) in Table Management documentation +* Note: Possible values for `status`: `USING`, `PRE_CREATE`, `PRE_DELETE`. For details, refer to the [View Tables](../Basic-Concept/Table-Management_apache.md#12-view-tables) in Table Management documentation * The query results only display the collection of tables for which you have any permission. * Query Example: @@ -216,7 +216,7 @@ IoTDB> select * from information_schema.queries | `comment` | STRING | ATTRIBUTE | Column description | Notes: -* Possible values for `status`: `USING`, `PRE_DELETE`. For details, refer to [Viewing Table Columns](../Basic-Concept/Table-Management.html#13-view-table-columns) in Table Management documentation. +* Possible values for `status`: `USING`, `PRE_DELETE`. For details, refer to [Viewing Table Columns](../Basic-Concept/Table-Management_apache.html#13-view-table-columns) in Table Management documentation. * The query results only display the column information of tables for which you have any permission. * Query Example: diff --git a/src/UserGuide/latest-Table/Reference/System-Tables_timecho.md b/src/UserGuide/latest-Table/Reference/System-Tables_timecho.md index 3d7c27e4a..a680e0ebd 100644 --- a/src/UserGuide/latest-Table/Reference/System-Tables_timecho.md +++ b/src/UserGuide/latest-Table/Reference/System-Tables_timecho.md @@ -109,7 +109,7 @@ IoTDB> select * from information_schema.databases | `status` | STRING | ATTRIBUTE | Status | | `comment` | STRING | ATTRIBUTE | Description/comment | -* Note: Possible values for `status`: `USING`, `PRE_CREATE`, `PRE_DELETE`. For details, refer to the [View Tables](../Basic-Concept/Table-Management.md#12-view-tables) in Table Management documentation +* Note: Possible values for `status`: `USING`, `PRE_CREATE`, `PRE_DELETE`. For details, refer to the [View Tables](../Basic-Concept/Table-Management_timecho.md#12-view-tables) in Table Management documentation * The query results only display the collection of tables for which you have any permission. * Query Example: @@ -216,7 +216,7 @@ IoTDB> select * from information_schema.queries | `comment` | STRING | ATTRIBUTE | Column description | Notes: -* Possible values for `status`: `USING`, `PRE_DELETE`. For details, refer to [Viewing Table Columns](../Basic-Concept/Table-Management.html#13-view-table-columns) in Table Management documentation. +* Possible values for `status`: `USING`, `PRE_DELETE`. For details, refer to [Viewing Table Columns](../Basic-Concept/Table-Management_timecho.html#13-view-table-columns) in Table Management documentation. * The query results only display the column information of tables for which you have any permission. * Query Example: diff --git a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations.md b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations.md index c09789283..6821d5dda 100644 --- a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations.md +++ b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations.md @@ -1,3 +1,6 @@ +--- +redirectTo: SQL-Metadata-Operations_apache.html +--- - -# Metadata Operations - -## 1. Database Management - -### 1.1 Create Database - -**Syntax:** - -```SQL -CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? -``` - -[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-1-create-a-database) - -**Examples:** - -```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - --- Create database with 1-year TTL -CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); -``` - -### 1.2 Use Database - -**Syntax:** - -```SQL -USE -``` - -**Examples:** - -```SQL -USE database1 -``` - -### 1.3 View Current Database - -**Syntax:** - -```SQL -SHOW CURRENT_DATABASE -``` - -**Examples:** - -```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE test; - -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| iot_database| -+---------------+ -``` - -### 1.4 List All Databases - -**Syntax:** - -```SQL -SHOW DATABASES (DETAILS)? -``` - -[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-4-view-all-databases) - -**Examples:** - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 3| 2| 100000| -| test2| 300| 3| 2| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -|test_prop| 300| 3| 2| 100000| 1| 2| -| test2| 300| 3| 2| 604800000| 1| 2| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -``` - -### 1.5 Modify Database - -**Syntax:** - -```SQL -ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments -``` - -**Examples:** - -```SQL -ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; -``` - -### 1.6 Drop Database - -**Syntax:** - -```SQL -DROP DATABASE (IF EXISTS)? -``` - -**Examples:** - -```SQL -DROP DATABASE IF EXISTS database1 -``` - -## 2. Table Management - -### 2.1 Create Table - -**Syntax:** - -```SQL -createTableStatement - : CREATE TABLE (IF NOT EXISTS)? qualifiedName - '(' (columnDefinition (',' columnDefinition)*)? ')' - charsetDesc? - comment? - (WITH properties)? - ; - -charsetDesc - : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString - ; - -columnDefinition - : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? - | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? - ; - -charsetName - : CHAR SET identifier - | CHARSET identifier - | CHARACTER SET identifier - ; - -comment - : COMMENT string - ; -``` - -[Detailed syntax reference](../Basic-Concept/Table-Management.md#_1-1-create-a-table) - -**Examples:** - -```SQL -CREATE TABLE table1 ( - time TIMESTAMP TIME, - region STRING TAG, - plant_id STRING TAG, - device_id STRING TAG, - model_id STRING ATTRIBUTE, - maintenance STRING ATTRIBUTE COMMENT 'maintenance', - temperature FLOAT FIELD COMMENT 'temperature', - humidity FLOAT FIELD COMMENT 'humidity', - status BOOLEAN FIELD COMMENT 'status', - arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' -) COMMENT 'table1' WITH (TTL=31536000000); - -CREATE TABLE IF NOT EXISTS table2 (); - -CREATE TABLE tableC ( - "plant" STRING TAG, - "temperature" INT32 FIELD COMMENT 'temperature' -) WITH (TTL=DEFAULT); -``` - -### 2.2 List Tables - -**Syntax:** - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -**Examples:** - -```SQL -IoTDB> show tables from test_db -+---------+-------+-------+ -|TableName|TTL(ms)|Comment| -+---------+-------+-------+ -| test| INF| TEST| -+---------+-------+-------+ - -IoTDB> show tables details from test_db -+---------+-------+----------+-------+ -|TableName|TTL(ms)| Status|Comment| -+---------+-------+----------+-------+ -| test| INF| USING| TEST| -| turbine| INF|PRE_CREATE| null| -| car| 1000|PRE_DELETE| null| -+---------+-------+----------+-------+ -``` - -### 2.3 Describe Table Columns - -**Syntax:** - -```SQL -(DESC | DESCRIBE) (DETAILS)? -``` - -**Examples:** - -```SQL -IoTDB> desc tableB -+----------+---------+-----------+-------+ -|ColumnName| DataType| Category|Comment| -+----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| a| STRING| TAG| a| -| b| STRING| ATTRIBUTE| b| -| c| INT32| FIELD| c| -+----------+---------+-----------+-------+ - -IoTDB> desc tableB details -+----------+---------+-----------+----------+-------+ -|ColumnName| DataType| Category| Status|Comment| -+----------+---------+-----------+----------+-------+ -| time|TIMESTAMP| TIME| USING| null| -| a| STRING| TAG| USING| a| -| b| STRING| ATTRIBUTE| USING| b| -| c| INT32| FIELD| USING| c| -| d| INT32| FIELD|PRE_DELETE| d| -+----------+---------+-----------+----------+-------+ -``` - -### 2.4 Modify Table - -**Syntax:** - -```SQL -ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn -// set TTL can use this -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties -| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' -| COMMENT ON COLUMN tableName.column IS 'column_comment' -``` - -**Examples:** - -```SQL -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' -ALTER TABLE tableB set properties TTL=3600 -COMMENT ON TABLE table1 IS 'table1' -COMMENT ON COLUMN table1.a IS null -``` - -### 2.5 Drop Table - -**Syntax:** - -```SQL -DROP TABLE (IF EXISTS)? -``` - -**Examples:** - -```SQL -DROP TABLE tableA -DROP TABLE test.tableB -``` - - diff --git a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md index c09789283..625e2ed75 100644 --- a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md +++ b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md @@ -31,7 +31,7 @@ CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? ``` -[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-1-create-a-database) +[Detailed syntax reference](../Basic-Concept/Database-Management_apache.md#_1-1-create-a-database) **Examples:** @@ -93,7 +93,7 @@ IoTDB> SHOW CURRENT_DATABASE; SHOW DATABASES (DETAILS)? ``` -[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-4-view-all-databases) +[Detailed syntax reference](../Basic-Concept/Database-Management_apache.md#_1-4-view-all-databases) **Examples:** @@ -177,7 +177,7 @@ comment ; ``` -[Detailed syntax reference](../Basic-Concept/Table-Management.md#_1-1-create-a-table) +[Detailed syntax reference](../Basic-Concept/Table-Management_apache.md#_1-1-create-a-table) **Examples:** diff --git a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md index c09789283..d3f8967d9 100644 --- a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md +++ b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md @@ -31,7 +31,7 @@ CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? ``` -[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-1-create-a-database) +[Detailed syntax reference](../Basic-Concept/Database-Management_timecho.md#_1-1-create-a-database) **Examples:** @@ -93,7 +93,7 @@ IoTDB> SHOW CURRENT_DATABASE; SHOW DATABASES (DETAILS)? ``` -[Detailed syntax reference](../Basic-Concept/Database-Management.md#_1-4-view-all-databases) +[Detailed syntax reference](../Basic-Concept/Database-Management_timecho.md#_1-4-view-all-databases) **Examples:** @@ -177,7 +177,7 @@ comment ; ``` -[Detailed syntax reference](../Basic-Concept/Table-Management.md#_1-1-create-a-table) +[Detailed syntax reference](../Basic-Concept/Table-Management_timecho.md#_1-1-create-a-table) **Examples:** diff --git a/src/UserGuide/latest-Table/User-Manual/Maintenance-commands.md b/src/UserGuide/latest-Table/User-Manual/Maintenance-commands.md index f77af49ce..30e0f15bc 100644 --- a/src/UserGuide/latest-Table/User-Manual/Maintenance-commands.md +++ b/src/UserGuide/latest-Table/User-Manual/Maintenance-commands.md @@ -1,3 +1,6 @@ +--- +redirectTo: Maintenance-statement_apache.html +--- -# Maintenance Statement - -## 1. Status Checking - -### 1.1 Viewing the Connected Model - -**Description**: Returns the current SQL dialect model (`Tree` or `Table`). - -**Syntax**: - -```SQL -showCurrentSqlDialectStatement - : SHOW CURRENT_SQL_DIALECT - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW CURRENT_SQL_DIALECT; -``` - -**Result:** - -```SQL -+-----------------+ -|CurrentSqlDialect| -+-----------------+ -| TABLE| -+-----------------+ -``` - -### 1.2 Viewing the Logged-in Username - -**Description**: Returns the currently logged-in username. - -**Syntax**: - -```SQL -showCurrentUserStatement - : SHOW CURRENT_USER - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW CURRENT_USER; -``` - -**Result**: - -```Plain -+-----------+ -|CurrentUser| -+-----------+ -| root| -+-----------+ -``` - -### 1.3 Viewing the Connected Database Name - -**Description**: Returns the name of the currently connected database. If no `USE` statement has been executed, it returns `null`. - -**Syntax**: - -```SQL -showCurrentDatabaseStatement - : SHOW CURRENT_DATABASE - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW CURRENT_DATABASE; -IoTDB> USE test; -IoTDB> SHOW CURRENT_DATABASE; -``` - -**Result**: - -```Plain -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ -+---------------+ -|CurrentDatabase| -+---------------+ -| test| -+---------------+ -``` - -### 1.4 Viewing the Cluster Version - -**Description**: Returns the current cluster version. - -**Syntax**: - -```SQL -showVersionStatement - : SHOW VERSION - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW VERSION; -``` - -**Result**: - -```Plain -+-------+---------+ -|Version|BuildInfo| -+-------+---------+ -|2.0.1.2| 1ca4008| -+-------+---------+ -``` - -### 1.5 Viewing Cluster Key Parameters - -**Description**: Returns key parameters of the current cluster. - -**Syntax**: - -```SQL -showVariablesStatement - : SHOW VARIABLES - ; -``` - -Key Parameters: - -1. **ClusterName**: The name of the current cluster. -2. **DataReplicationFactor**: Number of data replicas per DataRegion. -3. **SchemaReplicationFactor**: Number of schema replicas per SchemaRegion. -4. **DataRegionConsensusProtocolClass**: Consensus protocol class for DataRegions. -5. **SchemaRegionConsensusProtocolClass**: Consensus protocol class for SchemaRegions. -6. **ConfigNodeConsensusProtocolClass**: Consensus protocol class for ConfigNodes. -7. **TimePartitionOrigin**: The starting timestamp of database time partitions. -8. **TimePartitionInterval**: The interval of database time partitions (in milliseconds). -9. **ReadConsistencyLevel**: The consistency level for read operations. -10. **SchemaRegionPerDataNode**: Number of SchemaRegions per DataNode. -11. **DataRegionPerDataNode**: Number of DataRegions per DataNode. -12. **SeriesSlotNum**: Number of SeriesSlots per DataRegion. -13. **SeriesSlotExecutorClass**: Implementation class for SeriesSlots. -14. **DiskSpaceWarningThreshold**: Disk space warning threshold (in percentage). -15. **TimestampPrecision**: Timestamp precision. - -**Example**: - -```SQL -IoTDB> SHOW VARIABLES; -``` - -**Result**: - -```Plain -+----------------------------------+-----------------------------------------------------------------+ -| Variable| Value| -+----------------------------------+-----------------------------------------------------------------+ -| ClusterName| defaultCluster| -| DataReplicationFactor| 1| -| SchemaReplicationFactor| 1| -| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| -|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| TimePartitionOrigin| 0| -| TimePartitionInterval| 604800000| -| ReadConsistencyLevel| strong| -| SchemaRegionPerDataNode| 1| -| DataRegionPerDataNode| 0| -| SeriesSlotNum| 1000| -| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| -| DiskSpaceWarningThreshold| 0.05| -| TimestampPrecision| ms| -+----------------------------------+-----------------------------------------------------------------+ -``` - -### 1.6 Viewing the Cluster ID - -**Description**: Returns the ID of the current cluster. - -**Syntax**: - -```SQL -showClusterIdStatement - : SHOW (CLUSTERID | CLUSTER_ID) - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW CLUSTER_ID; -``` - -**Result**: - -```Plain -+------------------------------------+ -| ClusterId| -+------------------------------------+ -|40163007-9ec1-4455-aa36-8055d740fcda| -+------------------------------------+ -``` - -### 1.7 Viewing the Timestamp of the Connected DataNode - -**Description**: Returns the current timestamp of the DataNode process directly connected to the client. - -**Syntax**: - -```SQL -showCurrentTimestampStatement - : SHOW CURRENT_TIMESTAMP - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW CURRENT_TIMESTAMP; -``` - -**Result**: - -```Plain -+-----------------------------+ -| CurrentTimestamp| -+-----------------------------+ -|2025-02-17T11:11:52.987+08:00| -+-----------------------------+ -``` - -### 1.8 Viewing Executing Queries - -**Description**: Displays information about all currently executing queries. - -> For more details on how to use system tables, please refer to [System Tables](../Reference/System-Tables.md) - -**Syntax**: - -```SQL -showQueriesStatement - : SHOW (QUERIES | QUERY PROCESSLIST) - (WHERE where=booleanExpression)? - (ORDER BY sortItem (',' sortItem)*)? - limitOffsetClause - ; -``` - -**Parameters**: - -1. **WHERE Clause**: Filters the result set based on specified conditions. -2. **ORDER BY Clause**: Sorts the result set based on specified columns. -3. **limitOffsetClause**: Limits the number of rows returned. - 1. Format: `LIMIT , `. - -**Columns in QUERIES Table**: - -- **query_id**: Unique ID of the query. -- **start_time**: Timestamp when the query started. -- **datanode_id**: ID of the DataNode executing the query. -- **elapsed_time**: Time elapsed since the query started (in seconds). -- **statement**: The SQL statement being executed. -- **user**: The user who initiated the query. - -**Example**: - -```SQL -IoTDB> SHOW QUERIES WHERE elapsed_time > 30; -``` - -**Result**: - -```Plain -+-----------------------+-----------------------------+-----------+------------+------------+----+ -| query_id| start_time|datanode_id|elapsed_time| statement|user| -+-----------------------+-----------------------------+-----------+------------+------------+----+ -|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| -+-----------------------+-----------------------------+-----------+------------+------------+----+ -``` - - -### 1.9 Viewing Region Information - -**Description**: Displays regions' information of the current cluster. - -**Syntax**: - -```SQL -showRegionsStatement - : SHOW REGIONS - ; -``` - -**Example**: - -```SQL -IoTDB> SHOW REGIONS -``` - -**Result**: - -```SQL -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | -| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| -| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -``` - - -## 2. Status Setting - -### 2.1 Setting the Connected Model - -**Description**: Sets the current SQL dialect model to `Tree` or `Table` which can be used in both tree and table models. - -**Syntax**: - -```SQL -SET SQL_DIALECT = (TABLE | TREE); -``` - -**Example**: - -```SQL -IoTDB> SET SQL_DIALECT=TABLE; -IoTDB> SHOW CURRENT_SQL_DIALECT; -``` - -**Result**: - -```SQL -+-----------------+ -|CurrentSqlDialect| -+-----------------+ -| TABLE| -+-----------------+ -``` - -### 2.2 Updating Configuration Items - -**Description**: Updates configuration items. Changes take effect immediately without restarting if the items support hot modification. - -**Syntax**: - -```SQL -setConfigurationStatement - : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? - ; - -propertyAssignments - : property (',' property)* - ; - -property - : identifier EQ propertyValue - ; - -propertyValue - : DEFAULT - | expression - ; -``` - -**Parameters**: - -1. **propertyAssignments**: A list of properties to update. - 1. Format: `property (',' property)*`. - 2. Values: - - `DEFAULT`: Resets the configuration to its default value. - - `expression`: A specific value (must be a string). -2. **ON INTEGER_VALUE** **(Optional):** Specifies the node ID to update. - 1. If not specified or set to a negative value, updates all ConfigNodes and DataNodes. - -**Example**: - -```SQL -IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; -``` - -### 2.3 Loading Manually Modified Configuration Files - -**Description**: Loads manually modified configuration files and hot-loads the changes. Configuration items that support hot modification take effect immediately. - -**Syntax**: - -```SQL -loadConfigurationStatement - : LOAD CONFIGURATION localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **localOrClusterMode** **(Optional):** - 1. Specifies the scope of configuration loading. - 2. Default: `CLUSTER`. - 3. Values: - - `LOCAL`: Loads configuration only on the DataNode directly connected to the client. - - `CLUSTER`: Loads configuration on all DataNodes in the cluster. - -**Example**: - -```SQL -IoTDB> LOAD CONFIGURATION ON LOCAL; -``` - -### 2.4 Setting the System Status - -**Description**: Sets the system status to either `READONLY` or `RUNNING`. - -**Syntax**: - -```SQL -setSystemStatusStatement - : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **RUNNING |** **READONLY**: - 1. **RUNNING**: Sets the system to running mode, allowing both read and write operations. - 2. **READONLY**: Sets the system to read-only mode, allowing only read operations and prohibiting writes. -2. **localOrClusterMode** **(Optional):** - 1. **LOCAL**: Applies the status change only to the DataNode directly connected to the client. - 2. **CLUSTER**: Applies the status change to all DataNodes in the cluster. - 3. **Default**: `ON CLUSTER`. - -**Example**: - -```SQL -IoTDB> SET SYSTEM TO READONLY ON CLUSTER; -``` - -## 3. Data Management - -### 3.1 Flushing Data from Memory to Disk - -**Description**: Flushes data from the memory table to disk. - -**Syntax**: - -```SQL -flushStatement - : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? - ; - -booleanValue - : TRUE | FALSE - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **identifier** **(Optional):** - 1. Specifies the name of the database to flush. - 2. If not specified, all databases are flushed. - 3. **Multiple Databases**: Multiple database names can be specified, separated by commas (e.g., `FLUSH test_db1, test_db2`). -2. **booleanValue** **(****Optional****)**: - 1. Specifies the type of data to flush. - 2. **TRUE**: Flushes only the sequential memory table. - 3. **FALSE**: Flushes only the unsequential MemTable. - 4. **Default**: Flushes both sequential and unsequential memory tables. -3. **localOrClusterMode** **(****Optional****)**: - 1. **ON LOCAL**: Flushes only the memory tables on the DataNode directly connected to the client. - 2. **ON CLUSTER**: Flushes memory tables on all DataNodes in the cluster. - 3. **Default:** `ON CLUSTER`. - -**Example**: - -```SQL -IoTDB> FLUSH test_db TRUE ON LOCAL; -``` - -### 3.2 Clearing Cache on DataNode - -**Description**: Clears a specific type of cache on DataNode. - -**Syntax**: - -```SQL -clearCacheStatement - : CLEAR clearCacheOptions? CACHE localOrClusterMode? - ; - -clearCacheOptions - : ATTRIBUTE - | QUERY - | ALL - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **clearCacheOptions(Optional)**: - 1. Specifies the type of cache to clear. - 2. **ATTRIBUTE**: Clears device attribute cache. - 3. **QUERY**: Clears query cache in the storage engine. - 4. **ALL**: Clears all caches, including device attribute cache, query cache, and schema cache in the tree model. - 5. **Default**: `QUERY`. -2. **localOrClusterMode(Optional)**: - 1. **ON LOCAL**: Clears cache only on the DataNode directly connected to the client. - 2. **ON CLUSTER**: Clears cache on all DataNodes in the cluster. - 3. **Default:** `ON CLUSTER`. - -**Example**: - -```SQL -IoTDB> CLEAR ALL CACHE ON LOCAL; -``` - -## 4. Data Repair - -### 4.1 Starting Background Scan and Repair of TsFiles - -**Description**: Starts a background task to scan and repair TsFiles, fixing issues such as timestamp disorder within data files. - -**Syntax**: - -```SQL -startRepairDataStatement - : START REPAIR DATA localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **localOrClusterMode(Optional)**: - 1. **ON LOCAL**: Executes the repair task only on the DataNode directly connected to the client. - 2. **ON CLUSTER**: Executes the repair task on all DataNodes in the cluster. - 3. **Default:** `ON CLUSTER`. - -**Example**: - -```SQL -IoTDB> START REPAIR DATA ON CLUSTER; -``` - -### 4.2 Pausing Background TsFile Repair Task - -**Description**: Pauses the background repair task. The paused task can be resumed by executing the `START REPAIR DATA` command again. - -**Syntax**: - -```SQL -stopRepairDataStatement - : STOP REPAIR DATA localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**Parameters**: - -1. **localOrClusterMode** **(Optional):** - 1. **ON LOCAL**: Executes the pause command only on the DataNode directly connected to the client. - 2. **ON CLUSTER**: Executes the pause command on all DataNodes in the cluster. - 3. **Default:** `ON CLUSTER`. - -**Example**: - -```SQL -IoTDB> STOP REPAIR DATA ON CLUSTER; -``` - -## 5. Query Termination - -### 5.1 Terminating Queries - -**Description**: Terminates one or more running queries. - -**Syntax**: - -```SQL -killQueryStatement - : KILL (QUERY queryId=string | ALL QUERIES) - ; -``` - -**Parameters**: - -1. **QUERY** **queryId:** Specifies the ID of the query to terminate. - -- To obtain the `queryId`, use the `SHOW QUERIES` command. - -2. **ALL QUERIES:** Terminates all currently running queries. - -**Example**: - -Terminate a specific query: - -```SQL -IoTDB> KILL QUERY 20250108_101015_00000_1; -``` - -Terminate all queries: - -```SQL -IoTDB> KILL ALL QUERIES; -``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_apache.md b/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_apache.md index f77af49ce..e2be89e66 100644 --- a/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_apache.md +++ b/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_apache.md @@ -261,7 +261,7 @@ IoTDB> SHOW CURRENT_TIMESTAMP; **Description**: Displays information about all currently executing queries. -> For more details on how to use system tables, please refer to [System Tables](../Reference/System-Tables.md) +> For more details on how to use system tables, please refer to [System Tables](../Reference/System-Tables_apache.md) **Syntax**: diff --git a/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_timecho.md b/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_timecho.md index f77af49ce..c4c4feec5 100644 --- a/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_timecho.md +++ b/src/UserGuide/latest-Table/User-Manual/Maintenance-commands_timecho.md @@ -261,7 +261,7 @@ IoTDB> SHOW CURRENT_TIMESTAMP; **Description**: Displays information about all currently executing queries. -> For more details on how to use system tables, please refer to [System Tables](../Reference/System-Tables.md) +> For more details on how to use system tables, please refer to [System Tables](../Reference/System-Tables_timecho.md) **Syntax**: diff --git a/src/UserGuide/latest-Table/User-Manual/Tree-to-Table.md b/src/UserGuide/latest-Table/User-Manual/Tree-to-Table.md index c05049f06..4b9eaa718 100644 --- a/src/UserGuide/latest-Table/User-Manual/Tree-to-Table.md +++ b/src/UserGuide/latest-Table/User-Manual/Tree-to-Table.md @@ -1,3 +1,6 @@ +--- +redirectTo: Tree-to-Table_apache.html +--- - -# Tree-to-Table Mapping - -## 1. Functional Overview - -IoTDB introduces a tree-to-table function, which enables the creation of table views from existing tree-model data. This allows querying via table views, achieving collaborative processing of both tree and table models for the same dataset: - -* During the data writing phase, the tree-model syntax is used, supporting flexible data ingestion and expansion. -* During the data analysis phase, the table-model syntax is adopted, allowing complex data analysis through standard SQL queries. - -![](/img/tree-to-table-en-1.png) - -> * This feature supports from version V2.0.5. -> * Table views are read-only, so data cannot be written through them. - - ## 2. Feature Description -### 2.1 Creating a Table View -#### 2.1.1 Syntax Definition - -```SQL --- create (or replace) view on tree -CREATE - [OR REPLACE] - VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) - [comment] - [RESTRICT] - [WITH properties] - AS prefixPath - -viewColumnDefinition - : column_name [dataType] TAG [comment] # tagColumn - | column_name [dataType] TIME [comment] # timeColumn - | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn - ; - -comment - : COMMENT string - ; -``` - -> Note: Columns only support tags, fields, or time; attributes are not supported. - -#### 2.1.2 Syntax Explanation -1. **`prefixPath`** - -Corresponds to the path in the tree model. The last level of the path must be `**`, and no other levels can contain `*`or `**`. This path determines the subtree corresponding to the VIEW. - -2. **`view_name`** - -The name of the view, which follows the same rules as a table name (for specific constraints, refer to [Create Table](../Basic-Concept/Table-Management.md#\_1-1-create-a-table)), e.g., `db.view`. - -3. **`viewColumnDefinition`** - -* `TAG`: Each TAG column corresponds, in order, to the path nodes at the levels following the `prefixPath`. -* `FIELD`: A FIELD column corresponds to a measurement (leaf node) in the tree model. - * If a FIELD column is specified, the column name uses the declared `column_name`. - * If `original_measurement`is declared, it maps directly to that measurement in the tree model. Otherwise, the lowercase `column_name`is used as the measurement name for mapping. - * Mapping multiple FIELD columns to the same measurement name in the tree model is not supported. - * If the `dataType`for a FIELD column is not specified, the system defaults to the data type of the mapped measurement in the tree model. - * If a device in the tree model does not contain certain declared FIELD columns, or if their data types are inconsistent with the declared FIELD columns, the value for that FIELD column will always be `NULL`when querying that device. - * If no FIELD columns are specified, the system automatically scans for all measurements under the `prefixPath`subtree (including all ordinary sequence measurements and measurements defined in any templates whose mounted paths overlap with the `prefixPath`) during creation. The column names will use the measurement names from the tree model. - * The tree model cannot have measurements with the same name (case-insensitive) but different data types. - -4. **`WITH properties`** - -Currently, only TTL is supported. It indicates that data older than TTL (in milliseconds) will not be displayed in query results, i.e., effectively `WHERE time > now() - TTL`. If a TTL is also set in the tree model, the query uses the smaller value of the two. - -> Note: The table view's TTL does not affect the actual TTL of the devices in the tree model. When data reaches the TTL set in the tree model, it will be physically deleted by the system. - -5. **`OR REPLACE`** - -A table and a view cannot have the same name. If a table with the same name already exists during creation, an error will be reported. If a view with the same name already exists, it will be replaced. - -6. **`RESTRICT`** - -This constrains the number of levels of the tree model devices that are matched (starting from the level below the `prefixPath`). If the `RESTRICT`keyword is present, only devices whose level count exactly equals the number of TAG columns are matched. Otherwise, devices whose level count is less than or equal to the number of TAG columns are matched. The default behavior is non-RESTRICT, meaning devices with a level count less than or equal to the number of TAG columns are matched. - -#### 2.1.3 Usage Example -1. Tree Model and Table View Schema - -![](/img/tree-to-table-en-2.png) - -2. Creating the Table View - -* Creation Statement: - -```SQL -CREATE OR REPLACE VIEW viewdb."wind_turbine" - (wind_turbine_group String TAG, - wind_turbine_number String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -with (ttl=604800000) -AS root.db.** -``` - -* Detailed Explanation - -This statement creates a view named `viewdb.wind_turbine`(an error will occur if `viewdb`does not exist). If the view already exists, it will be replaced. - -* It creates a table view for the time series mounted under the tree model path `root.db.**`. -* It has two `TAG` columns, `wind_turbine_group `and `wind_turbine_number`, so the table view will only include devices from the 3rd level of the original tree model. -* It has two `FIELD`columns, `voltage` and `current`. Here, these `FIELD` columns correspond to measurement names in the tree model that are also `voltage` and `current`, and only select time series of type `DOUBLE`. - -**Renaming measurement requirement:** - -If the measurement name in the tree model is `current_new`, but you want the corresponding `FIELD` column name in the table view to be `current`, the SQL should be changed as follows: - -```SQL -CREATE OR REPLACE VIEW viewdb."wind_turbine" - (wind_turbine_group String TAG, - wind_turbine_number String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD FROM current_new - ) -with (ttl=604800000) -AS root.db.** -``` - -### 2.2 Modifying a Table View -#### 2.2.1 Syntax Definition - -The ALTER VIEW function supports modifying the view name, adding columns, renaming columns, deleting columns, setting the view's TTL property, and adding comments via COMMENT. - -```SQL --- Rename view -ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier - --- Add a column to the view -ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition -viewColumnDefinition - : column_name [dataType] TAG # tagColumn - | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn - --- Rename a column in the view -ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName - --- Delete a column from the view -ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName - --- Modify the view's TTL -ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments - --- Add comments -COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView -COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn -``` - -#### 2.2.2 Syntax Explanation -1. The `SET PROPERTIES`operation currently only supports configuring the TTL property for the table view. -2. The `DROP COLUMN`function only supports deleting FIELD columns; TAG columns cannot be deleted. -3. Modifying the comment will overwrite the original comment. If set to `null`, the previous comment will be erased. -#### 2.2.3 Usage Examples - -```SQL --- Rename view -ALTER VIEW IF EXISTS tableview1 RENAME TO tableview - --- Add a column to the view -ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field - --- Rename a column in the view -ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp - --- Delete a column from the view -ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp - --- Modify the view's TTL -ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 - --- Add comments -COMMENT ON VIEW tableview IS 'Tree to Table' -COMMENT ON COLUMN tableview.status is Null -``` - -### 2.3 Deleting a Table View -#### 2.3.1 Syntax Definition - -```SQL -DROP VIEW [IF EXISTS] viewName -``` - -#### 2.3.2 Usage Example - -```SQL -DROP VIEW IF EXISTS tableview -``` - -### 2.4 Viewing Table Views -#### 2.4.1 **`Show Tables`** -1. Syntax Definition - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -2. Syntax Explanation - -The `SHOW TABLES (DETAILS)`statement displays the type information of tables or views through the `TABLE_TYPE`field in the result set: - -| Type | `TABLE_TYPE`Field Value | -| -------------------------------------------- | ----------------------------- | -| Ordinary Table(Table) | `BASE TABLE` | -| Tree-to-Table View (Tree View) | `VIEW FROM TREE` | -| System Table(Iinformation\_schema.Tables) | `SYSTEM VIEW` | - -3. Usage Examples - -```SQL -IoTDB> show tables details from database1 -+-----------+-----------+------+---------------+--------------+ -| TableName| TTL(ms)|Status| Comment| TableType| -+-----------+-----------+------+---------------+--------------+ -| tableview| INF| USING| Tree to Table |VIEW FROM TREE| -| table1|31536000000| USING| null| BASE TABLE| -| table2|31536000000| USING| null| BASE TABLE| -+-----------+-----------+------+---------------+--------------+ - -IoTDB> show tables details from information_schema -+--------------+-------+------+-------+-----------+ -| TableName|TTL(ms)|Status|Comment| TableType| -+--------------+-------+------+-------+-----------+ -| columns| INF| USING| null|SYSTEM VIEW| -| config_nodes| INF| USING| null|SYSTEM VIEW| -|configurations| INF| USING| null|SYSTEM VIEW| -| data_nodes| INF| USING| null|SYSTEM VIEW| -| databases| INF| USING| null|SYSTEM VIEW| -| functions| INF| USING| null|SYSTEM VIEW| -| keywords| INF| USING| null|SYSTEM VIEW| -| models| INF| USING| null|SYSTEM VIEW| -| nodes| INF| USING| null|SYSTEM VIEW| -| pipe_plugins| INF| USING| null|SYSTEM VIEW| -| pipes| INF| USING| null|SYSTEM VIEW| -| queries| INF| USING| null|SYSTEM VIEW| -| regions| INF| USING| null|SYSTEM VIEW| -| subscriptions| INF| USING| null|SYSTEM VIEW| -| tables| INF| USING| null|SYSTEM VIEW| -| topics| INF| USING| null|SYSTEM VIEW| -| views| INF| USING| null|SYSTEM VIEW| -+--------------+-------+------+-------+-----------+ -``` - -#### 2.4.2 **`Show Create Table/View`** -1. Syntax Definition - -```SQL -SHOW CREATE TABLE|VIEW viewname; -``` - -2. Syntax Explanation - -* The `SHOW CREATE TABLE`statement can be used to display the complete creation information for ordinary tables or views. -* The `SHOW CREATE VIEW`statement can only be used to display the complete creation information for views. -* Neither statement can be used to display system tables. - -3. Usage Examples - -```SQL -IoTDB> show create table tableview -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| View| Create View| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ - -IoTDB> show create view tableview -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| View| Create View| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -``` - -### 2.5 Query Differences Between Non-aligned and Aligned Devices - -Queries on tree-to-table views may yield different results compared to equivalent tree model `ALIGN BY DEVICE`queries when dealing with null values in aligned and non-aligned devices. - -* Aligned Devices - * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. - * Table View Query Behavior:Consistent with the table model, rows where all selected fields are null are retained. -* Non-aligned Devices - * Tree Model Query Behavior:Rows where all selected time series have null values are not retained. - * Table View Query Behavior:Consistent with the tree model, rows where all selected fields are null are not retained. -* Explanation Example - * Aligned - - ```SQL - -- Write data in tree model (aligned) - CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) - INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) - INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) - - -- Create VIEW statement - CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** - - -- Query - IoTDB> select voltage from view1 - +-------+ - |voltage| - +-------+ - | 1| - | null| - +-------+ - Total line number = 2 - ``` - - * Non-aligned - - ```SQL - -- Write data in tree model (non-aligned) - CREATE TIMESERIES root.db.battery.b1.voltage INT32 - CREATE TIMESERIES root.db.battery.b1.current FLOAT - INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) - INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) - - -- Create VIEW statement - CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** - - -- Query - IoTDB> select voltage from view1 - +-------+ - |voltage| - +-------+ - | 1| - +-------+ - Total line number = 1 - - -- Can only ensure all rows are retrieved if the query specifies all FIELD columns, or only non-FIELD columns - IoTDB> select voltage,current from view1 - +-------+-------+ - |voltage|current| - +-------+-------+ - | 1| 1.0| - | null| 1.0| - +-------+-------+ - Total line number = 2 - - IoTDB> select battery_id from view1 - +-----------+ - |battery_id| - +-----------+ - | b1| - | b1| - +-----------+ - Total line number = 2 - - -- If the query involves only some FIELD columns, the final number of rows depends on the number of rows after aligning the specified FIELD columns by timestamp. - IoTDB> select time,voltage from view1 - +-----------------------------+-------+ - | time|voltage| - +-----------------------------+-------+ - |1970-01-01T08:00:00.001+08:00| 1| - +-----------------------------+-------+ - Total line number = 1 - ``` - -## 3. Scenario Examples -### 3.1 Managing Multiple Device Types in the Original Tree Model - -* The scenario involves managing different types of devices, each with its own hierarchical path and set of measurements. -* During Data Writing: Create branches under the database node according to device type. Each device type can have a different measurement structure. -* During Querying: Create a separate table for each device type. Each table will have different tags and sets of measurements. - -![](/img/tree-to-table-en-3.png) - -**SQL for Creating a Table View:** - -```SQL --- Wind Turbine Table -CREATE VIEW viewdb.wind_turbine - (wind_turbine_group String TAG, - wind_turbine_number String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -AS root.db.wind_turbine.** - --- Motor Table -CREATE VIEW viewdb.motor - ( motor_group String TAG, - motor_number String TAG, - power FLOAT FIELD, - electricity FLOAT FIELD, - temperature FLOAT FIELD - ) -AS root.db.motor.** -``` - -### 3.2 Original Tree Model Contains Only Measurements, No Devices - -This scenario occurs in systems like station monitoring where each measurement has a unique identifier but cannot be mapped to specific physical devices. - -> Wide Table Form - -![](/img/tree-to-table-en-4.png) - -**SQL for Creating a Table View:** - -```SQL -CREATE VIEW viewdb.machine - (DCS_PIT_02105A DOUBLE FIELD, - DCS_PIT_02105B DOUBLE FIELD, - DCS_PIT_02105C DOUBLE FIELD, - ... - DCS_XI_02716A DOUBLE FIELD - ) -AS root.db.** -``` - -### 3.3 Original Tree Model Where a Device Has Both Sub-devices and Measurements - -This scenario is common in energy storage systems where each hierarchical level requires monitoring of parameters like voltage and current. - -* Writing Phase: Model according to physical monitoring points at each hierarchical level -* Querying Phase: Create multiple tables based on device categories to manage information at each structural level - -![](/img/tree-to-table-en-5.png) - -**SQL for Creating a Table View:** - -```SQL --- Battery Compartment -CREATE VIEW viewdb.battery_compartment - (station String TAG, - batter_compartment String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -RESTRICT -AS root.db.** - --- Battery Stack -CREATE VIEW viewdb.battery_stack - (station String TAG, - batter_compartment String TAG, - battery_stack String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -RESTRICT -AS root.db.** - --- Battery Cluster -CREATE VIEW viewdb.battery_cluster - (station String TAG, - batter_compartment String TAG, - battery_stackString TAG, - battery_cluster String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -RESTRICT -AS 'root.db.**' - --- Battery Ceil -CREATE VIEW viewdb.battery_ceil - (station String TAG, - batter_compartment String TAG, - battery_cluster String TAG, - battery_cluster String TAG, - battery_ceil String TAG, - voltage DOUBLE FIELD, - current DOUBLE FIELD - ) -RESTRICT -AS root.db.** -``` - -### 3.4 Original Tree Model Where a Device Has Only One Measurement Under It - -> Narrow Table Form - -#### 3.4.1 All Measurements Have the Same Data Type - -![](/img/tree-to-table-en-6.png) - -**SQL for Creating a Table View:** - -```SQL -CREATE VIEW viewdb.machine - ( - sensor_id STRING TAG, - value DOUBLE FIELD - ) -AS root.db.** -``` - -#### 3.4.2 Measurements Have Different Data Types -##### 3.4.2.1 Create a Narrow Table View for Each Data Type of Measurement - -**Advantage: ​**The number of table views is constant, only related to the data types in the system. - -**Disadvantage: ​**When querying the value of a specific measurement, its data type must be known in advance to determine which table view to query. - -![](/img/tree-to-table-en-7.png) - -**SQL for Creating a Table View:** - -```SQL -CREATE VIEW viewdb.machine_float - ( - sensor_id STRING TAG, - value FLOAT FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_double - ( - sensor_id STRING TAG, - value DOUBLE FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_int32 - ( - sensor_id STRING TAG, - value INT32 FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_int64 - ( - sensor_id STRING TAG, - value INT64 FIELD - ) -AS root.db.** - -... -``` - -##### 3.4.2.2 Create a Table for Each Measurement - -**Advantage: ​**When querying the value of a specific measurement, there's no need to first check its data type to determine which table to query, making the process simple and convenient. - -**Disadvantage: ​**When there are a large number of measurements, it will introduce too many table views, requiring the writing of a large number of view creation statements. - -![](/img/tree-to-table-en-8.png) - -**SQL for Creating a Table View:** - -```SQL -CREATE VIEW viewdb.DCS_PIT_02105A - ( - value FLOAT FIELD - ) -AS root.db.DCS_PIT_02105A.** - -CREATE VIEW viewdb.DCS_PIT_02105B - ( - value DOUBLE FIELD - ) -AS root.db.DCS_PIT_02105B.** - -CREATE VIEW viewdb.DCS_XI_02716A - ( - value INT64 FIELD - ) -AS root.db.DCS_XI_02716A.** - -...... -``` diff --git a/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md b/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md index c05049f06..b9b1d06b9 100644 --- a/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md +++ b/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md @@ -67,7 +67,7 @@ Corresponds to the path in the tree model. The last level of the path must be `* 2. **`view_name`** -The name of the view, which follows the same rules as a table name (for specific constraints, refer to [Create Table](../Basic-Concept/Table-Management.md#\_1-1-create-a-table)), e.g., `db.view`. +The name of the view, which follows the same rules as a table name (for specific constraints, refer to [Create Table](../Basic-Concept/Table-Management_apache.md#\_1-1-create-a-table)), e.g., `db.view`. 3. **`viewColumnDefinition`** diff --git a/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md b/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md index c05049f06..d855bd5e3 100644 --- a/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md +++ b/src/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md @@ -67,7 +67,7 @@ Corresponds to the path in the tree model. The last level of the path must be `* 2. **`view_name`** -The name of the view, which follows the same rules as a table name (for specific constraints, refer to [Create Table](../Basic-Concept/Table-Management.md#\_1-1-create-a-table)), e.g., `db.view`. +The name of the view, which follows the same rules as a table name (for specific constraints, refer to [Create Table](../Basic-Concept/Table-Management_timecho.md#\_1-1-create-a-table)), e.g., `db.view`. 3. **`viewColumnDefinition`** diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management.md index 668d44e95..c2236d44a 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management.md @@ -1,3 +1,6 @@ +--- +redirectTo: Database-Management_apache.html +--- - -# 数据库管理 - -## 1. 数据库管理 - -### 1.1 创建数据库 - -用于创建数据库。 - -**语法:** - -```SQL - CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? -``` - -**说明:** - -1. 数据库名称,具有以下特性: - - 大小写不敏感,创建成功后,统一显示为小写 - - 名称的长度不得超过 64 个字符。 - - 名称中包含下划线(_)、数字(非开头)、英文字母可以直接创建 - - 名称中包含特殊字符(如`)、中文字符、数字开头时,必须用双引号 "" 括起来。 - -2. WITH properties 子句可配置如下属性: - -> 注:属性的大小写不敏感,有关详细信息[大小写敏感规则](../SQL-Manual/Identifier.md#大小写敏感性)。 - -| 属性 | 含义 | 默认值 | -| ------------------------- | ---------------------------------------- | --------- | -| `TTL` | 数据自动过期删除,单位 ms | INF | -| `TIME_PARTITION_INTERVAL` | 数据库的时间分区间隔,单位 ms | 604800000 | -| `SCHEMA_REGION_GROUP_NUM` | 数据库的元数据副本组数量,一般不需要修改 | 1 | -| `DATA_REGION_GROUP_NUM` | 数据库的数据副本组数量,一般不需要修改 | 2 | - -**示例:** - -```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 -CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); -``` - -### 1.2 使用数据库 - -用于指定当前数据库作为表的命名空间。 - -**语法:** - -```SQL -USE -``` - -**示例:** - -```SQL -USE database1 -``` - -### 1.3 查看当前数据库 - -返回当前会话所连接的数据库名称,若未执行过 `use`语句指定数据库,则默认为 `null`。 - -**语法:** - -```SQL -SHOW CURRENT_DATABASE -``` - -**示例:** - -```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE test; - -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| iot_database| -+---------------+ -``` - -### 1.4 查看所有数据库 - -用于查看所有数据库和数据库的属性信息。 - -**语法:** - -```SQL -SHOW DATABASES (DETAILS)? -``` - -**语句返回列含义如下:** - -| 列名 | 含义 | -| ----------------------- | ------------------------------------------------------------ | -| database | database名称。 | -| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management.md#14-修改表) 来设置或更新表的TTL时间。 | -| SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | -| DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | -| TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | -| SchemaRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的元数据副本组数量,一般不需要修改 | -| DataRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的数据副本组数量,一般不需要修改 | - -**示例:** - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 3| 2| 100000| -| test2| 300| 3| 2| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -|test_prop| 300| 3| 2| 100000| 1| 2| -| test2| 300| 3| 2| 604800000| 1| 2| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -``` - -### 1.5 修改数据库 - -用于修改数据库中的部分属性。 - -**语法:** - -```SQL -ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments -``` - -**说明:** - -1. `ALTER DATABASE`操作目前仅支持对数据库的`SCHEMA_REGION_GROUP_NUM`、`DATA_REGION_GROUP_NUM`以及`TTL`属性进行修改。 - -**示例:** - -```SQL -ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; -``` - -### 1.6 删除数据库 - -用于删除数据库。 - -**语法:** - -```SQL -DROP DATABASE (IF EXISTS)? -``` - -**说明:** - -1. 数据库已被设置为当前使用(use)的数据库,仍然可以被删除(drop)。 -2. 删除数据库将导致所选数据库及其内所有表连同其存储的数据一并被删除。 - -**示例:** - -```SQL -DROP DATABASE IF EXISTS database1 -``` diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data.md b/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data.md index 9c9f3178d..fde4f19e0 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data.md @@ -1,3 +1,6 @@ +--- +redirectTo: TTL-Delete-Data_apache.html +--- - -# 数据保留时间 - -## 1. 概览 - -IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系统自动定期删除旧数据,以有效控制磁盘空间并维护高性能查询和低内存占用。TTL默认以毫秒为单位,数据过期后不可查询且禁止写入,但物理删除会延迟至压缩时。需注意,TTL变更可能导致短暂数据可查询性变化。 - -**注意事项:** - -1. TTL设置为毫秒,不受配置文件时间精度影响。 -2. TTL变更可能影响数据的可查询性。 -3. 系统最终会移除过期数据,但存在延迟。 -4. TTL 判断数据是否过期依据的是数据点时间,非写入时间。 - -## 2. 设置 TTL - -在表模型中,IoTDB 的 TTL 是按照表的粒度生效的。可以直接在表上设置 TTL,或者在数据库级别设置 TTL。当在数据库级别设置了TTL时,在创建新表的过程中,系统会自动采用这个TTL值作为新表的默认设置,但每个表仍然可以独立地被设置或覆盖该值。 - -注意,如果数据库级别的TTL被修改,不会直接影响到已经存在的表的TTL设置。 - -### 2.1 为表设置 TTL - -如果在建表时通过sql语句设置了表的 TTL,则会以表的ttl为准。建表语句详情可见:[表管理](../Basic-Concept/Table-Management.md) - -示例1:创建表时设置 TTL - -```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600) -``` - -示例2:更改表语句设置TTL: - -```SQL -ALTER TABLE tableB SET PROPERTIES TTL=3600; -``` - -示例3:不指定TTL或设为默认值,它将与数据库的TTL相同,默认情况下是'INF'(无穷大): - -```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("场站" string id, "温度" int32) -ALTER TABLE tableB set properties TTL=DEFAULT -``` - -### 2.2 为数据库设置 TTL - -没有设置表的TTL,则会继承database的ttl。建数据库语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md) - -示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: - -```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) -``` - -示例5:数据库不设置ttl,将生成一个没有ttl的表: - -```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) -``` - -示例6:数据库设置了ttl,但想显式设置没有TTL的表,可以将TTL设置为'INF': - -```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') -``` - -## 3. 取消 TTL - -取消 TTL 设置,可以修改表的 TTL 设置为 'INF'。目前,IoTDB 不支持修改数据库的 TTL。 - -```SQL -ALTER TABLE tableB set properties TTL='INF' -``` - -## 4. 查看 TTL 信息 - -使用 "SHOW DATABASES" 和 "SHOW TABLES" 命令可以直接显示数据库和表的 TTL 详情。数据库和表管理语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md)、[表管理](../Basic-Concept/Table-Management.md) - -> 注意,树模型数据库的TTL也将显示。 - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 1| 3| 100000| -| test2| 300| 1| 1| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| -+---------+-------+-----------------------+---------------------+---------------------+-----+ -|test_prop| 300| 1| 3| 100000|TABLE| -| test2| 300| 1| 1| 604800000| TREE| -+---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables -+---------+-------+ -|TableName|TTL(ms)| -+---------+-------+ -| grass| 1000| -| bamboo| 300| -| flower| INF| -+---------+-------+ - -IoTDB> show tables details -+---------+-------+----------+ -|TableName|TTL(ms)| Status| -+---------+-------+----------+ -| bean| 300|PRE_CREATE| -| grass| 1000| USING| -| bamboo| 300| USING| -| flower| INF| USING| -+---------+-------+----------+ -``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management.md index 314991c13..cb319a68e 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management.md @@ -1,3 +1,6 @@ +--- +redirectTo: Table-Management_apache.html +--- - -# 表管理 - -在开始使用表管理功能前,推荐您先了解以下相关预备知识,以便更好地理解和应用表管理功能: -* [时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md):了解时序数据的基本概念与特点,帮助建立建模基础。 -* [建模方案设计](../Background-knowledge/Data-Model-and-Terminology_timecho.md):掌握 IoTDB 时序模型及适用场景,为表管理提供设计基础。 - -## 1. 表管理 - -### 1.1 创建表 - -#### 1.1.1 通过 Create 语句手动创建表 - -用于在当前数据库中创建表,也可以对任何指定数据库创建表,格式为“数据库名.表名”。 - -**语法:** - -```SQL -createTableStatement - : CREATE TABLE (IF NOT EXISTS)? qualifiedName - '(' (columnDefinition (',' columnDefinition)*)? ')' - charsetDesc? - comment? - (WITH properties)? - ; - -charsetDesc - : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString - ; - -columnDefinition - : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? - | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? - ; - -charsetName - : CHAR SET identifier - | CHARSET identifier - | CHARACTER SET identifier - ; - -comment - : COMMENT string - ; -``` - -**说明:** - -1. 在创建表时,可以不指定时间列(TIME),IoTDB会自动添加该列。其他所有列可以通过在数据库配置时启用`enable_auto_create_schema`选项,或通过 session 接口自动创建或修改表的语句来添加。 -2. 列的类别可以省略,默认为`FIELD`。当列的类别为`TAG`或`ATTRIBUTE`时,数据类型需为`STRING`(可省略)。 -3. 表的TTL默认为其所在数据库的TTL。如果使用默认值,可以省略此属性,或将其设置为`default`。 -4. 表名称,具有以下特性: - - 大小写不敏感,创建成功后,统一显示为小写 - - 名称可包含特殊字符,如 `~!`"%` 等 - - 包含特殊字符或中文字符的表名创建时必须用双引号 "" 括起来。 - - 注意:SQL中特殊字符或中文表名需加双引号。原生API中无需额外添加,否则表名会包含引号字符。 - - 当为表命名时,最外层的双引号(`""`)不会在实际创建的表名中出现。 - - - ```SQL - -- SQL 中 - "a""b" --> a"b - """""" --> "" - -- API 中 - "a""b" --> "a""b" - ``` -5. columnDefinition 列名称与表名称具有相同特性,并且可包含特殊字符`.`。 -6. COMMENT 给表添加注释。 - -**示例:** - -```SQL -CREATE TABLE table1 ( - time TIMESTAMP TIME, - region STRING TAG, - plant_id STRING TAG, - device_id STRING TAG, - model_id STRING ATTRIBUTE, - maintenance STRING ATTRIBUTE COMMENT 'maintenance', - temperature FLOAT FIELD COMMENT 'temperature', - humidity FLOAT FIELD COMMENT 'humidity', - status Boolean FIELD COMMENT 'status', - arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' -) COMMENT 'table1' WITH (TTL=31536000000); - -CREATE TABLE if not exists table2 (); - -CREATE TABLE tableC ( - "场站" STRING TAG, - "温度" int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); -``` - -#### 1.1.2 通过 Session 写入自动创建表 - -在通过 Session 进行数据写入时,IoTDB 能够根据写入请求中的信息自动构建表结构,无需用户事先手动创建表即可直接执行数据写入操作。 - -**示例:** - -```Java -try (ITableSession session = - new TableSessionBuilder() - .nodeUrls(Collections.singletonList("127.0.0.1:6667")) - .username("root") - .password("root") - .build()) { - - session.executeNonQueryStatement("CREATE DATABASE db1"); - session.executeNonQueryStatement("use db1"); - - // 不创建表直接写入数据 - List columnNameList = - Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); - List dataTypeList = - Arrays.asList( - TSDataType.STRING, - TSDataType.STRING, - TSDataType.STRING, - TSDataType.STRING, - TSDataType.FLOAT, - TSDataType.DOUBLE); - List columnTypeList = - new ArrayList<>( - Arrays.asList( - ColumnCategory.TAG, - ColumnCategory.TAG, - ColumnCategory.TAG, - ColumnCategory.ATTRIBUTE, - ColumnCategory.FIELD, - ColumnCategory.FIELD)); - Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); - for (long timestamp = 0; timestamp < 100; timestamp++) { - int rowIndex = tablet.getRowSize(); - tablet.addTimestamp(rowIndex, timestamp); - tablet.addValue("region_id", rowIndex, "1"); - tablet.addValue("plant_id", rowIndex, "5"); - tablet.addValue("device_id", rowIndex, "3"); - tablet.addValue("model", rowIndex, "A"); - tablet.addValue("temperature", rowIndex, 37.6F); - tablet.addValue("humidity", rowIndex, 111.1); - if (tablet.getRowSize() == tablet.getMaxRowNumber()) { - session.insert(tablet); - tablet.reset(); - } - } - if (tablet.getRowSize() != 0) { - session.insert(tablet); - tablet.reset(); - } -} -``` - -在代码执行完成后,可以通过下述语句确认表已成功创建,其中包含了时间列、标签列、属性列以及测点列等各类信息。 - -```SQL -IoTDB> desc table1 -+-----------+---------+-----------+-------+ -| ColumnName| DataType| Category|Comment| -+-----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| region_id| STRING| TAG| null| -| plant_id| STRING| TAG| null| -| device_id| STRING| TAG| null| -| model| STRING| ATTRIBUTE| null| -|temperature| FLOAT| FIELD| null| -| humidity| DOUBLE| FIELD| null| -+-----------+---------+-----------+-------+ -``` - -### 1.2 查看表 - -用于查看该数据库中或指定数据库中的所有表和表库的属性信息。 - -**语法:** - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -**说明:** - -1. 在查询中指定了`FROM`或`IN`子句时,系统将展示指定数据库内的所有表。 -2. 如果未指定`FROM`或`IN`子句,系统将展示当前选定数据库中的所有表。如果用户未使用(use)某个数据库空间,系统将报错。 -3. 请求显示详细信息(指定`DETAILS`),系统将展示表的当前状态,包括: - - `USING`:表示表处于正常可用状态。 - - `PRE_CREATE`:表示表正在创建中或创建失败,此时表不可用。 - - `PRE_DELETE`:表示表正在删除中或删除失败,此类表将永久不可用。 - -**示例:** - -```SQL -IoTDB> show tables from test_db -+---------+-------+-------+ -|TableName|TTL(ms)|Comment| -+---------+-------+-------+ -| test| INF| TEST| -+---------+-------+-------+ - -IoTDB> show tables details from test_db -+---------+-------+----------+-------+ -|TableName|TTL(ms)| Status|Comment| -+---------+-------+----------+-------+ -| test| INF| USING| TEST| -| turbine| INF|PRE_CREATE| null| -| car| 1000|PRE_DELETE| null| -+---------+-------+----------+-------+ -``` - -### 1.3 查看表的列 - -用于查看表的列名、数据类型、类别、状态。 - -**语法:** - -```SQL -(DESC | DESCRIBE) (DETAILS)? -``` - -**说明:** - -- 如果设置了`DETAILS`选项,系统将展示列的详细状态信息,包括: - - `USING`:表示列目前处于正常使用状态。 - - `PRE_DELETE`:表示列正在被删除或删除操作失败,该列将永久无法使用。 - -**示例:** - -```SQL -IoTDB> desc tableB -+----------+---------+-----------+-------+ -|ColumnName| DataType| Category|Comment| -+----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| a| STRING| TAG| a| -| b| STRING| ATTRIBUTE| b| -| c| INT32| FIELD| c| -+----------+---------+-----------+-------+ - -IoTDB> desc tableB details -+----------+---------+-----------+----------+-------+ -|ColumnName| DataType| Category| Status|Comment| -+----------+---------+-----------+----------+-------+ -| time|TIMESTAMP| TIME| USING| null| -| a| STRING| TAG| USING| a| -| b| STRING| ATTRIBUTE| USING| b| -| c| INT32| FIELD| USING| c| -| d| INT32| FIELD|PRE_DELETE| d| -+----------+---------+-----------+----------+-------+ -``` - -### 1.4 修改表 - -用于修改表,包括添加列、删除列以及设置表的属性。 - -**语法:** - -```SQL -ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn -// set TTL can use this -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties -| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' -| COMMENT ON COLUMN tableName.column IS 'column_comment' -``` - -**说明:** - -1. `SET PROPERTIES`操作目前仅支持对表的 TTL 属性进行配置。 -2. 删除列功能,仅支持删除属性列(ATTRIBUTE)和物理量列(FIELD),标识列(TAG)不支持删除。 -3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 - -**示例:** - -```SQL -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' -ALTER TABLE tableB set properties TTL=3600 -COMMENT ON TABLE table1 IS 'table1' -COMMENT ON COLUMN table1.a IS null -``` - -### 1.5 删除表 - -用于删除表。 - -**语法:** - -```SQL -DROP TABLE (IF EXISTS)? -``` - -**示例:** - -```SQL -DROP TABLE tableA -DROP TABLE test.tableB -``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/QuickStart/QuickStart_apache.md b/src/zh/UserGuide/Master/Table/QuickStart/QuickStart_apache.md index f8c960ed5..bc48bde3f 100644 --- a/src/zh/UserGuide/Master/Table/QuickStart/QuickStart_apache.md +++ b/src/zh/UserGuide/Master/Table/QuickStart/QuickStart_apache.md @@ -49,9 +49,9 @@ - 建模设计介绍:[建模方案设计](../Background-knowledge/Data-Model-and-Terminology_apache.md) - - 数据库介绍:[数据库管理](../Basic-Concept/Database-Management.md) + - 数据库介绍:[数据库管理](../Basic-Concept/Database-Management_apache.md) - - 表介绍:[表管理](../Basic-Concept/Table-Management.md) + - 表介绍:[表管理](../Basic-Concept/Table-Management_apache.md) 2. 数据写入&更新:在数据写入&更新方面,IoTDB 提供了多种方式来插入实时数据,支持追加查询写回,基本介绍请查看 [数据写入&更新](../Basic-Concept/Write-Updata-Data_apache.md) @@ -60,7 +60,7 @@ 4. 数据删除:IoTDB 提供了两种删除方式,分别为SQL语句删除与过期自动删除(TTL) - SQL语句删除:基本介绍请查看 [数据删除](../Basic-Concept/Delete-Data.md) - - 过期自动删除(TTL):基本介绍请查看 [过期自动删除](../Basic-Concept/TTL-Delete-Data.md) + - 过期自动删除(TTL):基本介绍请查看 [过期自动删除](../Basic-Concept/TTL-Delete-Data_apache.md) 5. 其他进阶功能:除了数据库常见的写入、查询等功能外,IoTDB 还支持“数据同步”等功能,具体使用方法可参见具体文档: diff --git a/src/zh/UserGuide/Master/Table/QuickStart/QuickStart_timecho.md b/src/zh/UserGuide/Master/Table/QuickStart/QuickStart_timecho.md index 9cf475b17..770782da7 100644 --- a/src/zh/UserGuide/Master/Table/QuickStart/QuickStart_timecho.md +++ b/src/zh/UserGuide/Master/Table/QuickStart/QuickStart_timecho.md @@ -56,9 +56,9 @@ - 建模设计介绍:[建模方案设计](../Background-knowledge/Data-Model-and-Terminology_timecho.md) - - 数据库介绍:[数据库管理](../Basic-Concept/Database-Management.md) + - 数据库介绍:[数据库管理](../Basic-Concept/Database-Management_timecho.md) - - 表介绍:[表管理](../Basic-Concept/Table-Management.md) + - 表介绍:[表管理](../Basic-Concept/Table-Management_timecho.md) 2. 数据写入&更新:在数据写入&更新方面,IoTDB 提供了多种方式来插入实时数据,支持追加查询写回,基本介绍请查看 [数据写入&更新](../Basic-Concept/Write-Updata-Data_timecho.md) @@ -67,7 +67,7 @@ 4. 数据删除:IoTDB 提供了两种删除方式,分别为SQL语句删除与过期自动删除(TTL) - SQL语句删除:基本介绍请查看 [数据删除](../Basic-Concept/Delete-Data.md) - - 过期自动删除(TTL):基本介绍请查看 [过期自动删除](../Basic-Concept/TTL-Delete-Data.md) + - 过期自动删除(TTL):基本介绍请查看 [过期自动删除](../Basic-Concept/TTL-Delete-Data_timecho.md) 5. 其他进阶功能:除了数据库常见的写入、查询等功能外,IoTDB 还支持“数据同步”等功能,具体使用方法可参见具体文档: diff --git a/src/zh/UserGuide/Master/Table/Reference/System-Tables.md b/src/zh/UserGuide/Master/Table/Reference/System-Tables.md index c15eba104..c8ac85f91 100644 --- a/src/zh/UserGuide/Master/Table/Reference/System-Tables.md +++ b/src/zh/UserGuide/Master/Table/Reference/System-Tables.md @@ -1,3 +1,6 @@ +--- +redirectTo: System-Tables_apache.html +--- - -# 系统表 - -IoTDB 内置系统数据库 `INFORMATION_SCHEMA`,其中包含一系列系统表,用于存储 IoTDB 运行时信息(如当前正在执行的 SQL 语句等)。目前`INFORMATION_SCHEMA`数据库只支持读操作。 - -## 1. 系统库 - -* 名称:`INFORMATION_SCHEMA` -* 指令:只读,只支持 `Show databases (DETAILS) `​`/ Show Tables (DETAILS) / Use`,其余操作将会报错:`"The database 'information_schema' can only be queried"` -* 属性:`TTL=INF`,其余属性默认为`null` -* SQL示例: - -```sql -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show tables from information_schema -+--------------+-------+ -| TableName|TTL(ms)| -+--------------+-------+ -| columns| INF| -| config_nodes| INF| -|configurations| INF| -| data_nodes| INF| -| databases| INF| -| functions| INF| -| keywords| INF| -| models| INF| -| nodes| INF| -| pipe_plugins| INF| -| pipes| INF| -| queries| INF| -| regions| INF| -| subscriptions| INF| -| tables| INF| -| topics| INF| -| views| INF| -+--------------+-------+ -``` - -## 2. 系统表 - -* 名称:`DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`,`VIEWS`,`MODELS`,`FUNCTIONS`,`CONFIGURATIONS`,`KEYWORDS`,`NODES`、`CONFIG_NODES`、`DATA_NODES`(详细介绍见后面小节) -* 操作:只读,只支持`SELECT`, `COUNT/SHOW DEVICES`, `DESC`,不支持对于表结构 / 内容的任意修改,如果修改将会报错:`"The database 'information_schema' can only be queried"` -* 列名:系统表的列名均默认为小写,且用`_`分隔 - -### 2.1 DATABASES 表 - -* 包含集群中所有数据库的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ----------------------------- | ---------- | ----------- | ---------------- | -| database | STRING | TAG | 数据库名称 | -| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | -| schema\_replication\_factor | INT32 | ATTRIBUTE | 元数据副本数 | -| data\_replication\_factor | INT32 | ATTRIBUTE | 数据副本数 | -| time\_partition\_interval | INT64 | ATTRIBUTE | 时间分区间隔 | -| schema\_region\_group\_num | INT32 | ATTRIBUTE | 元数据分区数量 | -| data\_region\_group\_num | INT32 | ATTRIBUTE | 数据分区数量 | - -* 查询结果只展示自身对该数据库本身或库中任意表有任意权限的数据库集合 -* 查询示例: - -```sql -IoTDB> select * from information_schema.databases -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -|information_schema| INF| null| null| null| null| null| -| database1| INF| 1| 1| 604800000| 0| 0| -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -``` - -### 2.2 TABLES 表 - -* 包含集群中所有表的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------- | ---------- | ----------- | -------------- | -| database | STRING | TAG | 数据库名称 | -| table\_name | STRING | TAG | 表名称 | -| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | -| status | STRING | ATTRIBUTE | 状态 | -| comment | STRING | ATTRIBUTE | 注释 | - -* 说明:status 可能为`USING`/`PRE_CREATE`/`PRE_DELETE`,具体见表管理中[查看表](../Basic-Concept/Table-Management.md#12-查看表)的相关描述 -* 查询结果只展示自身有任意权限的表集合 -* 查询示例: - -```sql -IoTDB> select * from information_schema.tables -+------------------+--------------+-----------+------+-------+-----------+ -| database| table_name| ttl(ms)|status|comment| table_type| -+------------------+--------------+-----------+------+-------+-----------+ -|information_schema| databases| INF| USING| null|SYSTEM VIEW| -|information_schema| models| INF| USING| null|SYSTEM VIEW| -|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| -|information_schema| regions| INF| USING| null|SYSTEM VIEW| -|information_schema| functions| INF| USING| null|SYSTEM VIEW| -|information_schema| keywords| INF| USING| null|SYSTEM VIEW| -|information_schema| columns| INF| USING| null|SYSTEM VIEW| -|information_schema| topics| INF| USING| null|SYSTEM VIEW| -|information_schema|configurations| INF| USING| null|SYSTEM VIEW| -|information_schema| queries| INF| USING| null|SYSTEM VIEW| -|information_schema| tables| INF| USING| null|SYSTEM VIEW| -|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| -|information_schema| nodes| INF| USING| null|SYSTEM VIEW| -|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| -|information_schema| pipes| INF| USING| null|SYSTEM VIEW| -|information_schema| views| INF| USING| null|SYSTEM VIEW| -|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| -| database1| table1|31536000000| USING| null| BASE TABLE| -+------------------+--------------+-----------+------+-------+-----------+ -``` - -### 2.3 REGIONS 表 - -* 包含集群中所有`Region`的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| --------------------- | ----------- | ----------- | ----------------------------------------------------------------------------------------------------------- | -| region\_id | INT32 | TAG | region ID | -| datanode\_id | INT32 | TAG | dataNode ID | -| type | STRING | ATTRIBUTE | 类型(SchemaRegion / DataRegion) | -| status | STRING | ATTRIBUTE | 状态(Running/Unknown 等) | -| database | STRING | ATTRIBUTE | database 名字 | -| series\_slot\_num | INT32 | ATTRIBUTE | series slot 个数 | -| time\_slot\_num | INT64 | ATTRIBUTE | time slot 个数 | -| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | -| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | -| internal\_address | STRING | ATTRIBUTE | 内部通讯地址 | -| role | STRING | ATTRIBUTE | Leader / Follower | -| create\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | -| tsfile\_size\_bytes | INT64 | ATTRIBUTE | 可统计的 DataRegion:含有 TsFile 的总文件大小;不可统计的 DataRegion(Unknown):-1;SchemaRegion:null; | - -* 仅管理员可执行查询操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.regions -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| -| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| -| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -``` - -### 2.4 QUERIES 表 - -* 包含集群中所有正在执行的查询的信息。也可以使用 `SHOW QUERIES`语法去查询。 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| --------------- | ----------- | ----------- | ------------------------------------------------ | -| query\_id | STRING | TAG | ID | -| start\_time | TIMESTAMP | ATTRIBUTE | 查询开始的时间戳,时间戳精度与系统精度保持一致 | -| datanode\_id | INT32 | ATTRIBUTE | 发起查询的DataNode ID | -| elapsed\_time | FLOAT | ATTRIBUTE | 查询执行耗时,单位是秒 | -| statement | STRING | ATTRIBUTE | 查询sql | -| user | STRING | ATTRIBUTE | 发起查询的用户 | - -* 普通用户查询结果仅显示自身执行的查询;管理员显示全部。 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.queries -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -| query_id| start_time|datanode_id|elapsed_time| statement|user| -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -``` - -### 2.5 COLUMNS 表 - -* 包含集群中所有表中列的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| -------------- | ---------- | ----------- | -------------- | -| database | STRING | TAG | 数据库名称 | -| table\_name | STRING | TAG | 表名称 | -| column\_name | STRING | TAG | 列名称 | -| datatype | STRING | ATTRIBUTE | 列的数值类型 | -| category | STRING | ATTRIBUTE | 列类型 | -| status | STRING | ATTRIBUTE | 列状态 | -| comment | STRING | ATTRIBUTE | 列注释 | - -说明: -* status 可能为`USING`/`PRE_DELETE`,具体见表管理中[查看表的列](../Basic-Concept/Table-Management.html#13-查看表的列)的相关描述 -* 查询结果只展示自身有任意权限的表的列信息 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.columns where database = 'database1' -+---------+----------+------------+---------+---------+------+-------+ -| database|table_name| column_name| datatype| category|status|comment| -+---------+----------+------------+---------+---------+------+-------+ -|database1| table1| time|TIMESTAMP| TIME| USING| null| -|database1| table1| region| STRING| TAG| USING| null| -|database1| table1| plant_id| STRING| TAG| USING| null| -|database1| table1| device_id| STRING| TAG| USING| null| -|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| -|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| -|database1| table1| temperature| FLOAT| FIELD| USING| null| -|database1| table1| humidity| FLOAT| FIELD| USING| null| -|database1| table1| status| BOOLEAN| FIELD| USING| null| -|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| -+---------+----------+------------+---------+---------+------+-------+ -``` - -### 2.6 PIPES 表 - -* 包含集群中所有 PIPE 的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------------------- | ----------- | ----------- | --------------------------------------- | -| id | STRING | TAG | Pipe 名称 | -| creation\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | -| state | STRING | ATTRIBUTE | Pipe 状态(RUNNING/STOPPED) | -| pipe\_source | STRING | ATTRIBUTE | source 插件参数 | -| pipe\_processor | STRING | ATTRIBUTE | processor 插件参数 | -| pipe\_sink | STRING | ATTRIBUTE | source 插件参数 | -| exception\_message | STRING | ATTRIBUTE | Exception 信息 | -| remaining\_event\_count | INT64 | ATTRIBUTE | 剩余 event 数量,如果 Unknown 则为 -1 | -| estimated\_remaining\_seconds | DOUBLE | ATTRIBUTE | 预估剩余时间,如果 Unknown 则为 -1 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -select * from information_schema.pipes -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -``` - -### 2.7 PIPE\_PLUGINS 表 - -* 包含集群中所有PIPE插件的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| -------------- | ---------- | ----------- | ----------------------------------------------- | -| plugin\_name | STRING | TAG | 插件名称 | -| plugin\_type | STRING | ATTRIBUTE | 插件类型(Builtin/External) | -| class\_name | STRING | ATTRIBUTE | 插件的主类名 | -| plugin\_jar | STRING | ATTRIBUTE | 插件的 jar 包名称,若为 builtin 类型则为 null | - -* 查询示例: - -```SQL -IoTDB> select * from information_schema.pipe_plugins -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -| plugin_name|plugin_type| class_name|plugin_jar| -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| -| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| -| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| -| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| -| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| -| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -``` - -### 2.8 SUBSCRIPTIONS 表 - -* 包含集群中所有数据订阅的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ----------------------- | ---------- | ----------- | -------------- | -| topic\_name | STRING | TAG | 订阅主题名称 | -| consumer\_group\_name | STRING | TAG | 消费者组名称 | -| subscribed\_consumers | STRING | ATTRIBUTE | 订阅的消费者 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' -+----------+-------------------+--------------------------------+ -|topic_name|consumer_group_name| subscribed_consumers| -+----------+-------------------+--------------------------------+ -| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| -+----------+-------------------+--------------------------------+ -``` - -### 2.9 TOPICS 表 - -* 包含集群中所有数据订阅主题的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ---------------- | ---------- | ----------- | -------------- | -| topic\_name | STRING | TAG | 订阅主题名称 | -| topic\_configs | STRING | ATTRIBUTE | 订阅主题配置 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.topics -+----------+----------------------------------------------------------------+ -|topic_name| topic_configs| -+----------+----------------------------------------------------------------+ -| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| -+----------+----------------------------------------------------------------+ -``` - -### 2.10 VIEWS 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的表视图信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------ | ---------- | ----------- | ---------------- | -| database | STRING | TAG | 数据库名称 | -| table\_name | STRING | TAG | 视图名称 | -| view\_definition | STRING | ATTRIBUTE | 视图的创建语句 | - -* 查询结果只展示自身有任意权限的视图集合 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.views -+---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ -| database|table_name| view_definition| -+---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ -|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| -+---------+----------+--------------------------------------------------------------------------------------------------------------------------------------- -``` - -### 2.11 MODELS 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的模型信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------- | ---------- | ----------- | ----------------------------------------------------------------------- | -| model\_id | STRING | TAG | 模型名称 | -| model\_type | STRING | ATTRIBUTE | 模型类型(预测,异常检测,自定义) | -| state | STRING | ATTRIBUTE | 模型状态(是否可用) | -| configs | STRING | ATTRIBUTE | 模型的超参数的 string 格式,与正常的 show 相同 | -| notes | STRING | ATTRIBUTE | 模型注释* 内置 model:Built-in model in IoTDB* 用户的 model:自定义 | - -* 查询示例: - -```SQL --- 找到类型为内置预测的所有模型 -IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' -+---------------------+-----------------+------+-------+-----------------------+ -| model_id| model_type| state|configs| notes| -+---------------------+-----------------+------+-------+-----------------------+ -| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -+---------------------+-----------------+------+-------+-----------------------+ -``` - -### 2.12 FUNCTIONS 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的函数信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------ | ---------- | ----------- | ----------------------------------------- | -| function\_name | STRING | TAG | 函数名称 | -| function\_type | STRING | ATTRIBUTE | 函数类型(内/外置数值/聚合/表函数) | -| class\_name(udf) | STRING | ATTRIBUTE | 如为 UDF,则为类名,否则为 null(暂定) | -| state | STRING | ATTRIBUTE | 是否可用 | - -* 查询示例: - -```SQL -IoTDB> select * from information_schema.functions where function_type='built-in table function' -+--------------+-----------------------+---------------+---------+ -|function_table| function_type|class_name(udf)| state| -+--------------+-----------------------+---------------+---------+ -| CUMULATE|built-in table function| null|AVAILABLE| -| SESSION|built-in table function| null|AVAILABLE| -| HOP|built-in table function| null|AVAILABLE| -| TUMBLE|built-in table function| null|AVAILABLE| -| FORECAST|built-in table function| null|AVAILABLE| -| VARIATION|built-in table function| null|AVAILABLE| -| CAPACITY|built-in table function| null|AVAILABLE| -+--------------+-----------------------+---------------+---------+ -``` - -### 2.13 CONFIGURATIONS表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的属性信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ---------- | ---------- | ----------- | -------- | -| variable | STRING | TAG | 属性名 | -| value | STRING | ATTRIBUTE | 属性值 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.configurations -+----------------------------------+-----------------------------------------------------------------+ -| variable| value| -+----------------------------------+-----------------------------------------------------------------+ -| ClusterName| defaultCluster| -| DataReplicationFactor| 1| -| SchemaReplicationFactor| 1| -| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| -|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| TimePartitionOrigin| 0| -| TimePartitionInterval| 604800000| -| ReadConsistencyLevel| strong| -| SchemaRegionPerDataNode| 1| -| DataRegionPerDataNode| 0| -| SeriesSlotNum| 1000| -| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| -| DiskSpaceWarningThreshold| 0.05| -| TimestampPrecision| ms| -+----------------------------------+-----------------------------------------------------------------+ -``` - -### 2.14 KEYWORDS 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的关键字信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ---------- | ---------- | ----------- | -------------------------------- | -| word | STRING | TAG | 关键字 | -| reserved | INT32 | ATTRIBUTE | 是否为保留字,1表示是,0表示否 | - -* 查询示例: - -```SQL -IoTDB> select * from information_schema.keywords limit 10 -+----------+--------+ -| word|reserved| -+----------+--------+ -| ABSENT| 0| -|ACTIVATION| 1| -| ACTIVATE| 1| -| ADD| 0| -| ADMIN| 0| -| AFTER| 0| -| AINODES| 1| -| ALL| 0| -| ALTER| 1| -| ANALYZE| 0| -+----------+--------+ -``` - -### 2.15 NODES 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的节点信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------------------ | ---------- | ----------- | --------------- | -| node\_id | INT32 | TAG | 节点 ID | -| node\_type | STRING | ATTRIBUTE | 节点类型 | -| status | STRING | ATTRIBUTE | 节点状态 | -| internal\_address | STRING | ATTRIBUTE | 内部 rpc 地址 | -| internal\_port | INT32 | ATTRIBUTE | 内部端口 | -| version | STRING | ATTRIBUTE | 版本号 | -| build\_info | STRING | ATTRIBUTE | CommitID | -| activate\_status(仅企业版) | STRING | ATTRIBUTE | 激活状态 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.nodes -+-------+----------+-------+----------------+-------------+-------+----------+ -|node_id| node_type| status|internal_address|internal_port|version|build_info| -+-------+----------+-------+----------------+-------------+-------+----------+ -| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| -| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| -+-------+----------+-------+----------------+-------------+-------+----------+ -+----------+--------+ -``` - -### 2.16 CONFIG\_NODES 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的配置节点信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------------- | ---------- | ----------- | --------------------- | -| node\_id | INT32 | TAG | 节点 ID | -| config\_consensus\_port | INT32 | ATTRIBUTE | configNode 共识端口 | -| role | STRING | ATTRIBUTE | configNode 节点角色 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.config_nodes -+-------+---------------------+------+ -|node_id|config_consensus_port| role| -+-------+---------------------+------+ -| 0| 10720|Leader| -+-------+---------------------+------+ -``` - -### 2.17 DATA\_NODES 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的数据节点信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------------ | ---------- | ----------- | ----------------------- | -| node\_id | INT32 | TAG | 节点 ID | -| data\_region\_num | INT32 | ATTRIBUTE | DataRegion 数量 | -| schema\_region\_num | INT32 | ATTRIBUTE | SchemaRegion 数量 | -| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | -| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | -| mpp\_port | INT32 | ATTRIBUTE | MPP 通信端口 | -| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion 共识端口 | -| scema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion 共识端口 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.data_nodes -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -``` - -## 3. 权限说明 - -* 不支持通过`GRANT/REVOKE`语句对 `information_schema` 数据库及其下任何表进行权限操作 -* 支持任意用户通过`show databases`语句查看`information_schema`数据库相关信息 -* 支持任意用户通过`show tables from information_schema` 语句查看所有系统表相关信息 -* 支持任意用户通过`desc`语句查看任意系统表 diff --git a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations.md b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations.md index 1831e8557..6821d5dda 100644 --- a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations.md +++ b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations.md @@ -1,3 +1,6 @@ +--- +redirectTo: SQL-Metadata-Operations_apache.html +--- - -# 元数据操作 - -## 1. 数据库管理 - -### 1.1 创建数据库 - -**语法:** - -```SQL -CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? -``` - -更多详细语法说明请参考:[创建数据库](../Basic-Concept/Database-Management.md#_1-1-创建数据库) - -**示例:** - -```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - --- 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 -CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); -``` - -### 1.2 使用数据库 - -**语法:** - -```SQL -USE -``` - -**示例:** - -```SQL -USE database1 -``` - -### 1.3 查看当前数据库 - -**语法:** - -```SQL -SHOW CURRENT_DATABASE -``` - -**示例:** - -```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE test; - -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| iot_database| -+---------------+ -``` - -### 1.4 查看所有数据库 - -**语法:** - -```SQL -SHOW DATABASES (DETAILS)? -``` - -更多返回结果详细说明请参考:[查看所有数据库](../Basic-Concept/Database-Management.md#_1-4-查看所有数据库) - -**示例:** - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 3| 2| 100000| -| test2| 300| 3| 2| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -|test_prop| 300| 3| 2| 100000| 1| 2| -| test2| 300| 3| 2| 604800000| 1| 2| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -``` - -### 1.5 修改数据库 - -**语法:** - -```SQL -ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments -``` - -**示例:** - -```SQL -ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; -``` - -### 1.6 删除数据库 - -**语法:** - -```SQL -DROP DATABASE (IF EXISTS)? -``` - -**示例:** - -```SQL -DROP DATABASE IF EXISTS database1 -``` - -## 2. 表管理 - -### 2.1 创建表 - -**语法:** - -```SQL -createTableStatement - : CREATE TABLE (IF NOT EXISTS)? qualifiedName - '(' (columnDefinition (',' columnDefinition)*)? ')' - charsetDesc? - comment? - (WITH properties)? - ; - -charsetDesc - : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString - ; - -columnDefinition - : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? - | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? - ; - -charsetName - : CHAR SET identifier - | CHARSET identifier - | CHARACTER SET identifier - ; - -comment - : COMMENT string - ; -``` - -更多详细语法说明请参考:[创建表](../Basic-Concept/Table-Management.md#_1-1-创建表) - -**示例:** - -```SQL -CREATE TABLE table1 ( - time TIMESTAMP TIME, - region STRING TAG, - plant_id STRING TAG, - device_id STRING TAG, - model_id STRING ATTRIBUTE, - maintenance STRING ATTRIBUTE COMMENT 'maintenance', - temperature FLOAT FIELD COMMENT 'temperature', - humidity FLOAT FIELD COMMENT 'humidity', - status Boolean FIELD COMMENT 'status', - arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' -) COMMENT 'table1' WITH (TTL=31536000000); - -CREATE TABLE if not exists table2 (); - -CREATE TABLE tableC ( - "场站" STRING TAG, - "温度" int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); -``` - -### 2.2 查看表 - -**语法:** - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -**示例:** - -```SQL -IoTDB> show tables from test_db -+---------+-------+-------+ -|TableName|TTL(ms)|Comment| -+---------+-------+-------+ -| test| INF| TEST| -+---------+-------+-------+ - -IoTDB> show tables details from test_db -+---------+-------+----------+-------+ -|TableName|TTL(ms)| Status|Comment| -+---------+-------+----------+-------+ -| test| INF| USING| TEST| -| turbine| INF|PRE_CREATE| null| -| car| 1000|PRE_DELETE| null| -+---------+-------+----------+-------+ -``` - -### 2.3 查看表的列 - -**语法:** - -```SQL -(DESC | DESCRIBE) (DETAILS)? -``` - -**示例:** - -```SQL -IoTDB> desc tableB -+----------+---------+-----------+-------+ -|ColumnName| DataType| Category|Comment| -+----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| a| STRING| TAG| a| -| b| STRING| ATTRIBUTE| b| -| c| INT32| FIELD| c| -+----------+---------+-----------+-------+ - -IoTDB> desc tableB details -+----------+---------+-----------+----------+-------+ -|ColumnName| DataType| Category| Status|Comment| -+----------+---------+-----------+----------+-------+ -| time|TIMESTAMP| TIME| USING| null| -| a| STRING| TAG| USING| a| -| b| STRING| ATTRIBUTE| USING| b| -| c| INT32| FIELD| USING| c| -| d| INT32| FIELD|PRE_DELETE| d| -+----------+---------+-----------+----------+-------+ -``` - -### 2.4 修改表 - -**语法:** - -```SQL -ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn -// set TTL can use this -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties -| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' -| COMMENT ON COLUMN tableName.column IS 'column_comment' -``` - -**示例:** - -```SQL -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' -ALTER TABLE tableB set properties TTL=3600 -COMMENT ON TABLE table1 IS 'table1' -COMMENT ON COLUMN table1.a IS null -``` - -### 2.5 删除表 - -**语法:** - -```SQL -DROP TABLE (IF EXISTS)? -``` - -**示例:** - -```SQL -DROP TABLE tableA -DROP TABLE test.tableB -``` - - diff --git a/src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement.md b/src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement.md index 2a3845f9a..30e0f15bc 100644 --- a/src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement.md +++ b/src/zh/UserGuide/Master/Table/User-Manual/Maintenance-statement.md @@ -1,3 +1,6 @@ +--- +redirectTo: Maintenance-statement_apache.html +--- -# 运维语句 - -## 1. 状态查看 - -### 1.1 查看连接的模型 - -**含义**:返回当前连接的 sql_dialect 是树模型/表模型。 - -#### 语法: - -```SQL -showCurrentSqlDialectStatement - : SHOW CURRENT_SQL_DIALECT - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW CURRENT_SQL_DIALECT -``` - -执行结果如下: - -```SQL -+-----------------+ -|CurrentSqlDialect| -+-----------------+ -| TABLE| -+-----------------+ -``` -### 1.2 查看登录的用户名 - -**含义**:返回当前登录的用户名。 - -#### 语法: - -```SQL -showCurrentUserStatement - : SHOW CURRENT_USER - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW CURRENT_USER -``` - -执行结果如下: - -```SQL -+-----------+ -|CurrentUser| -+-----------+ -| root| -+-----------+ -``` - -### 1.3 查看连接的数据库名 - -**含义**:返回当前连接的数据库名,若没有执行过 use 语句,则为 null。 - -#### 语法: - -```SQL -showCurrentDatabaseStatement - : SHOW CURRENT_DATABASE - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW CURRENT_DATABASE; - -IoTDB> USE test; - -IoTDB> SHOW CURRENT_DATABASE; -``` - -执行结果如下: - -```SQL -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -+---------------+ -|CurrentDatabase| -+---------------+ -| test| -+---------------+ -``` - -### 1.4 查看集群版本 - -**含义**:返回当前集群的版本。 - -#### 语法: - -```SQL -showVersionStatement - : SHOW VERSION - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW VERSION -``` - -执行结果如下: - -```SQL -+-------+---------+ -|Version|BuildInfo| -+-------+---------+ -|2.0.1.2| 1ca4008| -+-------+---------+ -``` - -### 1.5 查看集群关键参数 - -**含义**:返回当前集群的关键参数。 - -#### 语法: - -```SQL -showVariablesStatement - : SHOW VARIABLES - ; -``` - -关键参数如下: - -1. **ClusterName**:当前集群的名称。 -2. **DataReplicationFactor**:数据副本的数量,表示每个数据分区(DataRegion)的副本数。 -3. **SchemaReplicationFactor**:元数据副本的数量,表示每个元数据分区(SchemaRegion)的副本数。 -4. **DataRegionConsensusProtocolClass**:数据分区(DataRegion)使用的共识协议类。 -5. **SchemaRegionConsensusProtocolClass**:元数据分区(SchemaRegion)使用的共识协议类。 -6. **ConfigNodeConsensusProtocolClass**:配置节点(ConfigNode)使用的共识协议类。 -7. **TimePartitionOrigin**:数据库时间分区的起始时间戳。 -8. **TimePartitionInterval**:数据库的时间分区间隔(单位:毫秒)。 -9. **ReadConsistencyLevel**:读取操作的一致性级别。 -10. **SchemaRegionPerDataNode**:数据节点(DataNode)上的元数据分区(SchemaRegion)数量。 -11. **DataRegionPerDataNode**:数据节点(DataNode)上的数据分区(DataRegion)数量。 -12. **SeriesSlotNum**:数据分区(DataRegion)的序列槽(SeriesSlot)数量。 -13. **SeriesSlotExecutorClass**:序列槽的实现类。 -14. **DiskSpaceWarningThreshold**:磁盘空间告警阈值(单位:百分比)。 -15. **TimestampPrecision**:时间戳精度。 - -#### 示例: - -```SQL -IoTDB> SHOW VARIABLES -``` - -执行结果如下: - -```SQL -+----------------------------------+-----------------------------------------------------------------+ -| Variable| Value| -+----------------------------------+-----------------------------------------------------------------+ -| ClusterName| defaultCluster| -| DataReplicationFactor| 1| -| SchemaReplicationFactor| 1| -| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| -|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| TimePartitionOrigin| 0| -| TimePartitionInterval| 604800000| -| ReadConsistencyLevel| strong| -| SchemaRegionPerDataNode| 1| -| DataRegionPerDataNode| 0| -| SeriesSlotNum| 1000| -| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| -| DiskSpaceWarningThreshold| 0.05| -| TimestampPrecision| ms| -+----------------------------------+-----------------------------------------------------------------+ -``` - -### 1.6 查看集群ID - -**含义**:返回当前集群的ID。 - -#### 语法: - -```SQL -showClusterIdStatement - : SHOW (CLUSTERID | CLUSTER_ID) - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW CLUSTER_ID -``` - -执行结果如下: - -```SQL -+------------------------------------+ -| ClusterId| -+------------------------------------+ -|40163007-9ec1-4455-aa36-8055d740fcda| -``` - -### 1.7 查看客户端直连的 DataNode 进程所在服务器的时间 - -#### 语法: - -**含义**:返回当前客户端直连的 DataNode 进程所在服务器的时间。 - -```SQL -showCurrentTimestampStatement - : SHOW CURRENT_TIMESTAMP - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW CURRENT_TIMESTAMP -``` - -执行结果如下: - -```SQL -+-----------------------------+ -| CurrentTimestamp| -+-----------------------------+ -|2025-02-17T11:11:52.987+08:00| -+-----------------------------+ -``` - -### 1.8 查看正在执行的查询信息 - -**含义**:用于显示所有正在执行的查询信息。 - -> 更多系统表使用方法请参考[系统表](../Reference/System-Tables.md) - -#### 语法: - -```SQL -showQueriesStatement - : SHOW (QUERIES | QUERY PROCESSLIST) - (WHERE where=booleanExpression)? - (ORDER BY sortItem (',' sortItem)*)? - limitOffsetClause - ; -``` - -**参数解释**: - -1. **WHERE** 子句:需保证过滤的目标列是结果集中存在的列 -2. **ORDER BY** 子句:需保证`sortKey`是结果集中存在的列 -3. **limitOffsetClause**: - - **含义**:用于限制结果集的返回数量。 - - **格式**:`LIMIT , `, `` 是偏移量,`` 是返回的行数。 -4. **QUERIES** 表中的列: - - **query_id**:查询语句的 ID - - **start_time**:查询开始的时间戳,时间戳精度与系统精度一致 - - **datanode_id**:发起查询语句的 DataNode 的ID - - **elapsed_time**:查询的执行耗时,单位是秒 - - **statement**:查询的 SQL 语句 - - **user**:发起查询的用户 - -#### 示例: - -```SQL -IoTDB> SHOW QUERIES WHERE elapsed_time > 30 -``` - -执行结果如下: - -```SQL -+-----------------------+-----------------------------+-----------+------------+------------+----+ -| query_id| start_time|datanode_id|elapsed_time| statement|user| -+-----------------------+-----------------------------+-----------+------------+------------+----+ -|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| -+-----------------------+-----------------------------+-----------+------------+------------+----+ -``` - - -### 1.9 查看分区信息 - -**含义**:返回当前集群的分区信息。 - -#### 语法: - -```SQL -showRegionsStatement - : SHOW REGIONS - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW REGIONS -``` - -执行结果如下: - -```SQL -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | -| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| -| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -``` - - -## 2. 状态设置 - -### 2.1 设置连接的模型 - -**含义**:将当前连接的 sql_dialect 置为树模型/表模型,在树模型和表模型中均可使用该命令。 - -#### 语法: - -```SQL -SET SQL_DIALECT EQ (TABLE | TREE) -``` - -#### 示例: - -```SQL -IoTDB> SET SQL_DIALECT=TABLE -IoTDB> SHOW CURRENT_SQL_DIALECT -``` - -执行结果如下: - -```SQL -+-----------------+ -|CurrentSqlDialect| -+-----------------+ -| TABLE| -+-----------------+ -``` - -### 2.2 更新配置项 - -**含义**:用于更新配置项,执行完成后会进行配置项的热加载,对于支持热修改的配置项会立即生效。 - -#### 语法: - -```SQL -setConfigurationStatement - : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? - ; - -propertyAssignments - : property (',' property)* - ; - -property - : identifier EQ propertyValue - ; - -propertyValue - : DEFAULT - | expression - ; -``` - -**参数解释**: - -1. **propertyAssignments** - - **含义**:更新的配置列表,由多个 `property` 组成。 - - 可以更新多个配置列表,用逗号分隔。 - - **取值**: - - `DEFAULT`:将配置项恢复为默认值。 - - `expression`:具体的值,必须是一个字符串。 -2. **ON INTEGER_VALUE** - - **含义**:指定要更新配置的节点 ID。 - - **可选性**:可选。如果不指定或指定的值低于 0,则更新所有 ConfigNode 和 DataNode 的配置。 - -#### 示例: - -```SQL -IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; -``` - -### 2.3 读取手动修改的配置文件 - -**含义**:用于读取手动修改过的配置文件,并对配置项进行热加载,对于支持热修改的配置项会立即生效。 - -#### 语法: - -```SQL -loadConfigurationStatement - : LOAD CONFIGURATION localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **localOrClusterMode** - - **含义**:指定配置热加载的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `LOCAL`:只对客户端直连的 DataNode 进行配置热加载。 - - `CLUSTER`:对集群中所有 DataNode 进行配置热加载。 - -#### 示例: - -```SQL -IoTDB> LOAD CONFIGURATION ON LOCAL; -``` - -### 2.4 设置系统的状态 - -**含义**:用于设置系统的状态。 - -#### 语法: - -```SQL -setSystemStatusStatement - : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **RUNNING | READONLY** - - **含义**:指定系统的新状态。 - - **取值**: - - `RUNNING`:将系统设置为运行状态,允许读写操作。 - - `READONLY`:将系统设置为只读状态,只允许读取操作,禁止写入操作。 -2. **localOrClusterMode** - - **含义**:指定状态变更的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `LOCAL`:仅对客户端直连的 DataNode 生效。 - - `CLUSTER`:对集群中所有 DataNode 生效。 - -#### 示例: - -```SQL -IoTDB> SET SYSTEM TO READONLY ON CLUSTER; -``` - - -## 3. 数据管理 - -### 3.1 刷写内存表中的数据到磁盘 - -**含义**:将内存表中的数据刷写到磁盘上。 - -#### 语法: - -```SQL -flushStatement - : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? - ; - -booleanValue - : TRUE | FALSE - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **identifier** - - **含义**:指定要刷写的数据库名称。 - - **可选性**:可选。如果不指定,则默认刷写所有数据库。 - - **多个数据库**:可以指定多个数据库名称,用逗号分隔。例如:`FLUSH test_db1, test_db2`。 -2. **booleanValue** - - **含义**:指定刷写的内容。 - - **可选性**:可选。如果不指定,则默认刷写顺序和乱序空间的内存。 - - **取值**: - - `TRUE`:只刷写顺序空间的内存表。 - - `FALSE`:只刷写乱序空间的MemTable。 -3. **localOrClusterMode** - - **含义**:指定刷写的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `ON LOCAL`:只刷写客户端直连的 DataNode 上的内存表。 - - `ON CLUSTER`:刷写集群中所有 DataNode 上的内存表。 - -#### 示例: - -```SQL -IoTDB> FLUSH test_db TRUE ON LOCAL; -``` - -### 3.2 清除 DataNode 上的缓存 - -**含义**:用于清除 DataNode 上的某种类型的缓存。 - -#### 语法: - -```SQL -clearCacheStatement - : CLEAR clearCacheOptions? CACHE localOrClusterMode? - ; - -clearCacheOptions - : ATTRIBUTE - | QUERY - | ALL - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **clearCacheOptions** - - **含义**:指定要清除的缓存类型。 - - **可选性**:可选。如果不指定,默认清除查询缓存(`QUERY`)。 - - **取值**: - - `ATTRIBUTE`:清除设备属性缓存。 - - `QUERY`:清除存储引擎中的查询缓存。 - - `ALL`:清除所有缓存,包括设备属性缓存、查询缓存以及树模型中的模式缓存。 -2. **localOrClusterMode** - - **含义**:指定清除缓存的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `ON LOCAL`:只清除客户端直连的 DataNode 上的缓存。 - - `ON CLUSTER`:清除集群中所有 DataNode 上的缓存。 - -#### 示例: - -```SQL -IoTDB> CLEAR ALL CACHE ON LOCAL; -``` - -## 4. 数据修复 - -### 4.1 启动后台扫描并修复 tsfile 任务 - -**含义**:启动一个后台任务,开始扫描并修复 tsfile,能够修复数据文件内的时间戳乱序类异常。 - -#### 语法: - -```SQL -startRepairDataStatement - : START REPAIR DATA localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **localOrClusterMode** - - **含义**:指定数据修复的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 - - `ON CLUSTER`:对集群中所有 DataNode 执行。 - -#### 示例: - -```SQL -IoTDB> START REPAIR DATA ON CLUSTER; -``` - -### 4.2 暂停后台修复 tsfile 任务 - -**含义**:暂停后台的修复任务,暂停中的任务可通过再次执行 start repair data 命令恢复。 - -#### 语法: - -```SQL -stopRepairDataStatement - : STOP REPAIR DATA localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **localOrClusterMode** - - **含义**:指定数据修复的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 - - `ON CLUSTER`:对集群中所有 DataNode 执行。 - -#### 示例: - -```SQL -IoTDB> STOP REPAIR DATA ON CLUSTER; -``` - -## 5. 终止查询 - -### 5.1 主动终止查询 - -**含义**:使用该命令主动地终止查询。 - -#### 语法: - -```SQL -killQueryStatement - : KILL (QUERY queryId=string | ALL QUERIES) - ; -``` - -**参数解释**: - -1. **QUERY queryId=string** - - **含义**:指定要终止的查询的 ID。 `` 是正在执行的查询的唯一标识符。 - - **获取查询 ID**:可以通过 `SHOW QUERIES` 命令获取所有正在执行的查询及其 ID。 -2. **ALL QUERIES** - - **含义**:终止所有正在执行的查询。 - -#### 示例: - -通过指定 `queryId` 可以中止指定的查询,为了获取正在执行的查询 id,用户可以使用 show queries 命令,该命令将显示所有正在执行的查询列表。 - -```SQL -IoTDB> KILL QUERY 20250108_101015_00000_1; -- 终止指定query -IoTDB> KILL ALL QUERIES; -- 终止所有query -``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table.md b/src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table.md index fc6a446c5..4b9eaa718 100644 --- a/src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table.md +++ b/src/zh/UserGuide/Master/Table/User-Manual/Tree-to-Table.md @@ -1,3 +1,6 @@ +--- +redirectTo: Tree-to-Table_apache.html +--- -# 树转表视图 - -## 1. 功能概述 - -IoTDB 提供了树转表功能,支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理: - -* 数据写入阶段,采用树模型语法,支持数据灵活接入和扩展。 -* 数据分析阶段,采用表模型语法,支持通过标准 SQL 查询语言,执行复杂的数据分析。 - -![](/img/tree-to-table-1.png) - -> - V2.0.5 及以后版本支持该功能。 -> - 表视图只读,不允许通过表视图写入数据。 - -## 2. 功能介绍 -### 2.1 创建表视图 -#### 2.1.1 语法定义 - -```SQL --- create (or replace) view on tree -CREATE - [OR REPLACE] - VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) - [comment] - [RESTRICT] - [WITH properties] - AS prefixPath - -viewColumnDefinition - : column_name [dataType] TAG [comment] # tagColumn - | column_name [dataType] TIME [comment] # timeColumn - | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn - ; - -comment - : COMMENT string - ; -``` - -> 注意:列仅支持 tag / field / time,不支持 attribute。 - -#### 2.1.2 语法说明 -1. **`prefixPath`** - -对应树模型的路径,路径最后一级必须为 `**`,且其他层级均不能出现 `*` 或 `**`。该路径确定 VIEW 对应的子树。 - -2. **`view_name`** - -视图名称,与表名相同(具体约束可参考[创建表](../Basic-Concept/Table-Management.md#\_1-1-创建表)),如 db.view。 - -3. **`viewColumnDefinition`** - -* `TAG`:每个 Tag 列按顺序对应`prefixPath`后面层级的路径节点。 -* `FIELD`:FIELD 列对应树模型中的测点(叶子节点)。 - * 若指定了 FIELD 列,则列名使用声明中的`column_name`。 - * 若声明了 `original_measurement`,则直接映射到树模型该测点。否则取小写`column_name` 作为测点名进行树模型映射。 - * 不支持多个 FIELD 映射到树模型同名测点。 - * 若未指定 FIELD 列的 `dataType`,则默认获取树模型映射测点的数据类型。 - * 若树模型中的设备不包含某些声明的 FIELD 列,或与声明的 FIELD 列的数据类型不一致,则在查询该设备时,该 FIELD 列的值永远为 NULL。 - * 若未指定 FIELD 列,则创建时会自动扫描出`prefixPath`子树下所有的测点(包括定义为所有普通序列的测点,以及挂载路径与 `prefixPath `有所重合的所有模板中的测点),列名使用树模型测点名称。 - * 不支持树模型存在名称(含小写)相同但类型不同的测点 - -4. **`WITH properties`** - -目前仅支持 TTL,表示该视图 TTL ms 之前的数据不会在查询时展示,即`WHERE time > now() - TTL`。若树模型设置了 TTL,则查询时取两者中的更小值。 - -> 注意:表视图 TTL 不影响树模型中设备的真实 TTL,当设备数据达到树模型设定的 TTL 后,将被系统物理删除。 - -5. **`OR REPLACE`** - -table 与 view 不能重名。创建时若已存在同名 table ,则会报错;若已存在同名 view ,则进行替换。 - -6. **`RESTRICT`** - -约束匹配树模型设备的层级数(从 prefixPath 下一层开始),若有 RESTRICT 字段,则匹配层级完全等于 tag 数量的 device,否则匹配层级小于等于 tag 数量的 device。默认非 RESTRICT,即匹配层级小于等于 tag 数量的 device。 - -#### 2.1.3 使用示例 -1. 树模型及表视图原型 - -![](/img/tree-to-table-2.png) - -2. 创建表视图 - -* 创建语句 - -```SQL -CREATE OR REPLACE VIEW viewdb."风机表" - ("风机组" TAG, - "风机号" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -with (ttl=604800000) -AS root.db.** -``` - -* 具体说明 - -该语句表示,创建出名为 `viewdb."风机表"` 的视图(viewdb 如不存在会报错),如果该视图已存在,则替换该视图: - -* 为挂载于树模型 root.db.\*\* 路径下面的序列创建表视图。 -* 具备`风机组`、`风机号`两个 `TAG` 列,因此表视图中只包含原树模型中第 3 层上的设备。 -* 具备`电压`、`电流`两个 `FIELD` 列。这里两个 `FIELD` 列对应树模型下的序列名同样是`电压`、`电流`,且仅仅选取类型为 `DOUBLE` 的序列。 - - **​序列名的改名需求:​**如果树模型下的序列名为`current`,想要创建出的表视图中对应的 `FIELD` 列名为`电流`,这种情况下,SQL 变更如下: - - ```SQL - CREATE OR REPLACE VIEW viewdb."风机表" - ("风机组" TAG, - "风机号" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD FROM current - ) - AS root.db.** - with (ttl=604800000) - ``` - -### 2.2 修改表视图 -#### 2.2.1 语法定义 - -修改表视图功能支持修改视图名称、添加列、列重命名、删除列、设置视图的 TTL 属性,以及通过 COMMENT 添加注释。 - -```SQL --- 修改视图名 -ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier - --- 在视图中添加某一列 -ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition -viewColumnDefinition - : column_name [dataType] TAG # tagColumn - | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn - --- 为视图中的某一列重命名 -ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName - --- 删除视图中的某一列 -ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName - --- 修改视图的 TTL -ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments - --- 添加注释 -COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView -COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn -``` - -#### 2.2.2 语法说明 -1. `SET PROPERTIES`操作目前仅支持对表视图的 TTL 属性进行配置。 -2. 删除列功能,仅支持删除物理量列(FIELD),标识列(TAG)不支持删除。 -3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 -#### 2.2.3 使用示例 - -```SQL --- 修改视图名 -ALTER VIEW IF EXISTS tableview1 RENAME TO tableview - --- 在视图中添加某一列 -ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field - --- 为视图中的某一列重命名 -ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp - --- 删除视图中的某一列 -ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp - --- 修改视图的 TTL -ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 - --- 添加注释 -COMMENT ON VIEW tableview IS '树转表' -COMMENT ON COLUMN tableview.status is Null -``` - -### 2.3 删除表视图 -#### 2.3.1 语法定义 - -```SQL -DROP VIEW [IF EXISTS] viewName -``` - -#### 2.3.2 使用示例 - -```SQL -DROP VIEW IF EXISTS tableview -``` - -### 2.4 查看表视图 -#### 2.4.1 **`Show Tables`** -1. 语法定义 - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -2. 语法说明 - -`SHOW TABLES (DETAILS)` 语句通过结果集的`TABLE_TYPE`字段展示表或视图的类型信息: - -| 类型 | `TABLE_TYPE`字段值 | -| -------------------------------------- | ------------------------ | -| 普通表(Table) | `BASE TABLE` | -| 树转表视图(Tree View) | `VIEW FROM TREE` | -| 系统表(Iinformation\_schema.Tables) | `SYSTEM VIEW` | - -3. 使用示例 - -```SQL -IoTDB> show tables details from database1 -+-----------+-----------+------+-------+--------------+ -| TableName| TTL(ms)|Status|Comment| TableType| -+-----------+-----------+------+-------+--------------+ -| tableview| INF| USING| 树转表 |VIEW FROM TREE| -| table1|31536000000| USING| null| BASE TABLE| -| table2|31536000000| USING| null| BASE TABLE| -+-----------+-----------+------+-------+--------------+ - -IoTDB> show tables details from information_schema -+--------------+-------+------+-------+-----------+ -| TableName|TTL(ms)|Status|Comment| TableType| -+--------------+-------+------+-------+-----------+ -| columns| INF| USING| null|SYSTEM VIEW| -| config_nodes| INF| USING| null|SYSTEM VIEW| -|configurations| INF| USING| null|SYSTEM VIEW| -| data_nodes| INF| USING| null|SYSTEM VIEW| -| databases| INF| USING| null|SYSTEM VIEW| -| functions| INF| USING| null|SYSTEM VIEW| -| keywords| INF| USING| null|SYSTEM VIEW| -| models| INF| USING| null|SYSTEM VIEW| -| nodes| INF| USING| null|SYSTEM VIEW| -| pipe_plugins| INF| USING| null|SYSTEM VIEW| -| pipes| INF| USING| null|SYSTEM VIEW| -| queries| INF| USING| null|SYSTEM VIEW| -| regions| INF| USING| null|SYSTEM VIEW| -| subscriptions| INF| USING| null|SYSTEM VIEW| -| tables| INF| USING| null|SYSTEM VIEW| -| topics| INF| USING| null|SYSTEM VIEW| -| views| INF| USING| null|SYSTEM VIEW| -+--------------+-------+------+-------+-----------+ -``` - -#### 2.4.2 **`Show Create Table/View`** -1. 语法定义 - -```SQL -SHOW CREATE TABLE|VIEW viewname; -``` - -2. 语法说明 - -* SHOW CREATE TABLE 语句可用于展示普通表或者视图的完整创建信息; -* SHOW CREATE VIEW 语句仅可用于展示视图的完整创建信息; -* 两种语句均不支持用于展示系统表; - -3. 使用示例 - -```SQL -IoTDB> show create table tableview -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| View| Create View| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ - -IoTDB> show create view tableview -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| View| Create View| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -``` - -### 2.5 非对齐与对齐设备的查询差异 - -树转表视图在查询对齐设备和非对齐设备中有 null 值的情况下结果​**可能与等价的树模型 align by device 查询不同**​。 - -* **对齐设备** - * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 - * 表视图的查询表现:与表模型一致,保留全是 null 的行 -* **非对齐设备** - * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 - * 表视图的查询表现:与树模型一致,不保留全是 null 的行 -* **说明示例** - * 对齐 - - ```SQL - -- 树模型写入数据(对齐) - CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) - INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) - INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) - - -- 创建 VIEW 语句 - CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** - - -- 查询 - IoTDB> select voltage from view1 - +-------+ - |voltage| - +-------+ - | 1| - | null| - +-------+ - Total line number = 2 - ``` - - * 非对齐 - - ```SQL - -- 树模型写入数据(非对齐) - CREATE TIMESERIES root.db.battery.b1.voltage INT32 - CREATE TIMESERIES root.db.battery.b1.current FLOAT - INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) - INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) - - -- 创建 VIEW 语句 - CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** - - -- 查询 - IoTDB> select voltage from view1 - +-------+ - |voltage| - +-------+ - | 1| - +-------+ - Total line number = 1 - - -- 如果在查询语句中指定了所有 field 列,或是仅指定了非 field 列时,才可以确保查到所有行 - IoTDB> select voltage,current from view1 - +-------+-------+ - |voltage|current| - +-------+-------+ - | 1| 1.0| - | null| 1.0| - +-------+-------+ - Total line number = 2 - - IoTDB> select battery_id from view1 - +-------+ - |battery_id| - +-------+ - | b1| - | b1| - +-------+ - Total line number = 2 - - -- 如果查询中同时有部分 field 列,那最终结果的行数取决于这部分 field 列根据时间戳对齐后的行数 - IoTDB> select time,voltage from view1 - +-----------------------------+-------+ - | time|voltage| - +-----------------------------+-------+ - |1970-01-01T08:00:00.001+08:00| 1| - +-----------------------------+-------+ - Total line number = 1 - ``` - -## 3. 场景示例 -### 3.1 原树模型管理了多种类型的设备 - -* 场景中不同类型的设备具备不同的层级路径和测点集合。 -* ​**写入时**​:在数据库节点下按设备类型创建分支,每种设备下可以有不同的测点结构 -* ​**查询时**​:为每种类型的设备建立一张表,每个表具有不同的标签和测点集合 - -![](/img/tree-to-table-3.png) - -**表视图的创建 SQL:** - -```SQL --- 风机表 -CREATE VIEW viewdb."风机表" - ("风机组" TAG, - "风机号" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -AS root.db."风机".** - --- 电机表 -CREATE VIEW viewdb."电机表" - ("电机组" TAG, - "电机号" TAG, - "功率" FLOAT FIELD, - "电量" FLOAT FIELD, - "温度" FLOAT FIELD - ) -AS root.db."电机".** -``` - -### 3.2 原树模型中没有设备,只有测点 - -如场站的监控系统中,每个测点都有唯一编号,但无法对应到某些设备 - -> 大宽表形式 - -![](/img/tree-to-table-4.png) - -**表视图的创建 SQL:** - -```SQL -CREATE VIEW viewdb.machine - (DCS_PIT_02105A DOUBLE FIELD, - DCS_PIT_02105B DOUBLE FIELD, - DCS_PIT_02105C DOUBLE FIELD, - ... - DCS_XI_02716A DOUBLE FIELD - ) -AS root.db.** -``` - -### 3.3 原树模型中一个设备既有子设备,也有测点 - -如在储能场景中,每一层结构都要监控其电压和电流 - -* ​**写入时**​:按照物理世界的监测点,对每一层结构进行建模 -* ​**查询时**​:按照设备分类,建立多个表对每一层结构信息进行管理 - -![](/img/tree-to-table-5.png) - -**表视图的创建 SQL:** - -```SQL --- 电池舱表 -CREATE VIEW viewdb."电池舱表" - ("电池站" TAG, - "电池舱" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -RESTRICT -AS root.db.** - --- 电池堆表 -CREATE VIEW viewdb."电池堆表" - ("电池站" TAG, - "电池舱" TAG, - "电池堆" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -RESTRICT -AS root.db.** - --- 电池簇表 -CREATE VIEW viewdb."电池簇表" - ("电池站" TAG, - "电池舱" TAG, - "电池堆" TAG, - "电池簇" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -RESTRICT -AS 'root.db.**' - --- 电芯表 -CREATE VIEW viewdb."电芯表" - ("电池站" TAG, - "电池舱" TAG, - "电池堆" TAG, - "电池簇" TAG, - "电芯" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -RESTRICT -AS root.db.** -``` - -### 3.4 原树模型中一个设备下只有一个测点 - -> 窄表形式 - -#### 3.4.1 所有测点数据类型相同 - -![](/img/tree-to-table-6.png) - -**表视图的创建 SQL:** - -```SQL -CREATE VIEW viewdb.machine - ( - sensor_id STRING TAG, - value DOUBLE FIELD - ) -AS root.db.** -``` - -#### 3.4.2 测点的数据类型不相同 -##### 3.4.2.1 为每一种数据类型的测点建一个窄表视图 - -​**优点**​:表视图数量是常数个,仅与系统中的数据类型相关 - -​**缺点**​:查询某一个测点值时,需要提前知道其数据类型,再去决定查询哪张表视图 - -![](/img/tree-to-table-7.png) - -**表视图的创建 SQL:** - -```SQL -CREATE VIEW viewdb.machine_float - ( - sensor_id STRING TAG, - value FLOAT FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_double - ( - sensor_id STRING TAG, - value DOUBLE FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_int32 - ( - sensor_id STRING TAG, - value INT32 FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_int64 - ( - sensor_id STRING TAG, - value INT64 FIELD - ) -AS root.db.** - -... -``` - -##### 3.4.2.2 为每一个测点建一个表 - -​**优点**​:查询某一个测点值时,不需要先查一下数据类型,再去决定查询哪张表,简单便捷 - -​**缺点**​:当测点数量较多时,会引入过多的表视图,需要写大量的建视图语句 - -![](/img/tree-to-table-8.png) - -**表视图的创建 SQL:** - -```SQL -CREATE VIEW viewdb.DCS_PIT_02105A - ( - value FLOAT FIELD - ) -AS root.db.DCS_PIT_02105A.** - -CREATE VIEW viewdb.DCS_PIT_02105B - ( - value DOUBLE FIELD - ) -AS root.db.DCS_PIT_02105B.** - -CREATE VIEW viewdb.DCS_XI_02716A - ( - value INT64 FIELD - ) -AS root.db.DCS_XI_02716A.** - -...... -``` diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management.md index 668d44e95..c2236d44a 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management.md @@ -1,3 +1,6 @@ +--- +redirectTo: Database-Management_apache.html +--- - -# 数据库管理 - -## 1. 数据库管理 - -### 1.1 创建数据库 - -用于创建数据库。 - -**语法:** - -```SQL - CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? -``` - -**说明:** - -1. 数据库名称,具有以下特性: - - 大小写不敏感,创建成功后,统一显示为小写 - - 名称的长度不得超过 64 个字符。 - - 名称中包含下划线(_)、数字(非开头)、英文字母可以直接创建 - - 名称中包含特殊字符(如`)、中文字符、数字开头时,必须用双引号 "" 括起来。 - -2. WITH properties 子句可配置如下属性: - -> 注:属性的大小写不敏感,有关详细信息[大小写敏感规则](../SQL-Manual/Identifier.md#大小写敏感性)。 - -| 属性 | 含义 | 默认值 | -| ------------------------- | ---------------------------------------- | --------- | -| `TTL` | 数据自动过期删除,单位 ms | INF | -| `TIME_PARTITION_INTERVAL` | 数据库的时间分区间隔,单位 ms | 604800000 | -| `SCHEMA_REGION_GROUP_NUM` | 数据库的元数据副本组数量,一般不需要修改 | 1 | -| `DATA_REGION_GROUP_NUM` | 数据库的数据副本组数量,一般不需要修改 | 2 | - -**示例:** - -```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 -CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); -``` - -### 1.2 使用数据库 - -用于指定当前数据库作为表的命名空间。 - -**语法:** - -```SQL -USE -``` - -**示例:** - -```SQL -USE database1 -``` - -### 1.3 查看当前数据库 - -返回当前会话所连接的数据库名称,若未执行过 `use`语句指定数据库,则默认为 `null`。 - -**语法:** - -```SQL -SHOW CURRENT_DATABASE -``` - -**示例:** - -```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE test; - -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| iot_database| -+---------------+ -``` - -### 1.4 查看所有数据库 - -用于查看所有数据库和数据库的属性信息。 - -**语法:** - -```SQL -SHOW DATABASES (DETAILS)? -``` - -**语句返回列含义如下:** - -| 列名 | 含义 | -| ----------------------- | ------------------------------------------------------------ | -| database | database名称。 | -| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management.md#14-修改表) 来设置或更新表的TTL时间。 | -| SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | -| DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | -| TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | -| SchemaRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的元数据副本组数量,一般不需要修改 | -| DataRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的数据副本组数量,一般不需要修改 | - -**示例:** - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 3| 2| 100000| -| test2| 300| 3| 2| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -|test_prop| 300| 3| 2| 100000| 1| 2| -| test2| 300| 3| 2| 604800000| 1| 2| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -``` - -### 1.5 修改数据库 - -用于修改数据库中的部分属性。 - -**语法:** - -```SQL -ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments -``` - -**说明:** - -1. `ALTER DATABASE`操作目前仅支持对数据库的`SCHEMA_REGION_GROUP_NUM`、`DATA_REGION_GROUP_NUM`以及`TTL`属性进行修改。 - -**示例:** - -```SQL -ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; -``` - -### 1.6 删除数据库 - -用于删除数据库。 - -**语法:** - -```SQL -DROP DATABASE (IF EXISTS)? -``` - -**说明:** - -1. 数据库已被设置为当前使用(use)的数据库,仍然可以被删除(drop)。 -2. 删除数据库将导致所选数据库及其内所有表连同其存储的数据一并被删除。 - -**示例:** - -```SQL -DROP DATABASE IF EXISTS database1 -``` diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md index 668d44e95..eede4d4ca 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md @@ -120,15 +120,15 @@ SHOW DATABASES (DETAILS)? **语句返回列含义如下:** -| 列名 | 含义 | -| ----------------------- | ------------------------------------------------------------ | -| database | database名称。 | -| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management.md#14-修改表) 来设置或更新表的TTL时间。 | -| SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | -| DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | -| TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | -| SchemaRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的元数据副本组数量,一般不需要修改 | -| DataRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的数据副本组数量,一般不需要修改 | +| 列名 | 含义 | +| ----------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| database | database名称。 | +| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management_apache.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management_apache.md#14-修改表) 来设置或更新表的TTL时间。 | +| SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | +| DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | +| TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | +| SchemaRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的元数据副本组数量,一般不需要修改 | +| DataRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的数据副本组数量,一般不需要修改 | **示例:** diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md index 668d44e95..0c5b5c5da 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md @@ -120,15 +120,15 @@ SHOW DATABASES (DETAILS)? **语句返回列含义如下:** -| 列名 | 含义 | -| ----------------------- | ------------------------------------------------------------ | -| database | database名称。 | -| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management.md#14-修改表) 来设置或更新表的TTL时间。 | -| SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | -| DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | -| TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | -| SchemaRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的元数据副本组数量,一般不需要修改 | -| DataRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的数据副本组数量,一般不需要修改 | +| 列名 | 含义 | +| ----------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| database | database名称。 | +| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management_timecho.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management_timecho.md#14-修改表) 来设置或更新表的TTL时间。 | +| SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | +| DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | +| TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | +| SchemaRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的元数据副本组数量,一般不需要修改 | +| DataRegionGroupNum | 使用`DETAILS`语句会返回此列,展示数据库的数据副本组数量,一般不需要修改 | **示例:** diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data.md b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data.md index 9c9f3178d..fde4f19e0 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data.md @@ -1,3 +1,6 @@ +--- +redirectTo: TTL-Delete-Data_apache.html +--- - -# 数据保留时间 - -## 1. 概览 - -IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系统自动定期删除旧数据,以有效控制磁盘空间并维护高性能查询和低内存占用。TTL默认以毫秒为单位,数据过期后不可查询且禁止写入,但物理删除会延迟至压缩时。需注意,TTL变更可能导致短暂数据可查询性变化。 - -**注意事项:** - -1. TTL设置为毫秒,不受配置文件时间精度影响。 -2. TTL变更可能影响数据的可查询性。 -3. 系统最终会移除过期数据,但存在延迟。 -4. TTL 判断数据是否过期依据的是数据点时间,非写入时间。 - -## 2. 设置 TTL - -在表模型中,IoTDB 的 TTL 是按照表的粒度生效的。可以直接在表上设置 TTL,或者在数据库级别设置 TTL。当在数据库级别设置了TTL时,在创建新表的过程中,系统会自动采用这个TTL值作为新表的默认设置,但每个表仍然可以独立地被设置或覆盖该值。 - -注意,如果数据库级别的TTL被修改,不会直接影响到已经存在的表的TTL设置。 - -### 2.1 为表设置 TTL - -如果在建表时通过sql语句设置了表的 TTL,则会以表的ttl为准。建表语句详情可见:[表管理](../Basic-Concept/Table-Management.md) - -示例1:创建表时设置 TTL - -```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600) -``` - -示例2:更改表语句设置TTL: - -```SQL -ALTER TABLE tableB SET PROPERTIES TTL=3600; -``` - -示例3:不指定TTL或设为默认值,它将与数据库的TTL相同,默认情况下是'INF'(无穷大): - -```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("场站" string id, "温度" int32) -ALTER TABLE tableB set properties TTL=DEFAULT -``` - -### 2.2 为数据库设置 TTL - -没有设置表的TTL,则会继承database的ttl。建数据库语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md) - -示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: - -```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) -``` - -示例5:数据库不设置ttl,将生成一个没有ttl的表: - -```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) -``` - -示例6:数据库设置了ttl,但想显式设置没有TTL的表,可以将TTL设置为'INF': - -```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') -``` - -## 3. 取消 TTL - -取消 TTL 设置,可以修改表的 TTL 设置为 'INF'。目前,IoTDB 不支持修改数据库的 TTL。 - -```SQL -ALTER TABLE tableB set properties TTL='INF' -``` - -## 4. 查看 TTL 信息 - -使用 "SHOW DATABASES" 和 "SHOW TABLES" 命令可以直接显示数据库和表的 TTL 详情。数据库和表管理语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md)、[表管理](../Basic-Concept/Table-Management.md) - -> 注意,树模型数据库的TTL也将显示。 - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 1| 3| 100000| -| test2| 300| 1| 1| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| -+---------+-------+-----------------------+---------------------+---------------------+-----+ -|test_prop| 300| 1| 3| 100000|TABLE| -| test2| 300| 1| 1| 604800000| TREE| -+---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables -+---------+-------+ -|TableName|TTL(ms)| -+---------+-------+ -| grass| 1000| -| bamboo| 300| -| flower| INF| -+---------+-------+ - -IoTDB> show tables details -+---------+-------+----------+ -|TableName|TTL(ms)| Status| -+---------+-------+----------+ -| bean| 300|PRE_CREATE| -| grass| 1000| USING| -| bamboo| 300| USING| -| flower| INF| USING| -+---------+-------+----------+ -``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md index 9c9f3178d..77b59ba13 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md @@ -40,7 +40,7 @@ IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系 ### 2.1 为表设置 TTL -如果在建表时通过sql语句设置了表的 TTL,则会以表的ttl为准。建表语句详情可见:[表管理](../Basic-Concept/Table-Management.md) +如果在建表时通过sql语句设置了表的 TTL,则会以表的ttl为准。建表语句详情可见:[表管理](../Basic-Concept/Table-Management_apache.md) 示例1:创建表时设置 TTL @@ -64,7 +64,7 @@ ALTER TABLE tableB set properties TTL=DEFAULT ### 2.2 为数据库设置 TTL -没有设置表的TTL,则会继承database的ttl。建数据库语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md) +没有设置表的TTL,则会继承database的ttl。建数据库语句详情可见:[数据库管理](../Basic-Concept/Database-Management_apache.md) 示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: @@ -100,7 +100,7 @@ ALTER TABLE tableB set properties TTL='INF' ## 4. 查看 TTL 信息 -使用 "SHOW DATABASES" 和 "SHOW TABLES" 命令可以直接显示数据库和表的 TTL 详情。数据库和表管理语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md)、[表管理](../Basic-Concept/Table-Management.md) +使用 "SHOW DATABASES" 和 "SHOW TABLES" 命令可以直接显示数据库和表的 TTL 详情。数据库和表管理语句详情可见:[数据库管理](../Basic-Concept/Database-Management_apache.md)、[表管理](../Basic-Concept/Table-Management_apache.md) > 注意,树模型数据库的TTL也将显示。 diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md index 9c9f3178d..6c145ef83 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md @@ -40,7 +40,7 @@ IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系 ### 2.1 为表设置 TTL -如果在建表时通过sql语句设置了表的 TTL,则会以表的ttl为准。建表语句详情可见:[表管理](../Basic-Concept/Table-Management.md) +如果在建表时通过sql语句设置了表的 TTL,则会以表的ttl为准。建表语句详情可见:[表管理](../Basic-Concept/Table-Management_timecho.md) 示例1:创建表时设置 TTL @@ -64,7 +64,7 @@ ALTER TABLE tableB set properties TTL=DEFAULT ### 2.2 为数据库设置 TTL -没有设置表的TTL,则会继承database的ttl。建数据库语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md) +没有设置表的TTL,则会继承database的ttl。建数据库语句详情可见:[数据库管理](../Basic-Concept/Database-Management_timecho.md) 示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: @@ -100,7 +100,7 @@ ALTER TABLE tableB set properties TTL='INF' ## 4. 查看 TTL 信息 -使用 "SHOW DATABASES" 和 "SHOW TABLES" 命令可以直接显示数据库和表的 TTL 详情。数据库和表管理语句详情可见:[数据库管理](../Basic-Concept/Database-Management.md)、[表管理](../Basic-Concept/Table-Management.md) +使用 "SHOW DATABASES" 和 "SHOW TABLES" 命令可以直接显示数据库和表的 TTL 详情。数据库和表管理语句详情可见:[数据库管理](../Basic-Concept/Database-Management_timecho.md)、[表管理](../Basic-Concept/Table-Management_timecho.md) > 注意,树模型数据库的TTL也将显示。 diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management.md index 314991c13..cb319a68e 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management.md @@ -1,3 +1,6 @@ +--- +redirectTo: Table-Management_apache.html +--- - -# 表管理 - -在开始使用表管理功能前,推荐您先了解以下相关预备知识,以便更好地理解和应用表管理功能: -* [时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md):了解时序数据的基本概念与特点,帮助建立建模基础。 -* [建模方案设计](../Background-knowledge/Data-Model-and-Terminology_timecho.md):掌握 IoTDB 时序模型及适用场景,为表管理提供设计基础。 - -## 1. 表管理 - -### 1.1 创建表 - -#### 1.1.1 通过 Create 语句手动创建表 - -用于在当前数据库中创建表,也可以对任何指定数据库创建表,格式为“数据库名.表名”。 - -**语法:** - -```SQL -createTableStatement - : CREATE TABLE (IF NOT EXISTS)? qualifiedName - '(' (columnDefinition (',' columnDefinition)*)? ')' - charsetDesc? - comment? - (WITH properties)? - ; - -charsetDesc - : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString - ; - -columnDefinition - : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? - | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? - ; - -charsetName - : CHAR SET identifier - | CHARSET identifier - | CHARACTER SET identifier - ; - -comment - : COMMENT string - ; -``` - -**说明:** - -1. 在创建表时,可以不指定时间列(TIME),IoTDB会自动添加该列。其他所有列可以通过在数据库配置时启用`enable_auto_create_schema`选项,或通过 session 接口自动创建或修改表的语句来添加。 -2. 列的类别可以省略,默认为`FIELD`。当列的类别为`TAG`或`ATTRIBUTE`时,数据类型需为`STRING`(可省略)。 -3. 表的TTL默认为其所在数据库的TTL。如果使用默认值,可以省略此属性,或将其设置为`default`。 -4. 表名称,具有以下特性: - - 大小写不敏感,创建成功后,统一显示为小写 - - 名称可包含特殊字符,如 `~!`"%` 等 - - 包含特殊字符或中文字符的表名创建时必须用双引号 "" 括起来。 - - 注意:SQL中特殊字符或中文表名需加双引号。原生API中无需额外添加,否则表名会包含引号字符。 - - 当为表命名时,最外层的双引号(`""`)不会在实际创建的表名中出现。 - - - ```SQL - -- SQL 中 - "a""b" --> a"b - """""" --> "" - -- API 中 - "a""b" --> "a""b" - ``` -5. columnDefinition 列名称与表名称具有相同特性,并且可包含特殊字符`.`。 -6. COMMENT 给表添加注释。 - -**示例:** - -```SQL -CREATE TABLE table1 ( - time TIMESTAMP TIME, - region STRING TAG, - plant_id STRING TAG, - device_id STRING TAG, - model_id STRING ATTRIBUTE, - maintenance STRING ATTRIBUTE COMMENT 'maintenance', - temperature FLOAT FIELD COMMENT 'temperature', - humidity FLOAT FIELD COMMENT 'humidity', - status Boolean FIELD COMMENT 'status', - arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' -) COMMENT 'table1' WITH (TTL=31536000000); - -CREATE TABLE if not exists table2 (); - -CREATE TABLE tableC ( - "场站" STRING TAG, - "温度" int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); -``` - -#### 1.1.2 通过 Session 写入自动创建表 - -在通过 Session 进行数据写入时,IoTDB 能够根据写入请求中的信息自动构建表结构,无需用户事先手动创建表即可直接执行数据写入操作。 - -**示例:** - -```Java -try (ITableSession session = - new TableSessionBuilder() - .nodeUrls(Collections.singletonList("127.0.0.1:6667")) - .username("root") - .password("root") - .build()) { - - session.executeNonQueryStatement("CREATE DATABASE db1"); - session.executeNonQueryStatement("use db1"); - - // 不创建表直接写入数据 - List columnNameList = - Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); - List dataTypeList = - Arrays.asList( - TSDataType.STRING, - TSDataType.STRING, - TSDataType.STRING, - TSDataType.STRING, - TSDataType.FLOAT, - TSDataType.DOUBLE); - List columnTypeList = - new ArrayList<>( - Arrays.asList( - ColumnCategory.TAG, - ColumnCategory.TAG, - ColumnCategory.TAG, - ColumnCategory.ATTRIBUTE, - ColumnCategory.FIELD, - ColumnCategory.FIELD)); - Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); - for (long timestamp = 0; timestamp < 100; timestamp++) { - int rowIndex = tablet.getRowSize(); - tablet.addTimestamp(rowIndex, timestamp); - tablet.addValue("region_id", rowIndex, "1"); - tablet.addValue("plant_id", rowIndex, "5"); - tablet.addValue("device_id", rowIndex, "3"); - tablet.addValue("model", rowIndex, "A"); - tablet.addValue("temperature", rowIndex, 37.6F); - tablet.addValue("humidity", rowIndex, 111.1); - if (tablet.getRowSize() == tablet.getMaxRowNumber()) { - session.insert(tablet); - tablet.reset(); - } - } - if (tablet.getRowSize() != 0) { - session.insert(tablet); - tablet.reset(); - } -} -``` - -在代码执行完成后,可以通过下述语句确认表已成功创建,其中包含了时间列、标签列、属性列以及测点列等各类信息。 - -```SQL -IoTDB> desc table1 -+-----------+---------+-----------+-------+ -| ColumnName| DataType| Category|Comment| -+-----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| region_id| STRING| TAG| null| -| plant_id| STRING| TAG| null| -| device_id| STRING| TAG| null| -| model| STRING| ATTRIBUTE| null| -|temperature| FLOAT| FIELD| null| -| humidity| DOUBLE| FIELD| null| -+-----------+---------+-----------+-------+ -``` - -### 1.2 查看表 - -用于查看该数据库中或指定数据库中的所有表和表库的属性信息。 - -**语法:** - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -**说明:** - -1. 在查询中指定了`FROM`或`IN`子句时,系统将展示指定数据库内的所有表。 -2. 如果未指定`FROM`或`IN`子句,系统将展示当前选定数据库中的所有表。如果用户未使用(use)某个数据库空间,系统将报错。 -3. 请求显示详细信息(指定`DETAILS`),系统将展示表的当前状态,包括: - - `USING`:表示表处于正常可用状态。 - - `PRE_CREATE`:表示表正在创建中或创建失败,此时表不可用。 - - `PRE_DELETE`:表示表正在删除中或删除失败,此类表将永久不可用。 - -**示例:** - -```SQL -IoTDB> show tables from test_db -+---------+-------+-------+ -|TableName|TTL(ms)|Comment| -+---------+-------+-------+ -| test| INF| TEST| -+---------+-------+-------+ - -IoTDB> show tables details from test_db -+---------+-------+----------+-------+ -|TableName|TTL(ms)| Status|Comment| -+---------+-------+----------+-------+ -| test| INF| USING| TEST| -| turbine| INF|PRE_CREATE| null| -| car| 1000|PRE_DELETE| null| -+---------+-------+----------+-------+ -``` - -### 1.3 查看表的列 - -用于查看表的列名、数据类型、类别、状态。 - -**语法:** - -```SQL -(DESC | DESCRIBE) (DETAILS)? -``` - -**说明:** - -- 如果设置了`DETAILS`选项,系统将展示列的详细状态信息,包括: - - `USING`:表示列目前处于正常使用状态。 - - `PRE_DELETE`:表示列正在被删除或删除操作失败,该列将永久无法使用。 - -**示例:** - -```SQL -IoTDB> desc tableB -+----------+---------+-----------+-------+ -|ColumnName| DataType| Category|Comment| -+----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| a| STRING| TAG| a| -| b| STRING| ATTRIBUTE| b| -| c| INT32| FIELD| c| -+----------+---------+-----------+-------+ - -IoTDB> desc tableB details -+----------+---------+-----------+----------+-------+ -|ColumnName| DataType| Category| Status|Comment| -+----------+---------+-----------+----------+-------+ -| time|TIMESTAMP| TIME| USING| null| -| a| STRING| TAG| USING| a| -| b| STRING| ATTRIBUTE| USING| b| -| c| INT32| FIELD| USING| c| -| d| INT32| FIELD|PRE_DELETE| d| -+----------+---------+-----------+----------+-------+ -``` - -### 1.4 修改表 - -用于修改表,包括添加列、删除列以及设置表的属性。 - -**语法:** - -```SQL -ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn -// set TTL can use this -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties -| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' -| COMMENT ON COLUMN tableName.column IS 'column_comment' -``` - -**说明:** - -1. `SET PROPERTIES`操作目前仅支持对表的 TTL 属性进行配置。 -2. 删除列功能,仅支持删除属性列(ATTRIBUTE)和物理量列(FIELD),标识列(TAG)不支持删除。 -3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 - -**示例:** - -```SQL -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b' -ALTER TABLE tableB set properties TTL=3600 -COMMENT ON TABLE table1 IS 'table1' -COMMENT ON COLUMN table1.a IS null -``` - -### 1.5 删除表 - -用于删除表。 - -**语法:** - -```SQL -DROP TABLE (IF EXISTS)? -``` - -**示例:** - -```SQL -DROP TABLE tableA -DROP TABLE test.tableB -``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md index 314991c13..3c3dc8d6e 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md @@ -23,7 +23,7 @@ 在开始使用表管理功能前,推荐您先了解以下相关预备知识,以便更好地理解和应用表管理功能: * [时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md):了解时序数据的基本概念与特点,帮助建立建模基础。 -* [建模方案设计](../Background-knowledge/Data-Model-and-Terminology_timecho.md):掌握 IoTDB 时序模型及适用场景,为表管理提供设计基础。 +* [建模方案设计](../Background-knowledge/Data-Model-and-Terminology_apache.md):掌握 IoTDB 时序模型及适用场景,为表管理提供设计基础。 ## 1. 表管理 diff --git a/src/zh/UserGuide/latest-Table/QuickStart/QuickStart_apache.md b/src/zh/UserGuide/latest-Table/QuickStart/QuickStart_apache.md index f8c960ed5..bc48bde3f 100644 --- a/src/zh/UserGuide/latest-Table/QuickStart/QuickStart_apache.md +++ b/src/zh/UserGuide/latest-Table/QuickStart/QuickStart_apache.md @@ -49,9 +49,9 @@ - 建模设计介绍:[建模方案设计](../Background-knowledge/Data-Model-and-Terminology_apache.md) - - 数据库介绍:[数据库管理](../Basic-Concept/Database-Management.md) + - 数据库介绍:[数据库管理](../Basic-Concept/Database-Management_apache.md) - - 表介绍:[表管理](../Basic-Concept/Table-Management.md) + - 表介绍:[表管理](../Basic-Concept/Table-Management_apache.md) 2. 数据写入&更新:在数据写入&更新方面,IoTDB 提供了多种方式来插入实时数据,支持追加查询写回,基本介绍请查看 [数据写入&更新](../Basic-Concept/Write-Updata-Data_apache.md) @@ -60,7 +60,7 @@ 4. 数据删除:IoTDB 提供了两种删除方式,分别为SQL语句删除与过期自动删除(TTL) - SQL语句删除:基本介绍请查看 [数据删除](../Basic-Concept/Delete-Data.md) - - 过期自动删除(TTL):基本介绍请查看 [过期自动删除](../Basic-Concept/TTL-Delete-Data.md) + - 过期自动删除(TTL):基本介绍请查看 [过期自动删除](../Basic-Concept/TTL-Delete-Data_apache.md) 5. 其他进阶功能:除了数据库常见的写入、查询等功能外,IoTDB 还支持“数据同步”等功能,具体使用方法可参见具体文档: diff --git a/src/zh/UserGuide/latest-Table/QuickStart/QuickStart_timecho.md b/src/zh/UserGuide/latest-Table/QuickStart/QuickStart_timecho.md index 9cf475b17..770782da7 100644 --- a/src/zh/UserGuide/latest-Table/QuickStart/QuickStart_timecho.md +++ b/src/zh/UserGuide/latest-Table/QuickStart/QuickStart_timecho.md @@ -56,9 +56,9 @@ - 建模设计介绍:[建模方案设计](../Background-knowledge/Data-Model-and-Terminology_timecho.md) - - 数据库介绍:[数据库管理](../Basic-Concept/Database-Management.md) + - 数据库介绍:[数据库管理](../Basic-Concept/Database-Management_timecho.md) - - 表介绍:[表管理](../Basic-Concept/Table-Management.md) + - 表介绍:[表管理](../Basic-Concept/Table-Management_timecho.md) 2. 数据写入&更新:在数据写入&更新方面,IoTDB 提供了多种方式来插入实时数据,支持追加查询写回,基本介绍请查看 [数据写入&更新](../Basic-Concept/Write-Updata-Data_timecho.md) @@ -67,7 +67,7 @@ 4. 数据删除:IoTDB 提供了两种删除方式,分别为SQL语句删除与过期自动删除(TTL) - SQL语句删除:基本介绍请查看 [数据删除](../Basic-Concept/Delete-Data.md) - - 过期自动删除(TTL):基本介绍请查看 [过期自动删除](../Basic-Concept/TTL-Delete-Data.md) + - 过期自动删除(TTL):基本介绍请查看 [过期自动删除](../Basic-Concept/TTL-Delete-Data_timecho.md) 5. 其他进阶功能:除了数据库常见的写入、查询等功能外,IoTDB 还支持“数据同步”等功能,具体使用方法可参见具体文档: diff --git a/src/zh/UserGuide/latest-Table/Reference/System-Tables.md b/src/zh/UserGuide/latest-Table/Reference/System-Tables.md index 6239cd69c..c8ac85f91 100644 --- a/src/zh/UserGuide/latest-Table/Reference/System-Tables.md +++ b/src/zh/UserGuide/latest-Table/Reference/System-Tables.md @@ -1,3 +1,6 @@ +--- +redirectTo: System-Tables_apache.html +--- - -# 系统表 - -IoTDB 内置系统数据库 `INFORMATION_SCHEMA`,其中包含一系列系统表,用于存储 IoTDB 运行时信息(如当前正在执行的 SQL 语句等)。目前`INFORMATION_SCHEMA`数据库只支持读操作。 - -## 1. 系统库 - -* 名称:`INFORMATION_SCHEMA` -* 指令:只读,只支持 `Show databases (DETAILS) `​`/ Show Tables (DETAILS) / Use`,其余操作将会报错:`"The database 'information_schema' can only be queried"` -* 属性:`TTL=INF`,其余属性默认为`null` -* SQL示例: - -```sql -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show tables from information_schema -+--------------+-------+ -| TableName|TTL(ms)| -+--------------+-------+ -| columns| INF| -| config_nodes| INF| -|configurations| INF| -| data_nodes| INF| -| databases| INF| -| functions| INF| -| keywords| INF| -| models| INF| -| nodes| INF| -| pipe_plugins| INF| -| pipes| INF| -| queries| INF| -| regions| INF| -| subscriptions| INF| -| tables| INF| -| topics| INF| -| views| INF| -+--------------+-------+ -``` - -## 2. 系统表 - -* 名称:`DATABASES`, `TABLES`, `REGIONS`, `QUERIES`, `COLUMNS`, `PIPES`, `PIPE_PLUGINS`, `SUBSCRIPTION`, `TOPICS`, `VIEWS`, `MODELS`, `FUNCTIONS`, `CONFIGURATIONS`, `KEYWORDS`, `NODES`, `CONFIG_NODES`, `DATA_NODES`(详细介绍见后面小节) -* 操作:只读,只支持`SELECT`, `COUNT/SHOW DEVICES`, `DESC`,不支持对于表结构 / 内容的任意修改,如果修改将会报错:`"The database 'information_schema' can only be queried"` -* 列名:系统表的列名均默认为小写,且用`_`分隔 - -### 2.1 DATABASES 表 - -* 包含集群中所有数据库的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ----------------------------- | ---------- | ----------- | ---------------- | -| database | STRING | TAG | 数据库名称 | -| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | -| schema\_replication\_factor | INT32 | ATTRIBUTE | 元数据副本数 | -| data\_replication\_factor | INT32 | ATTRIBUTE | 数据副本数 | -| time\_partition\_interval | INT64 | ATTRIBUTE | 时间分区间隔 | -| schema\_region\_group\_num | INT32 | ATTRIBUTE | 元数据分区数量 | -| data\_region\_group\_num | INT32 | ATTRIBUTE | 数据分区数量 | - -* 查询结果只展示自身对该数据库本身或库中任意表有任意权限的数据库集合 -* 查询示例: - -```sql -IoTDB> select * from information_schema.databases -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -| database|ttl(ms)|schema_replication_factor|data_replication_factor|time_partition_interval|schema_region_group_num|data_region_group_num| -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -|information_schema| INF| null| null| null| null| null| -| database1| INF| 1| 1| 604800000| 0| 0| -+------------------+-------+-------------------------+-----------------------+-----------------------+-----------------------+---------------------+ -``` - -### 2.2 TABLES 表 - -* 包含集群中所有表的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------- | ---------- | ----------- | -------------- | -| database | STRING | TAG | 数据库名称 | -| table\_name | STRING | TAG | 表名称 | -| ttl(ms) | STRING | ATTRIBUTE | 数据保留时间 | -| status | STRING | ATTRIBUTE | 状态 | -| comment | STRING | ATTRIBUTE | 注释 | - -* 说明:status 可能为`USING`/`PRE_CREATE`/`PRE_DELETE`,具体见表管理中[查看表](../Basic-Concept/Table-Management.md#12-查看表)的相关描述 -* 查询结果只展示自身有任意权限的表集合 -* 查询示例: - -```sql -IoTDB> select * from information_schema.tables -+------------------+--------------+-----------+------+-------+-----------+ -| database| table_name| ttl(ms)|status|comment| table_type| -+------------------+--------------+-----------+------+-------+-----------+ -|information_schema| databases| INF| USING| null|SYSTEM VIEW| -|information_schema| models| INF| USING| null|SYSTEM VIEW| -|information_schema| subscriptions| INF| USING| null|SYSTEM VIEW| -|information_schema| regions| INF| USING| null|SYSTEM VIEW| -|information_schema| functions| INF| USING| null|SYSTEM VIEW| -|information_schema| keywords| INF| USING| null|SYSTEM VIEW| -|information_schema| columns| INF| USING| null|SYSTEM VIEW| -|information_schema| topics| INF| USING| null|SYSTEM VIEW| -|information_schema|configurations| INF| USING| null|SYSTEM VIEW| -|information_schema| queries| INF| USING| null|SYSTEM VIEW| -|information_schema| tables| INF| USING| null|SYSTEM VIEW| -|information_schema| pipe_plugins| INF| USING| null|SYSTEM VIEW| -|information_schema| nodes| INF| USING| null|SYSTEM VIEW| -|information_schema| data_nodes| INF| USING| null|SYSTEM VIEW| -|information_schema| pipes| INF| USING| null|SYSTEM VIEW| -|information_schema| views| INF| USING| null|SYSTEM VIEW| -|information_schema| config_nodes| INF| USING| null|SYSTEM VIEW| -| database1| table1|31536000000| USING| null| BASE TABLE| -+------------------+--------------+-----------+------+-------+-----------+ -``` - -### 2.3 REGIONS 表 - -* 包含集群中所有`Region`的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| --------------------- | ----------- | ----------- | ----------------------------------------------------------------------------------------------------------- | -| region\_id | INT32 | TAG | region ID | -| datanode\_id | INT32 | TAG | dataNode ID | -| type | STRING | ATTRIBUTE | 类型(SchemaRegion / DataRegion) | -| status | STRING | ATTRIBUTE | 状态(Running/Unknown 等) | -| database | STRING | ATTRIBUTE | database 名字 | -| series\_slot\_num | INT32 | ATTRIBUTE | series slot 个数 | -| time\_slot\_num | INT64 | ATTRIBUTE | time slot 个数 | -| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | -| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | -| internal\_address | STRING | ATTRIBUTE | 内部通讯地址 | -| role | STRING | ATTRIBUTE | Leader / Follower | -| create\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | -| tsfile\_size\_bytes | INT64 | ATTRIBUTE | 可统计的 DataRegion:含有 TsFile 的总文件大小;不可统计的 DataRegion(Unknown):-1;SchemaRegion:null; | - -* 仅管理员可执行查询操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.regions -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -|region_id|datanode_id| type| status| database|series_slot_num|time_slot_num|rpc_address|rpc_port|internal_address| role| create_time|tsfile_size_bytes| -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -| 0| 1|SchemaRegion|Running|database1| 12| 0| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:08.485+08:00| null| -| 1| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3985| -| 2| 1| DataRegion|Running|database1| 6| 6| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-03-31T11:19:09.156+08:00| 3841| -+---------+-----------+------------+-------+---------+---------------+-------------+-----------+--------+----------------+------+-----------------------------+-----------------+ -``` - -### 2.4 QUERIES 表 - -* 包含集群中所有正在执行的查询的信息。也可以使用 `SHOW QUERIES`语法去查询。 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| --------------- | ----------- | ----------- | ------------------------------------------------ | -| query\_id | STRING | TAG | ID | -| start\_time | TIMESTAMP | ATTRIBUTE | 查询开始的时间戳,时间戳精度与系统精度保持一致 | -| datanode\_id | INT32 | ATTRIBUTE | 发起查询的DataNode ID | -| elapsed\_time | FLOAT | ATTRIBUTE | 查询执行耗时,单位是秒 | -| statement | STRING | ATTRIBUTE | 查询sql | -| user | STRING | ATTRIBUTE | 发起查询的用户 | - -* 普通用户查询结果仅显示自身执行的查询;管理员显示全部。 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.queries -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -| query_id| start_time|datanode_id|elapsed_time| statement|user| -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -|20250331_023242_00011_1|2025-03-31T10:32:42.360+08:00| 1| 0.025|select * from information_schema.queries|root| -+-----------------------+-----------------------------+-----------+------------+----------------------------------------+----+ -``` - -### 2.5 COLUMNS 表 - -* 包含集群中所有表中列的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| -------------- | ---------- | ----------- | -------------- | -| database | STRING | TAG | 数据库名称 | -| table\_name | STRING | TAG | 表名称 | -| column\_name | STRING | TAG | 列名称 | -| datatype | STRING | ATTRIBUTE | 列的数值类型 | -| category | STRING | ATTRIBUTE | 列类型 | -| status | STRING | ATTRIBUTE | 列状态 | -| comment | STRING | ATTRIBUTE | 列注释 | - -说明: -* status 可能为`USING`/`PRE_DELETE`,具体见表管理中[查看表的列](../Basic-Concept/Table-Management.html#13-查看表的列)的相关描述 -* 查询结果只展示自身有任意权限的表的列信息 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.columns where database = 'database1' -+---------+----------+------------+---------+---------+------+-------+ -| database|table_name| column_name| datatype| category|status|comment| -+---------+----------+------------+---------+---------+------+-------+ -|database1| table1| time|TIMESTAMP| TIME| USING| null| -|database1| table1| region| STRING| TAG| USING| null| -|database1| table1| plant_id| STRING| TAG| USING| null| -|database1| table1| device_id| STRING| TAG| USING| null| -|database1| table1| model_id| STRING|ATTRIBUTE| USING| null| -|database1| table1| maintenance| STRING|ATTRIBUTE| USING| null| -|database1| table1| temperature| FLOAT| FIELD| USING| null| -|database1| table1| humidity| FLOAT| FIELD| USING| null| -|database1| table1| status| BOOLEAN| FIELD| USING| null| -|database1| table1|arrival_time|TIMESTAMP| FIELD| USING| null| -+---------+----------+------------+---------+---------+------+-------+ -``` - -### 2.6 PIPES 表 - -* 包含集群中所有 PIPE 的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------------------- | ----------- | ----------- | --------------------------------------- | -| id | STRING | TAG | Pipe 名称 | -| creation\_time | TIMESTAMP | ATTRIBUTE | 创建时间 | -| state | STRING | ATTRIBUTE | Pipe 状态(RUNNING/STOPPED) | -| pipe\_source | STRING | ATTRIBUTE | source 插件参数 | -| pipe\_processor | STRING | ATTRIBUTE | processor 插件参数 | -| pipe\_sink | STRING | ATTRIBUTE | source 插件参数 | -| exception\_message | STRING | ATTRIBUTE | Exception 信息 | -| remaining\_event\_count | INT64 | ATTRIBUTE | 剩余 event 数量,如果 Unknown 则为 -1 | -| estimated\_remaining\_seconds | DOUBLE | ATTRIBUTE | 预估剩余时间,如果 Unknown 则为 -1 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -select * from information_schema.pipes -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -| id| creation_time| state| pipe_source|pipe_processor| pipe_sink|exception_message|remaining_event_count|estimated_remaining_seconds| -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -|tablepipe1|2025-03-31T12:25:24.040+08:00|RUNNING|{__system.sql-dialect=table, source.password=******, source.username=root}| {}|{format=hybrid, node-urls=192.168.xxx.xxx:6667, sink=iotdb-thrift-sink}| | 0| 0.0| -+----------+-----------------------------+-------+--------------------------------------------------------------------------+--------------+-----------------------------------------------------------------------+-----------------+---------------------+---------------------------+ -``` - -### 2.7 PIPE\_PLUGINS 表 - -* 包含集群中所有PIPE插件的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| -------------- | ---------- | ----------- | ----------------------------------------------- | -| plugin\_name | STRING | TAG | 插件名称 | -| plugin\_type | STRING | ATTRIBUTE | 插件类型(Builtin/External) | -| class\_name | STRING | ATTRIBUTE | 插件的主类名 | -| plugin\_jar | STRING | ATTRIBUTE | 插件的 jar 包名称,若为 builtin 类型则为 null | - -* 查询示例: - -```SQL -IoTDB> select * from information_schema.pipe_plugins -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -| plugin_name|plugin_type| class_name|plugin_jar| -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| null| -| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| null| -| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.donothing.DoNothingConnector| null| -| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.processor.donothing.DoNothingProcessor| null| -| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| null| -| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.agent.plugin.builtin.extractor.iotdb.IoTDBExtractor| null| -+---------------------+-----------+-------------------------------------------------------------------------------------------------+----------+ -``` - -### 2.8 SUBSCRIPTIONS 表 - -* 包含集群中所有数据订阅的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ----------------------- | ---------- | ----------- | -------------- | -| topic\_name | STRING | TAG | 订阅主题名称 | -| consumer\_group\_name | STRING | TAG | 消费者组名称 | -| subscribed\_consumers | STRING | ATTRIBUTE | 订阅的消费者 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.subscriptions where topic_name = 'topic_1' -+----------+-------------------+--------------------------------+ -|topic_name|consumer_group_name| subscribed_consumers| -+----------+-------------------+--------------------------------+ -| topic_1| cg1|[c3, c4, c5, c6, c7, c0, c1, c2]| -+----------+-------------------+--------------------------------+ -``` - -### 2.9 TOPICS 表 - -* 包含集群中所有数据订阅主题的信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ---------------- | ---------- | ----------- | -------------- | -| topic\_name | STRING | TAG | 订阅主题名称 | -| topic\_configs | STRING | ATTRIBUTE | 订阅主题配置 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.topics -+----------+----------------------------------------------------------------+ -|topic_name| topic_configs| -+----------+----------------------------------------------------------------+ -| topic|{__system.sql-dialect=table, start-time=2025-01-10T17:05:38.282}| -+----------+----------------------------------------------------------------+ -``` - -### 2.10 VIEWS 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的表视图信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------ | ---------- | ----------- | ---------------- | -| database | STRING | TAG | 数据库名称 | -| table\_name | STRING | TAG | 视图名称 | -| view\_definition | STRING | ATTRIBUTE | 视图的创建语句 | - -* 查询结果只展示自身有任意权限的视图集合 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.views -+---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ -| database|table_name| view_definition| -+---------+----------+---------------------------------------------------------------------------------------------------------------------------------------+ -|database1| ln|CREATE VIEW "ln" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) WITH (ttl='INF') AS root.ln.**| -+---------+----------+--------------------------------------------------------------------------------------------------------------------------------------- -``` - -### 2.11 MODELS 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的模型信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------- | ---------- | ----------- | ----------------------------------------------------------------------- | -| model\_id | STRING | TAG | 模型名称 | -| model\_type | STRING | ATTRIBUTE | 模型类型(预测,异常检测,自定义) | -| state | STRING | ATTRIBUTE | 模型状态(是否可用) | -| configs | STRING | ATTRIBUTE | 模型的超参数的 string 格式,与正常的 show 相同 | -| notes | STRING | ATTRIBUTE | 模型注释* 内置 model:Built-in model in IoTDB* 用户的 model:自定义 | - -* 查询示例: - -```SQL --- 找到类型为内置预测的所有模型 -IoTDB> select * from information_schema.models where model_type = 'BUILT_IN_FORECAST' -+---------------------+-----------------+------+-------+-----------------------+ -| model_id| model_type| state|configs| notes| -+---------------------+-----------------+------+-------+-----------------------+ -| _STLForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _NaiveForecaster|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _ARIMA|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -|_ExponentialSmoothing|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _HoltWinters|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -| _sundial|BUILT_IN_FORECAST|ACTIVE| null|Built-in model in IoTDB| -+---------------------+-----------------+------+-------+-----------------------+ -``` - -### 2.12 FUNCTIONS 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的函数信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------ | ---------- | ----------- | ----------------------------------------- | -| function\_name | STRING | TAG | 函数名称 | -| function\_type | STRING | ATTRIBUTE | 函数类型(内/外置数值/聚合/表函数) | -| class\_name(udf) | STRING | ATTRIBUTE | 如为 UDF,则为类名,否则为 null(暂定) | -| state | STRING | ATTRIBUTE | 是否可用 | - -* 查询示例: - -```SQL -IoTDB> select * from information_schema.functions where function_type='built-in table function' -+--------------+-----------------------+---------------+---------+ -|function_table| function_type|class_name(udf)| state| -+--------------+-----------------------+---------------+---------+ -| CUMULATE|built-in table function| null|AVAILABLE| -| SESSION|built-in table function| null|AVAILABLE| -| HOP|built-in table function| null|AVAILABLE| -| TUMBLE|built-in table function| null|AVAILABLE| -| FORECAST|built-in table function| null|AVAILABLE| -| VARIATION|built-in table function| null|AVAILABLE| -| CAPACITY|built-in table function| null|AVAILABLE| -+--------------+-----------------------+---------------+---------+ -``` - -### 2.13 CONFIGURATIONS表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的属性信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ---------- | ---------- | ----------- | -------- | -| variable | STRING | TAG | 属性名 | -| value | STRING | ATTRIBUTE | 属性值 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.configurations -+----------------------------------+-----------------------------------------------------------------+ -| variable| value| -+----------------------------------+-----------------------------------------------------------------+ -| ClusterName| defaultCluster| -| DataReplicationFactor| 1| -| SchemaReplicationFactor| 1| -| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| -|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| TimePartitionOrigin| 0| -| TimePartitionInterval| 604800000| -| ReadConsistencyLevel| strong| -| SchemaRegionPerDataNode| 1| -| DataRegionPerDataNode| 0| -| SeriesSlotNum| 1000| -| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| -| DiskSpaceWarningThreshold| 0.05| -| TimestampPrecision| ms| -+----------------------------------+-----------------------------------------------------------------+ -``` - -### 2.14 KEYWORDS 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的关键字信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ---------- | ---------- | ----------- | -------------------------------- | -| word | STRING | TAG | 关键字 | -| reserved | INT32 | ATTRIBUTE | 是否为保留字,1表示是,0表示否 | - -* 查询示例: - -```SQL -IoTDB> select * from information_schema.keywords limit 10 -+----------+--------+ -| word|reserved| -+----------+--------+ -| ABSENT| 0| -|ACTIVATION| 1| -| ACTIVATE| 1| -| ADD| 0| -| ADMIN| 0| -| AFTER| 0| -| AINODES| 1| -| ALL| 0| -| ALTER| 1| -| ANALYZE| 0| -+----------+--------+ -``` - -### 2.15 NODES 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的节点信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------------------ | ---------- | ----------- | --------------- | -| node\_id | INT32 | TAG | 节点 ID | -| node\_type | STRING | ATTRIBUTE | 节点类型 | -| status | STRING | ATTRIBUTE | 节点状态 | -| internal\_address | STRING | ATTRIBUTE | 内部 rpc 地址 | -| internal\_port | INT32 | ATTRIBUTE | 内部端口 | -| version | STRING | ATTRIBUTE | 版本号 | -| build\_info | STRING | ATTRIBUTE | CommitID | -| activate\_status(仅企业版) | STRING | ATTRIBUTE | 激活状态 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.nodes -+-------+----------+-------+----------------+-------------+-------+----------+ -|node_id| node_type| status|internal_address|internal_port|version|build_info| -+-------+----------+-------+----------------+-------------+-------+----------+ -| 0|ConfigNode|Running| 127.0.0.1| 10710|2.0.5.1| 58d685e| -| 1| DataNode|Running| 127.0.0.1| 10730|2.0.5.1| 58d685e| -+-------+----------+-------+----------------+-------------+-------+----------+ -+----------+--------+ -``` - -### 2.16 CONFIG\_NODES 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的配置节点信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------------- | ---------- | ----------- | --------------------- | -| node\_id | INT32 | TAG | 节点 ID | -| config\_consensus\_port | INT32 | ATTRIBUTE | configNode 共识端口 | -| role | STRING | ATTRIBUTE | configNode 节点角色 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.config_nodes -+-------+---------------------+------+ -|node_id|config_consensus_port| role| -+-------+---------------------+------+ -| 0| 10720|Leader| -+-------+---------------------+------+ -``` - -### 2.17 DATA\_NODES 表 - -> 该系统表从 V 2.0.5 版本开始提供 - -* 包含数据库内所有的数据节点信息 -* 表结构如下表所示: - -| 列名 | 数据类型 | 列类型 | 说明 | -| ------------------------ | ---------- | ----------- | ----------------------- | -| node\_id | INT32 | TAG | 节点 ID | -| data\_region\_num | INT32 | ATTRIBUTE | DataRegion 数量 | -| schema\_region\_num | INT32 | ATTRIBUTE | SchemaRegion 数量 | -| rpc\_address | STRING | ATTRIBUTE | Rpc 地址 | -| rpc\_port | INT32 | ATTRIBUTE | Rpc 端口 | -| mpp\_port | INT32 | ATTRIBUTE | MPP 通信端口 | -| data\_consensus\_port | INT32 | ATTRIBUTE | DataRegion 共识端口 | -| scema\_consensus\_port | INT32 | ATTRIBUTE | SchemaRegion 共识端口 | - -* 仅管理员可执行操作 -* 查询示例: - -```SQL -IoTDB> select * from information_schema.data_nodes -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -|node_id|data_region_num|schema_region_num|rpc_address|rpc_port|mpp_port|data_consensus_port|schema_consensus_port| -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -| 1| 4| 4| 0.0.0.0| 6667| 10740| 10760| 10750| -+-------+---------------+-----------------+-----------+--------+--------+-------------------+---------------------+ -``` - -## 3. 权限说明 - -* 不支持通过`GRANT/REVOKE`语句对 `information_schema` 数据库及其下任何表进行权限操作 -* 支持任意用户通过`show databases`语句查看`information_schema`数据库相关信息 -* 支持任意用户通过`show tables from information_schema` 语句查看所有系统表相关信息 -* 支持任意用户通过`desc`语句查看任意系统表 diff --git a/src/zh/UserGuide/latest-Table/Reference/System-Tables_apache.md b/src/zh/UserGuide/latest-Table/Reference/System-Tables_apache.md index 6239cd69c..e0c594dc4 100644 --- a/src/zh/UserGuide/latest-Table/Reference/System-Tables_apache.md +++ b/src/zh/UserGuide/latest-Table/Reference/System-Tables_apache.md @@ -109,7 +109,7 @@ IoTDB> select * from information_schema.databases | status | STRING | ATTRIBUTE | 状态 | | comment | STRING | ATTRIBUTE | 注释 | -* 说明:status 可能为`USING`/`PRE_CREATE`/`PRE_DELETE`,具体见表管理中[查看表](../Basic-Concept/Table-Management.md#12-查看表)的相关描述 +* 说明:status 可能为`USING`/`PRE_CREATE`/`PRE_DELETE`,具体见表管理中[查看表](../Basic-Concept/Table-Management_apache.md#12-查看表)的相关描述 * 查询结果只展示自身有任意权限的表集合 * 查询示例: @@ -216,7 +216,7 @@ IoTDB> select * from information_schema.queries | comment | STRING | ATTRIBUTE | 列注释 | 说明: -* status 可能为`USING`/`PRE_DELETE`,具体见表管理中[查看表的列](../Basic-Concept/Table-Management.html#13-查看表的列)的相关描述 +* status 可能为`USING`/`PRE_DELETE`,具体见表管理中[查看表的列](../Basic-Concept/Table-Management_apache.md#13-查看表的列)的相关描述 * 查询结果只展示自身有任意权限的表的列信息 * 查询示例: diff --git a/src/zh/UserGuide/latest-Table/Reference/System-Tables_timecho.md b/src/zh/UserGuide/latest-Table/Reference/System-Tables_timecho.md index 6239cd69c..f0f2fec5b 100644 --- a/src/zh/UserGuide/latest-Table/Reference/System-Tables_timecho.md +++ b/src/zh/UserGuide/latest-Table/Reference/System-Tables_timecho.md @@ -109,7 +109,7 @@ IoTDB> select * from information_schema.databases | status | STRING | ATTRIBUTE | 状态 | | comment | STRING | ATTRIBUTE | 注释 | -* 说明:status 可能为`USING`/`PRE_CREATE`/`PRE_DELETE`,具体见表管理中[查看表](../Basic-Concept/Table-Management.md#12-查看表)的相关描述 +* 说明:status 可能为`USING`/`PRE_CREATE`/`PRE_DELETE`,具体见表管理中[查看表](../Basic-Concept/Table-Management_timecho.md#12-查看表)的相关描述 * 查询结果只展示自身有任意权限的表集合 * 查询示例: @@ -216,7 +216,7 @@ IoTDB> select * from information_schema.queries | comment | STRING | ATTRIBUTE | 列注释 | 说明: -* status 可能为`USING`/`PRE_DELETE`,具体见表管理中[查看表的列](../Basic-Concept/Table-Management.html#13-查看表的列)的相关描述 +* status 可能为`USING`/`PRE_DELETE`,具体见表管理中[查看表的列](../Basic-Concept/Table-Management_timecho.md#13-查看表的列)的相关描述 * 查询结果只展示自身有任意权限的表的列信息 * 查询示例: diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations.md b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations.md index 1831e8557..6821d5dda 100644 --- a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations.md +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations.md @@ -1,3 +1,6 @@ +--- +redirectTo: SQL-Metadata-Operations_apache.html +--- - -# 元数据操作 - -## 1. 数据库管理 - -### 1.1 创建数据库 - -**语法:** - -```SQL -CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? -``` - -更多详细语法说明请参考:[创建数据库](../Basic-Concept/Database-Management.md#_1-1-创建数据库) - -**示例:** - -```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - --- 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 -CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); -``` - -### 1.2 使用数据库 - -**语法:** - -```SQL -USE -``` - -**示例:** - -```SQL -USE database1 -``` - -### 1.3 查看当前数据库 - -**语法:** - -```SQL -SHOW CURRENT_DATABASE -``` - -**示例:** - -```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE test; - -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| iot_database| -+---------------+ -``` - -### 1.4 查看所有数据库 - -**语法:** - -```SQL -SHOW DATABASES (DETAILS)? -``` - -更多返回结果详细说明请参考:[查看所有数据库](../Basic-Concept/Database-Management.md#_1-4-查看所有数据库) - -**示例:** - -```SQL -IoTDB> show databases -+---------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+---------+-------+-----------------------+---------------------+---------------------+ -|test_prop| 300| 3| 2| 100000| -| test2| 300| 3| 2| 604800000| -+---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -|test_prop| 300| 3| 2| 100000| 1| 2| -| test2| 300| 3| 2| 604800000| 1| 2| -+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ -``` - -### 1.5 修改数据库 - -**语法:** - -```SQL -ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments -``` - -**示例:** - -```SQL -ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; -``` - -### 1.6 删除数据库 - -**语法:** - -```SQL -DROP DATABASE (IF EXISTS)? -``` - -**示例:** - -```SQL -DROP DATABASE IF EXISTS database1 -``` - -## 2. 表管理 - -### 2.1 创建表 - -**语法:** - -```SQL -createTableStatement - : CREATE TABLE (IF NOT EXISTS)? qualifiedName - '(' (columnDefinition (',' columnDefinition)*)? ')' - charsetDesc? - comment? - (WITH properties)? - ; - -charsetDesc - : DEFAULT? (CHAR SET | CHARSET | CHARACTER SET) EQ? identifierOrString - ; - -columnDefinition - : identifier columnCategory=(TAG | ATTRIBUTE | TIME) charsetName? comment? - | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? charsetName? comment? - ; - -charsetName - : CHAR SET identifier - | CHARSET identifier - | CHARACTER SET identifier - ; - -comment - : COMMENT string - ; -``` - -更多详细语法说明请参考:[创建表](../Basic-Concept/Table-Management.md#_1-1-创建表) - -**示例:** - -```SQL -CREATE TABLE table1 ( - time TIMESTAMP TIME, - region STRING TAG, - plant_id STRING TAG, - device_id STRING TAG, - model_id STRING ATTRIBUTE, - maintenance STRING ATTRIBUTE COMMENT 'maintenance', - temperature FLOAT FIELD COMMENT 'temperature', - humidity FLOAT FIELD COMMENT 'humidity', - status Boolean FIELD COMMENT 'status', - arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' -) COMMENT 'table1' WITH (TTL=31536000000); - -CREATE TABLE if not exists table2 (); - -CREATE TABLE tableC ( - "场站" STRING TAG, - "温度" int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); -``` - -### 2.2 查看表 - -**语法:** - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -**示例:** - -```SQL -IoTDB> show tables from test_db -+---------+-------+-------+ -|TableName|TTL(ms)|Comment| -+---------+-------+-------+ -| test| INF| TEST| -+---------+-------+-------+ - -IoTDB> show tables details from test_db -+---------+-------+----------+-------+ -|TableName|TTL(ms)| Status|Comment| -+---------+-------+----------+-------+ -| test| INF| USING| TEST| -| turbine| INF|PRE_CREATE| null| -| car| 1000|PRE_DELETE| null| -+---------+-------+----------+-------+ -``` - -### 2.3 查看表的列 - -**语法:** - -```SQL -(DESC | DESCRIBE) (DETAILS)? -``` - -**示例:** - -```SQL -IoTDB> desc tableB -+----------+---------+-----------+-------+ -|ColumnName| DataType| Category|Comment| -+----------+---------+-----------+-------+ -| time|TIMESTAMP| TIME| null| -| a| STRING| TAG| a| -| b| STRING| ATTRIBUTE| b| -| c| INT32| FIELD| c| -+----------+---------+-----------+-------+ - -IoTDB> desc tableB details -+----------+---------+-----------+----------+-------+ -|ColumnName| DataType| Category| Status|Comment| -+----------+---------+-----------+----------+-------+ -| time|TIMESTAMP| TIME| USING| null| -| a| STRING| TAG| USING| a| -| b| STRING| ATTRIBUTE| USING| b| -| c| INT32| FIELD| USING| c| -| d| INT32| FIELD|PRE_DELETE| d| -+----------+---------+-----------+----------+-------+ -``` - -### 2.4 修改表 - -**语法:** - -```SQL -ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition COMMENT 'column_comment' #addColumn -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn -// set TTL can use this -| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties -| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment' -| COMMENT ON COLUMN tableName.column IS 'column_comment' -``` - -**示例:** - -```SQL -ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a' -ALTER TABLE tableB set properties TTL=3600 -COMMENT ON TABLE table1 IS 'table1' -COMMENT ON COLUMN table1.a IS null -``` - -### 2.5 删除表 - -**语法:** - -```SQL -DROP TABLE (IF EXISTS)? -``` - -**示例:** - -```SQL -DROP TABLE tableA -DROP TABLE test.tableB -``` - - diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md index 1831e8557..638e001de 100644 --- a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md @@ -31,7 +31,7 @@ CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? ``` -更多详细语法说明请参考:[创建数据库](../Basic-Concept/Database-Management.md#_1-1-创建数据库) +更多详细语法说明请参考:[创建数据库](../Basic-Concept/Database-Management_apache.md#_1-1-创建数据库) **示例:** @@ -93,7 +93,7 @@ IoTDB> SHOW CURRENT_DATABASE; SHOW DATABASES (DETAILS)? ``` -更多返回结果详细说明请参考:[查看所有数据库](../Basic-Concept/Database-Management.md#_1-4-查看所有数据库) +更多返回结果详细说明请参考:[查看所有数据库](../Basic-Concept/Database-Management_apache.md#_1-4-查看所有数据库) **示例:** @@ -177,7 +177,7 @@ comment ; ``` -更多详细语法说明请参考:[创建表](../Basic-Concept/Table-Management.md#_1-1-创建表) +更多详细语法说明请参考:[创建表](../Basic-Concept/Table-Management_apache.md#_1-1-创建表) **示例:** diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md index 1831e8557..5a612565a 100644 --- a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md @@ -31,7 +31,7 @@ CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? ``` -更多详细语法说明请参考:[创建数据库](../Basic-Concept/Database-Management.md#_1-1-创建数据库) +更多详细语法说明请参考:[创建数据库](../Basic-Concept/Database-Management_timecho.md#_1-1-创建数据库) **示例:** @@ -93,7 +93,7 @@ IoTDB> SHOW CURRENT_DATABASE; SHOW DATABASES (DETAILS)? ``` -更多返回结果详细说明请参考:[查看所有数据库](../Basic-Concept/Database-Management.md#_1-4-查看所有数据库) +更多返回结果详细说明请参考:[查看所有数据库](../Basic-Concept/Database-Management_timecho.md#_1-4-查看所有数据库) **示例:** @@ -177,7 +177,7 @@ comment ; ``` -更多详细语法说明请参考:[创建表](../Basic-Concept/Table-Management.md#_1-1-创建表) +更多详细语法说明请参考:[创建表](../Basic-Concept/Table-Management_timecho.md#_1-1-创建表) **示例:** diff --git a/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement.md b/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement.md index 99b6e36e5..30e0f15bc 100644 --- a/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement.md +++ b/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement.md @@ -1,3 +1,6 @@ +--- +redirectTo: Maintenance-statement_apache.html +--- -# 运维语句 - -## 1. 状态查看 - -### 1.1 查看连接的模型 - -**含义**:返回当前连接的 sql_dialect 是树模型/表模型。 - -#### 语法: - -```SQL -showCurrentSqlDialectStatement - : SHOW CURRENT_SQL_DIALECT - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW CURRENT_SQL_DIALECT -``` - -执行结果如下: - -```SQL -+-----------------+ -|CurrentSqlDialect| -+-----------------+ -| TABLE| -+-----------------+ -``` -### 1.2 查看登录的用户名 - -**含义**:返回当前登录的用户名。 - -#### 语法: - -```SQL -showCurrentUserStatement - : SHOW CURRENT_USER - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW CURRENT_USER -``` - -执行结果如下: - -```SQL -+-----------+ -|CurrentUser| -+-----------+ -| root| -+-----------+ -``` - -### 1.3 查看连接的数据库名 - -**含义**:返回当前连接的数据库名,若没有执行过 use 语句,则为 null。 - -#### 语法: - -```SQL -showCurrentDatabaseStatement - : SHOW CURRENT_DATABASE - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW CURRENT_DATABASE; - -IoTDB> USE test; - -IoTDB> SHOW CURRENT_DATABASE; -``` - -执行结果如下: - -```SQL -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -+---------------+ -|CurrentDatabase| -+---------------+ -| test| -+---------------+ -``` - -### 1.4 查看集群版本 - -**含义**:返回当前集群的版本。 - -#### 语法: - -```SQL -showVersionStatement - : SHOW VERSION - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW VERSION -``` - -执行结果如下: - -```SQL -+-------+---------+ -|Version|BuildInfo| -+-------+---------+ -|2.0.1.2| 1ca4008| -+-------+---------+ -``` - -### 1.5 查看集群关键参数 - -**含义**:返回当前集群的关键参数。 - -#### 语法: - -```SQL -showVariablesStatement - : SHOW VARIABLES - ; -``` - -关键参数如下: - -1. **ClusterName**:当前集群的名称。 -2. **DataReplicationFactor**:数据副本的数量,表示每个数据分区(DataRegion)的副本数。 -3. **SchemaReplicationFactor**:元数据副本的数量,表示每个元数据分区(SchemaRegion)的副本数。 -4. **DataRegionConsensusProtocolClass**:数据分区(DataRegion)使用的共识协议类。 -5. **SchemaRegionConsensusProtocolClass**:元数据分区(SchemaRegion)使用的共识协议类。 -6. **ConfigNodeConsensusProtocolClass**:配置节点(ConfigNode)使用的共识协议类。 -7. **TimePartitionOrigin**:数据库时间分区的起始时间戳。 -8. **TimePartitionInterval**:数据库的时间分区间隔(单位:毫秒)。 -9. **ReadConsistencyLevel**:读取操作的一致性级别。 -10. **SchemaRegionPerDataNode**:数据节点(DataNode)上的元数据分区(SchemaRegion)数量。 -11. **DataRegionPerDataNode**:数据节点(DataNode)上的数据分区(DataRegion)数量。 -12. **SeriesSlotNum**:数据分区(DataRegion)的序列槽(SeriesSlot)数量。 -13. **SeriesSlotExecutorClass**:序列槽的实现类。 -14. **DiskSpaceWarningThreshold**:磁盘空间告警阈值(单位:百分比)。 -15. **TimestampPrecision**:时间戳精度。 - -#### 示例: - -```SQL -IoTDB> SHOW VARIABLES -``` - -执行结果如下: - -```SQL -+----------------------------------+-----------------------------------------------------------------+ -| Variable| Value| -+----------------------------------+-----------------------------------------------------------------+ -| ClusterName| defaultCluster| -| DataReplicationFactor| 1| -| SchemaReplicationFactor| 1| -| DataRegionConsensusProtocolClass| org.apache.iotdb.consensus.iot.IoTConsensus| -|SchemaRegionConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| ConfigNodeConsensusProtocolClass| org.apache.iotdb.consensus.ratis.RatisConsensus| -| TimePartitionOrigin| 0| -| TimePartitionInterval| 604800000| -| ReadConsistencyLevel| strong| -| SchemaRegionPerDataNode| 1| -| DataRegionPerDataNode| 0| -| SeriesSlotNum| 1000| -| SeriesSlotExecutorClass|org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor| -| DiskSpaceWarningThreshold| 0.05| -| TimestampPrecision| ms| -+----------------------------------+-----------------------------------------------------------------+ -``` - -### 1.6 查看集群ID - -**含义**:返回当前集群的ID。 - -#### 语法: - -```SQL -showClusterIdStatement - : SHOW (CLUSTERID | CLUSTER_ID) - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW CLUSTER_ID -``` - -执行结果如下: - -```SQL -+------------------------------------+ -| ClusterId| -+------------------------------------+ -|40163007-9ec1-4455-aa36-8055d740fcda| -``` - -### 1.7 查看客户端直连的 DataNode 进程所在服务器的时间 - -#### 语法: - -**含义**:返回当前客户端直连的 DataNode 进程所在服务器的时间。 - -```SQL -showCurrentTimestampStatement - : SHOW CURRENT_TIMESTAMP - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW CURRENT_TIMESTAMP -``` - -执行结果如下: - -```SQL -+-----------------------------+ -| CurrentTimestamp| -+-----------------------------+ -|2025-02-17T11:11:52.987+08:00| -+-----------------------------+ -``` - -### 1.8 查看正在执行的查询信息 - -**含义**:用于显示所有正在执行的查询信息。 - -> 更多系统表使用方法请参考[系统表](../Reference/System-Tables.md) - -#### 语法: - -```SQL -showQueriesStatement - : SHOW (QUERIES | QUERY PROCESSLIST) - (WHERE where=booleanExpression)? - (ORDER BY sortItem (',' sortItem)*)? - limitOffsetClause - ; -``` - -**参数解释**: - -1. **WHERE** 子句:需保证过滤的目标列是结果集中存在的列 -2. **ORDER BY** 子句:需保证`sortKey`是结果集中存在的列 -3. **limitOffsetClause**: - - **含义**:用于限制结果集的返回数量。 - - **格式**:`LIMIT , `, `` 是偏移量,`` 是返回的行数。 -4. **QUERIES** 表中的列: - - **query_id**:查询语句的 ID - - **start_time**:查询开始的时间戳,时间戳精度与系统精度一致 - - **datanode_id**:发起查询语句的 DataNode 的ID - - **elapsed_time**:查询的执行耗时,单位是秒 - - **statement**:查询的 SQL 语句 - - **user**:发起查询的用户 - -#### 示例: - -```SQL -IoTDB> SHOW QUERIES WHERE elapsed_time > 30 -``` - -执行结果如下: - -```SQL -+-----------------------+-----------------------------+-----------+------------+------------+----+ -| query_id| start_time|datanode_id|elapsed_time| statement|user| -+-----------------------+-----------------------------+-----------+------------+------------+----+ -|20250108_101015_00000_1|2025-01-08T18:10:15.935+08:00| 1| 32.283|show queries|root| -+-----------------------+-----------------------------+-----------+------------+------------+----+ -``` - -### 1.9 查看分区信息 - -**含义**:返回当前集群的分区信息。 - -#### 语法: - -```SQL -showRegionsStatement - : SHOW REGIONS - ; -``` - -#### 示例: - -```SQL -IoTDB> SHOW REGIONS -``` - -执行结果如下: - -```SQL -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -|RegionId| Type| Status| Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime|TsFileSize| -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -| 6|SchemaRegion|Running|tcollector| 670| 0| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.194| | -| 7| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.196| 169.85 KB| -| 8| DataRegion|Running|tcollector| 335| 335| 1| 0.0.0.0| 6667| 127.0.0.1|Leader|2025-08-01T17:37:01.198| 161.63 KB| -+--------+------------+-------+----------+-------------+-----------+----------+----------+-------+---------------+------+-----------------------+----------+ -``` - - -## 2. 状态设置 - -### 2.1 设置连接的模型 - -**含义**:将当前连接的 sql_dialect 置为树模型/表模型,在树模型和表模型中均可使用该命令。 - -#### 语法: - -```SQL -SET SQL_DIALECT EQ (TABLE | TREE) -``` - -#### 示例: - -```SQL -IoTDB> SET SQL_DIALECT=TABLE -IoTDB> SHOW CURRENT_SQL_DIALECT -``` - -执行结果如下: - -```SQL -+-----------------+ -|CurrentSqlDialect| -+-----------------+ -| TABLE| -+-----------------+ -``` - -### 2.2 更新配置项 - -**含义**:用于更新配置项,执行完成后会进行配置项的热加载,对于支持热修改的配置项会立即生效。 - -#### 语法: - -```SQL -setConfigurationStatement - : SET CONFIGURATION propertyAssignments (ON INTEGER_VALUE)? - ; - -propertyAssignments - : property (',' property)* - ; - -property - : identifier EQ propertyValue - ; - -propertyValue - : DEFAULT - | expression - ; -``` - -**参数解释**: - -1. **propertyAssignments** - - **含义**:更新的配置列表,由多个 `property` 组成。 - - 可以更新多个配置列表,用逗号分隔。 - - **取值**: - - `DEFAULT`:将配置项恢复为默认值。 - - `expression`:具体的值,必须是一个字符串。 -2. **ON INTEGER_VALUE** - - **含义**:指定要更新配置的节点 ID。 - - **可选性**:可选。如果不指定或指定的值低于 0,则更新所有 ConfigNode 和 DataNode 的配置。 - -#### 示例: - -```SQL -IoTDB> SET CONFIGURATION disk_space_warning_threshold='0.05',heartbeat_interval_in_ms='1000' ON 1; -``` - -### 2.3 读取手动修改的配置文件 - -**含义**:用于读取手动修改过的配置文件,并对配置项进行热加载,对于支持热修改的配置项会立即生效。 - -#### 语法: - -```SQL -loadConfigurationStatement - : LOAD CONFIGURATION localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **localOrClusterMode** - - **含义**:指定配置热加载的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `LOCAL`:只对客户端直连的 DataNode 进行配置热加载。 - - `CLUSTER`:对集群中所有 DataNode 进行配置热加载。 - -#### 示例: - -```SQL -IoTDB> LOAD CONFIGURATION ON LOCAL; -``` - -### 2.4 设置系统的状态 - -**含义**:用于设置系统的状态。 - -#### 语法: - -```SQL -setSystemStatusStatement - : SET SYSTEM TO (READONLY | RUNNING) localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **RUNNING | READONLY** - - **含义**:指定系统的新状态。 - - **取值**: - - `RUNNING`:将系统设置为运行状态,允许读写操作。 - - `READONLY`:将系统设置为只读状态,只允许读取操作,禁止写入操作。 -2. **localOrClusterMode** - - **含义**:指定状态变更的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `LOCAL`:仅对客户端直连的 DataNode 生效。 - - `CLUSTER`:对集群中所有 DataNode 生效。 - -#### 示例: - -```SQL -IoTDB> SET SYSTEM TO READONLY ON CLUSTER; -``` - - -## 3. 数据管理 - -### 3.1 刷写内存表中的数据到磁盘 - -**含义**:将内存表中的数据刷写到磁盘上。 - -#### 语法: - -```SQL -flushStatement - : FLUSH identifier? (',' identifier)* booleanValue? localOrClusterMode? - ; - -booleanValue - : TRUE | FALSE - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **identifier** - - **含义**:指定要刷写的数据库名称。 - - **可选性**:可选。如果不指定,则默认刷写所有数据库。 - - **多个数据库**:可以指定多个数据库名称,用逗号分隔。例如:`FLUSH test_db1, test_db2`。 -2. **booleanValue** - - **含义**:指定刷写的内容。 - - **可选性**:可选。如果不指定,则默认刷写顺序和乱序空间的内存。 - - **取值**: - - `TRUE`:只刷写顺序空间的内存表。 - - `FALSE`:只刷写乱序空间的MemTable。 -3. **localOrClusterMode** - - **含义**:指定刷写的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `ON LOCAL`:只刷写客户端直连的 DataNode 上的内存表。 - - `ON CLUSTER`:刷写集群中所有 DataNode 上的内存表。 - -#### 示例: - -```SQL -IoTDB> FLUSH test_db TRUE ON LOCAL; -``` - -### 3.2 清除 DataNode 上的缓存 - -**含义**:用于清除 DataNode 上的某种类型的缓存。 - -#### 语法: - -```SQL -clearCacheStatement - : CLEAR clearCacheOptions? CACHE localOrClusterMode? - ; - -clearCacheOptions - : ATTRIBUTE - | QUERY - | ALL - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **clearCacheOptions** - - **含义**:指定要清除的缓存类型。 - - **可选性**:可选。如果不指定,默认清除查询缓存(`QUERY`)。 - - **取值**: - - `ATTRIBUTE`:清除设备属性缓存。 - - `QUERY`:清除存储引擎中的查询缓存。 - - `ALL`:清除所有缓存,包括设备属性缓存、查询缓存以及树模型中的模式缓存。 -2. **localOrClusterMode** - - **含义**:指定清除缓存的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `ON LOCAL`:只清除客户端直连的 DataNode 上的缓存。 - - `ON CLUSTER`:清除集群中所有 DataNode 上的缓存。 - -#### 示例: - -```SQL -IoTDB> CLEAR ALL CACHE ON LOCAL; -``` - -## 4. 数据修复 - -### 4.1 启动后台扫描并修复 tsfile 任务 - -**含义**:启动一个后台任务,开始扫描并修复 tsfile,能够修复数据文件内的时间戳乱序类异常。 - -#### 语法: - -```SQL -startRepairDataStatement - : START REPAIR DATA localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **localOrClusterMode** - - **含义**:指定数据修复的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 - - `ON CLUSTER`:对集群中所有 DataNode 执行。 - -#### 示例: - -```SQL -IoTDB> START REPAIR DATA ON CLUSTER; -``` - -### 4.2 暂停后台修复 tsfile 任务 - -**含义**:暂停后台的修复任务,暂停中的任务可通过再次执行 start repair data 命令恢复。 - -#### 语法: - -```SQL -stopRepairDataStatement - : STOP REPAIR DATA localOrClusterMode? - ; - -localOrClusterMode - : (ON (LOCAL | CLUSTER)) - ; -``` - -**参数解释**: - -1. **localOrClusterMode** - - **含义**:指定数据修复的范围。 - - **可选性**:可选。默认值为 `CLUSTER`。 - - **取值**: - - `ON LOCAL`:仅对客户端直连的 DataNode 执行。 - - `ON CLUSTER`:对集群中所有 DataNode 执行。 - -#### 示例: - -```SQL -IoTDB> STOP REPAIR DATA ON CLUSTER; -``` - -## 5. 终止查询 - -### 5.1 主动终止查询 - -**含义**:使用该命令主动地终止查询。 - -#### 语法: - -```SQL -killQueryStatement - : KILL (QUERY queryId=string | ALL QUERIES) - ; -``` - -**参数解释**: - -1. **QUERY queryId=string** - - **含义**:指定要终止的查询的 ID。 `` 是正在执行的查询的唯一标识符。 - - **获取查询 ID**:可以通过 `SHOW QUERIES` 命令获取所有正在执行的查询及其 ID。 -2. **ALL QUERIES** - - **含义**:终止所有正在执行的查询。 - -#### 示例: - -通过指定 `queryId` 可以中止指定的查询,为了获取正在执行的查询 id,用户可以使用 show queries 命令,该命令将显示所有正在执行的查询列表。 - -```SQL -IoTDB> KILL QUERY 20250108_101015_00000_1; -- 终止指定query -IoTDB> KILL ALL QUERIES; -- 终止所有query -``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_apache.md b/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_apache.md index 99b6e36e5..9f13e8397 100644 --- a/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_apache.md +++ b/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_apache.md @@ -262,7 +262,7 @@ IoTDB> SHOW CURRENT_TIMESTAMP **含义**:用于显示所有正在执行的查询信息。 -> 更多系统表使用方法请参考[系统表](../Reference/System-Tables.md) +> 更多系统表使用方法请参考[系统表](../Reference/System-Tables_apache.md) #### 语法: diff --git a/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_timecho.md b/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_timecho.md index 99b6e36e5..bd526e7fa 100644 --- a/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_timecho.md +++ b/src/zh/UserGuide/latest-Table/User-Manual/Maintenance-statement_timecho.md @@ -262,7 +262,7 @@ IoTDB> SHOW CURRENT_TIMESTAMP **含义**:用于显示所有正在执行的查询信息。 -> 更多系统表使用方法请参考[系统表](../Reference/System-Tables.md) +> 更多系统表使用方法请参考[系统表](../Reference/System-Tables_timecho.md) #### 语法: diff --git a/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table.md b/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table.md index fc6a446c5..4b9eaa718 100644 --- a/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table.md +++ b/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table.md @@ -1,3 +1,6 @@ +--- +redirectTo: Tree-to-Table_apache.html +--- -# 树转表视图 - -## 1. 功能概述 - -IoTDB 提供了树转表功能,支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理: - -* 数据写入阶段,采用树模型语法,支持数据灵活接入和扩展。 -* 数据分析阶段,采用表模型语法,支持通过标准 SQL 查询语言,执行复杂的数据分析。 - -![](/img/tree-to-table-1.png) - -> - V2.0.5 及以后版本支持该功能。 -> - 表视图只读,不允许通过表视图写入数据。 - -## 2. 功能介绍 -### 2.1 创建表视图 -#### 2.1.1 语法定义 - -```SQL --- create (or replace) view on tree -CREATE - [OR REPLACE] - VIEW view_name ([viewColumnDefinition (',' viewColumnDefinition)*]) - [comment] - [RESTRICT] - [WITH properties] - AS prefixPath - -viewColumnDefinition - : column_name [dataType] TAG [comment] # tagColumn - | column_name [dataType] TIME [comment] # timeColumn - | column_name [dataType] FIELD [FROM original_measurement] [comment] # fieldColumn - ; - -comment - : COMMENT string - ; -``` - -> 注意:列仅支持 tag / field / time,不支持 attribute。 - -#### 2.1.2 语法说明 -1. **`prefixPath`** - -对应树模型的路径,路径最后一级必须为 `**`,且其他层级均不能出现 `*` 或 `**`。该路径确定 VIEW 对应的子树。 - -2. **`view_name`** - -视图名称,与表名相同(具体约束可参考[创建表](../Basic-Concept/Table-Management.md#\_1-1-创建表)),如 db.view。 - -3. **`viewColumnDefinition`** - -* `TAG`:每个 Tag 列按顺序对应`prefixPath`后面层级的路径节点。 -* `FIELD`:FIELD 列对应树模型中的测点(叶子节点)。 - * 若指定了 FIELD 列,则列名使用声明中的`column_name`。 - * 若声明了 `original_measurement`,则直接映射到树模型该测点。否则取小写`column_name` 作为测点名进行树模型映射。 - * 不支持多个 FIELD 映射到树模型同名测点。 - * 若未指定 FIELD 列的 `dataType`,则默认获取树模型映射测点的数据类型。 - * 若树模型中的设备不包含某些声明的 FIELD 列,或与声明的 FIELD 列的数据类型不一致,则在查询该设备时,该 FIELD 列的值永远为 NULL。 - * 若未指定 FIELD 列,则创建时会自动扫描出`prefixPath`子树下所有的测点(包括定义为所有普通序列的测点,以及挂载路径与 `prefixPath `有所重合的所有模板中的测点),列名使用树模型测点名称。 - * 不支持树模型存在名称(含小写)相同但类型不同的测点 - -4. **`WITH properties`** - -目前仅支持 TTL,表示该视图 TTL ms 之前的数据不会在查询时展示,即`WHERE time > now() - TTL`。若树模型设置了 TTL,则查询时取两者中的更小值。 - -> 注意:表视图 TTL 不影响树模型中设备的真实 TTL,当设备数据达到树模型设定的 TTL 后,将被系统物理删除。 - -5. **`OR REPLACE`** - -table 与 view 不能重名。创建时若已存在同名 table ,则会报错;若已存在同名 view ,则进行替换。 - -6. **`RESTRICT`** - -约束匹配树模型设备的层级数(从 prefixPath 下一层开始),若有 RESTRICT 字段,则匹配层级完全等于 tag 数量的 device,否则匹配层级小于等于 tag 数量的 device。默认非 RESTRICT,即匹配层级小于等于 tag 数量的 device。 - -#### 2.1.3 使用示例 -1. 树模型及表视图原型 - -![](/img/tree-to-table-2.png) - -2. 创建表视图 - -* 创建语句 - -```SQL -CREATE OR REPLACE VIEW viewdb."风机表" - ("风机组" TAG, - "风机号" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -with (ttl=604800000) -AS root.db.** -``` - -* 具体说明 - -该语句表示,创建出名为 `viewdb."风机表"` 的视图(viewdb 如不存在会报错),如果该视图已存在,则替换该视图: - -* 为挂载于树模型 root.db.\*\* 路径下面的序列创建表视图。 -* 具备`风机组`、`风机号`两个 `TAG` 列,因此表视图中只包含原树模型中第 3 层上的设备。 -* 具备`电压`、`电流`两个 `FIELD` 列。这里两个 `FIELD` 列对应树模型下的序列名同样是`电压`、`电流`,且仅仅选取类型为 `DOUBLE` 的序列。 - - **​序列名的改名需求:​**如果树模型下的序列名为`current`,想要创建出的表视图中对应的 `FIELD` 列名为`电流`,这种情况下,SQL 变更如下: - - ```SQL - CREATE OR REPLACE VIEW viewdb."风机表" - ("风机组" TAG, - "风机号" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD FROM current - ) - AS root.db.** - with (ttl=604800000) - ``` - -### 2.2 修改表视图 -#### 2.2.1 语法定义 - -修改表视图功能支持修改视图名称、添加列、列重命名、删除列、设置视图的 TTL 属性,以及通过 COMMENT 添加注释。 - -```SQL --- 修改视图名 -ALTER VIEW [IF EXISTS] viewName RENAME TO to=identifier - --- 在视图中添加某一列 -ALTER VIEW [IF EXISTS] viewName ADD COLUMN [IF NOT EXISTS] viewColumnDefinition -viewColumnDefinition - : column_name [dataType] TAG # tagColumn - | column_name [dataType] FIELD [FROM original_measurement] # fieldColumn - --- 为视图中的某一列重命名 -ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName - --- 删除视图中的某一列 -ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName - --- 修改视图的 TTL -ALTER VIEW [IF EXISTS] viewName SET PROPERTIES propertyAssignments - --- 添加注释 -COMMENT ON VIEW qualifiedName IS (string | NULL) #commentView -COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commentColumn -``` - -#### 2.2.2 语法说明 -1. `SET PROPERTIES`操作目前仅支持对表视图的 TTL 属性进行配置。 -2. 删除列功能,仅支持删除物理量列(FIELD),标识列(TAG)不支持删除。 -3. 修改后的 comment 会覆盖原有注释,如果指定为 null,则会擦除之前的 comment。 -#### 2.2.3 使用示例 - -```SQL --- 修改视图名 -ALTER VIEW IF EXISTS tableview1 RENAME TO tableview - --- 在视图中添加某一列 -ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field - --- 为视图中的某一列重命名 -ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp - --- 删除视图中的某一列 -ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp - --- 修改视图的 TTL -ALTER VIEW IF EXISTS tableview SET PROPERTIES TTL=3600 - --- 添加注释 -COMMENT ON VIEW tableview IS '树转表' -COMMENT ON COLUMN tableview.status is Null -``` - -### 2.3 删除表视图 -#### 2.3.1 语法定义 - -```SQL -DROP VIEW [IF EXISTS] viewName -``` - -#### 2.3.2 使用示例 - -```SQL -DROP VIEW IF EXISTS tableview -``` - -### 2.4 查看表视图 -#### 2.4.1 **`Show Tables`** -1. 语法定义 - -```SQL -SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? -``` - -2. 语法说明 - -`SHOW TABLES (DETAILS)` 语句通过结果集的`TABLE_TYPE`字段展示表或视图的类型信息: - -| 类型 | `TABLE_TYPE`字段值 | -| -------------------------------------- | ------------------------ | -| 普通表(Table) | `BASE TABLE` | -| 树转表视图(Tree View) | `VIEW FROM TREE` | -| 系统表(Iinformation\_schema.Tables) | `SYSTEM VIEW` | - -3. 使用示例 - -```SQL -IoTDB> show tables details from database1 -+-----------+-----------+------+-------+--------------+ -| TableName| TTL(ms)|Status|Comment| TableType| -+-----------+-----------+------+-------+--------------+ -| tableview| INF| USING| 树转表 |VIEW FROM TREE| -| table1|31536000000| USING| null| BASE TABLE| -| table2|31536000000| USING| null| BASE TABLE| -+-----------+-----------+------+-------+--------------+ - -IoTDB> show tables details from information_schema -+--------------+-------+------+-------+-----------+ -| TableName|TTL(ms)|Status|Comment| TableType| -+--------------+-------+------+-------+-----------+ -| columns| INF| USING| null|SYSTEM VIEW| -| config_nodes| INF| USING| null|SYSTEM VIEW| -|configurations| INF| USING| null|SYSTEM VIEW| -| data_nodes| INF| USING| null|SYSTEM VIEW| -| databases| INF| USING| null|SYSTEM VIEW| -| functions| INF| USING| null|SYSTEM VIEW| -| keywords| INF| USING| null|SYSTEM VIEW| -| models| INF| USING| null|SYSTEM VIEW| -| nodes| INF| USING| null|SYSTEM VIEW| -| pipe_plugins| INF| USING| null|SYSTEM VIEW| -| pipes| INF| USING| null|SYSTEM VIEW| -| queries| INF| USING| null|SYSTEM VIEW| -| regions| INF| USING| null|SYSTEM VIEW| -| subscriptions| INF| USING| null|SYSTEM VIEW| -| tables| INF| USING| null|SYSTEM VIEW| -| topics| INF| USING| null|SYSTEM VIEW| -| views| INF| USING| null|SYSTEM VIEW| -+--------------+-------+------+-------+-----------+ -``` - -#### 2.4.2 **`Show Create Table/View`** -1. 语法定义 - -```SQL -SHOW CREATE TABLE|VIEW viewname; -``` - -2. 语法说明 - -* SHOW CREATE TABLE 语句可用于展示普通表或者视图的完整创建信息; -* SHOW CREATE VIEW 语句仅可用于展示视图的完整创建信息; -* 两种语句均不支持用于展示系统表; - -3. 使用示例 - -```SQL -IoTDB> show create table tableview -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| View| Create View| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '树转表' WITH (ttl=INF) AS root.ln.**| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ - -IoTDB> show create view tableview -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| View| Create View| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -|tableview|CREATE VIEW "tableview" ("device" STRING TAG,"model" STRING TAG,"status" BOOLEAN FIELD,"hardware" STRING FIELD) COMMENT '表视图' WITH (ttl=INF) AS root.ln.**| -+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ -``` - -### 2.5 非对齐与对齐设备的查询差异 - -树转表视图在查询对齐设备和非对齐设备中有 null 值的情况下结果​**可能与等价的树模型 align by device 查询不同**​。 - -* **对齐设备** - * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 - * 表视图的查询表现:与表模型一致,保留全是 null 的行 -* **非对齐设备** - * 树模型的查询表现:当查询涉及的所有序列在某一行都是null时,不保留该行 - * 表视图的查询表现:与树模型一致,不保留全是 null 的行 -* **说明示例** - * 对齐 - - ```SQL - -- 树模型写入数据(对齐) - CREATE ALIGNED TIMESERIES root.db.battery.b1(voltage INT32, current FLOAT) - INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (1, 1, 1) - INSERT INTO root.db.battery.b1(time, voltage, current) aligned values (2, null, 1) - - -- 创建 VIEW 语句 - CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** - - -- 查询 - IoTDB> select voltage from view1 - +-------+ - |voltage| - +-------+ - | 1| - | null| - +-------+ - Total line number = 2 - ``` - - * 非对齐 - - ```SQL - -- 树模型写入数据(非对齐) - CREATE TIMESERIES root.db.battery.b1.voltage INT32 - CREATE TIMESERIES root.db.battery.b1.current FLOAT - INSERT INTO root.db.battery.b1(time, voltage, current) values (1, 1, 1) - INSERT INTO root.db.battery.b1(time, voltage, current) values (2, null, 1) - - -- 创建 VIEW 语句 - CREATE VIEW view1 (battery_id TAG, voltage INT32 FIELD, current FLOAT FIELD) as root.db.battery.** - - -- 查询 - IoTDB> select voltage from view1 - +-------+ - |voltage| - +-------+ - | 1| - +-------+ - Total line number = 1 - - -- 如果在查询语句中指定了所有 field 列,或是仅指定了非 field 列时,才可以确保查到所有行 - IoTDB> select voltage,current from view1 - +-------+-------+ - |voltage|current| - +-------+-------+ - | 1| 1.0| - | null| 1.0| - +-------+-------+ - Total line number = 2 - - IoTDB> select battery_id from view1 - +-------+ - |battery_id| - +-------+ - | b1| - | b1| - +-------+ - Total line number = 2 - - -- 如果查询中同时有部分 field 列,那最终结果的行数取决于这部分 field 列根据时间戳对齐后的行数 - IoTDB> select time,voltage from view1 - +-----------------------------+-------+ - | time|voltage| - +-----------------------------+-------+ - |1970-01-01T08:00:00.001+08:00| 1| - +-----------------------------+-------+ - Total line number = 1 - ``` - -## 3. 场景示例 -### 3.1 原树模型管理了多种类型的设备 - -* 场景中不同类型的设备具备不同的层级路径和测点集合。 -* ​**写入时**​:在数据库节点下按设备类型创建分支,每种设备下可以有不同的测点结构 -* ​**查询时**​:为每种类型的设备建立一张表,每个表具有不同的标签和测点集合 - -![](/img/tree-to-table-3.png) - -**表视图的创建 SQL:** - -```SQL --- 风机表 -CREATE VIEW viewdb."风机表" - ("风机组" TAG, - "风机号" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -AS root.db."风机".** - --- 电机表 -CREATE VIEW viewdb."电机表" - ("电机组" TAG, - "电机号" TAG, - "功率" FLOAT FIELD, - "电量" FLOAT FIELD, - "温度" FLOAT FIELD - ) -AS root.db."电机".** -``` - -### 3.2 原树模型中没有设备,只有测点 - -如场站的监控系统中,每个测点都有唯一编号,但无法对应到某些设备 - -> 大宽表形式 - -![](/img/tree-to-table-4.png) - -**表视图的创建 SQL:** - -```SQL -CREATE VIEW viewdb.machine - (DCS_PIT_02105A DOUBLE FIELD, - DCS_PIT_02105B DOUBLE FIELD, - DCS_PIT_02105C DOUBLE FIELD, - ... - DCS_XI_02716A DOUBLE FIELD - ) -AS root.db.** -``` - -### 3.3 原树模型中一个设备既有子设备,也有测点 - -如在储能场景中,每一层结构都要监控其电压和电流 - -* ​**写入时**​:按照物理世界的监测点,对每一层结构进行建模 -* ​**查询时**​:按照设备分类,建立多个表对每一层结构信息进行管理 - -![](/img/tree-to-table-5.png) - -**表视图的创建 SQL:** - -```SQL --- 电池舱表 -CREATE VIEW viewdb."电池舱表" - ("电池站" TAG, - "电池舱" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -RESTRICT -AS root.db.** - --- 电池堆表 -CREATE VIEW viewdb."电池堆表" - ("电池站" TAG, - "电池舱" TAG, - "电池堆" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -RESTRICT -AS root.db.** - --- 电池簇表 -CREATE VIEW viewdb."电池簇表" - ("电池站" TAG, - "电池舱" TAG, - "电池堆" TAG, - "电池簇" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -RESTRICT -AS 'root.db.**' - --- 电芯表 -CREATE VIEW viewdb."电芯表" - ("电池站" TAG, - "电池舱" TAG, - "电池堆" TAG, - "电池簇" TAG, - "电芯" TAG, - "电压" DOUBLE FIELD, - "电流" DOUBLE FIELD - ) -RESTRICT -AS root.db.** -``` - -### 3.4 原树模型中一个设备下只有一个测点 - -> 窄表形式 - -#### 3.4.1 所有测点数据类型相同 - -![](/img/tree-to-table-6.png) - -**表视图的创建 SQL:** - -```SQL -CREATE VIEW viewdb.machine - ( - sensor_id STRING TAG, - value DOUBLE FIELD - ) -AS root.db.** -``` - -#### 3.4.2 测点的数据类型不相同 -##### 3.4.2.1 为每一种数据类型的测点建一个窄表视图 - -​**优点**​:表视图数量是常数个,仅与系统中的数据类型相关 - -​**缺点**​:查询某一个测点值时,需要提前知道其数据类型,再去决定查询哪张表视图 - -![](/img/tree-to-table-7.png) - -**表视图的创建 SQL:** - -```SQL -CREATE VIEW viewdb.machine_float - ( - sensor_id STRING TAG, - value FLOAT FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_double - ( - sensor_id STRING TAG, - value DOUBLE FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_int32 - ( - sensor_id STRING TAG, - value INT32 FIELD - ) -AS root.db.** - -CREATE VIEW viewdb.machine_int64 - ( - sensor_id STRING TAG, - value INT64 FIELD - ) -AS root.db.** - -... -``` - -##### 3.4.2.2 为每一个测点建一个表 - -​**优点**​:查询某一个测点值时,不需要先查一下数据类型,再去决定查询哪张表,简单便捷 - -​**缺点**​:当测点数量较多时,会引入过多的表视图,需要写大量的建视图语句 - -![](/img/tree-to-table-8.png) - -**表视图的创建 SQL:** - -```SQL -CREATE VIEW viewdb.DCS_PIT_02105A - ( - value FLOAT FIELD - ) -AS root.db.DCS_PIT_02105A.** - -CREATE VIEW viewdb.DCS_PIT_02105B - ( - value DOUBLE FIELD - ) -AS root.db.DCS_PIT_02105B.** - -CREATE VIEW viewdb.DCS_XI_02716A - ( - value INT64 FIELD - ) -AS root.db.DCS_XI_02716A.** - -...... -``` diff --git a/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md b/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md index fc6a446c5..06b2e5b62 100644 --- a/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md +++ b/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_apache.md @@ -66,7 +66,7 @@ comment 2. **`view_name`** -视图名称,与表名相同(具体约束可参考[创建表](../Basic-Concept/Table-Management.md#\_1-1-创建表)),如 db.view。 +视图名称,与表名相同(具体约束可参考[创建表](../Basic-Concept/Table-Management_apache.md#\_1-1-创建表)),如 db.view。 3. **`viewColumnDefinition`** diff --git a/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md b/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md index fc6a446c5..75378e3c5 100644 --- a/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md +++ b/src/zh/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md @@ -66,7 +66,7 @@ comment 2. **`view_name`** -视图名称,与表名相同(具体约束可参考[创建表](../Basic-Concept/Table-Management.md#\_1-1-创建表)),如 db.view。 +视图名称,与表名相同(具体约束可参考[创建表](../Basic-Concept/Table-Management_timecho.md#\_1-1-创建表)),如 db.view。 3. **`viewColumnDefinition`** From 8883d833c9cca920c07000d791a133b2fe3c1a61 Mon Sep 17 00:00:00 2001 From: CritasWang Date: Tue, 13 Jan 2026 10:29:08 +0800 Subject: [PATCH 3/5] Update SSH key handling in clean-site workflow --- .github/workflows/clean-site.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clean-site.yml b/.github/workflows/clean-site.yml index 61aba6079..8ce1b9ec7 100644 --- a/.github/workflows/clean-site.yml +++ b/.github/workflows/clean-site.yml @@ -33,8 +33,8 @@ jobs: SSH_KEY: ${{ secrets.IOTDB_WEBSITE_BUILD_SSH }} run: | mkdir -p ~/.ssh - echo "$SSH_KEY" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa + echo "$SSH_KEY" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 ssh-keyscan -H github.com >> ~/.ssh/known_hosts - name: Checkout iotdb-website repository From 412b5025b2e79f48a1c019d1abb7661dc5b699e0 Mon Sep 17 00:00:00 2001 From: CritasWang Date: Tue, 13 Jan 2026 10:29:35 +0800 Subject: [PATCH 4/5] Update site-build.yaml --- .github/workflows/site-build.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/site-build.yaml b/.github/workflows/site-build.yaml index 2a68c963e..69742b660 100644 --- a/.github/workflows/site-build.yaml +++ b/.github/workflows/site-build.yaml @@ -43,8 +43,8 @@ jobs: SSH_KEY: ${{ secrets.IOTDB_WEBSITE_BUILD_SSH }} run: | mkdir -p ~/.ssh - echo "$SSH_KEY" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa + echo "$SSH_KEY" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 ssh-keyscan -H github.com >> ~/.ssh/known_hosts git config --global user.name github-actions git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com @@ -103,8 +103,8 @@ jobs: SSH_KEY: ${{ secrets.IOTDB_WEBSITE_BUILD_SSH }} run: | mkdir -p ~/.ssh - echo "$SSH_KEY" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa + echo "$SSH_KEY" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 ssh-keyscan -H github.com >> ~/.ssh/known_hosts git config --global user.name github-actions git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com From ae099a132892d3d4443150a98053f9a31cc2a008 Mon Sep 17 00:00:00 2001 From: CritasWang Date: Tue, 13 Jan 2026 11:08:47 +0800 Subject: [PATCH 5/5] deploy staging when labes contains deploy-staging --- .github/workflows/site-build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/site-build.yaml b/.github/workflows/site-build.yaml index 69742b660..46bc66b3b 100644 --- a/.github/workflows/site-build.yaml +++ b/.github/workflows/site-build.yaml @@ -39,6 +39,7 @@ jobs: run: pnpm build - name: Deploy staging website + if: contains(github.event.pull_request.labels.*.name, 'deploy-staging') env: SSH_KEY: ${{ secrets.IOTDB_WEBSITE_BUILD_SSH }} run: |