Skip to content

Commit b1ac933

Browse files
committed
add Time Series Data Model and Modeling Design Plan to table management, update related document
1 parent 593a139 commit b1ac933

60 files changed

Lines changed: 22294 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<!--
2+
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
20+
-->
21+
22+
# Database Management
23+
24+
## 1. Database Management
25+
26+
### 1.1 Create a Database
27+
28+
This command is used to create a database.
29+
30+
**Syntax:**
31+
32+
```SQL
33+
CREATE DATABASE (IF NOT EXISTS)? <DATABASE_NAME> (WITH properties)?
34+
```
35+
36+
**Note: **
37+
38+
1. `<DATABASE_NAME>`: The name of the database, with the following characteristics:
39+
- Case-insensitive. After creation, it will be displayed uniformly in lowercase.
40+
- Can include commas (`,`), underscores (`_`), numbers, letters, and Chinese characters.
41+
- Maximum length is 64 characters.
42+
- Names with special characters or Chinese characters must be enclosed in double quotes (`""`).
43+
44+
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:
45+
46+
| Property | Description | Default Value |
47+
| ----------------------- | ------------------------------------------------------------ | -------------------- |
48+
| TTL | Automatic data expiration time, in milliseconds | `INF` |
49+
| TIME_PARTITION_INTERVAL | Time partition interval for the database, in milliseconds | `604800000` (7 days) |
50+
| SCHEMA_REGION_GROUP_NUM | Number of metadata replica groups; generally does not require modification | `1` |
51+
| DATA_REGION_GROUP_NUM | Number of data replica groups; generally does not require modification | `2` |
52+
53+
**Examples:**
54+
55+
```SQL
56+
CREATE DATABASE database1;
57+
CREATE DATABASE IF NOT EXISTS database1;
58+
59+
// Sets TTL to 1 year.
60+
CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000);
61+
```
62+
63+
### 1.2 Use a Database
64+
65+
Specify the current database as the namespace for table operations.
66+
67+
**Syntax:**
68+
69+
```SQL
70+
USE <DATABASE_NAME>
71+
```
72+
73+
**Example:**
74+
75+
```SQL
76+
USE database1
77+
```
78+
79+
### 1.3 View the Current Database
80+
81+
Displays the name of the currently connected database. If no USE statement has been executed, the default is `null`.
82+
83+
**Syntax:**
84+
85+
```SQL
86+
SHOW CURRENT_DATABASE
87+
```
88+
89+
**Example:**
90+
91+
```SQL
92+
IoTDB> SHOW CURRENT_DATABASE;
93+
+---------------+
94+
|CurrentDatabase|
95+
+---------------+
96+
| null|
97+
+---------------+
98+
99+
IoTDB> USE test;
100+
101+
IoTDB> SHOW CURRENT_DATABASE;
102+
+---------------+
103+
|CurrentDatabase|
104+
+---------------+
105+
| iot_database|
106+
+---------------+
107+
```
108+
109+
### 1.4 View All Databases
110+
111+
Displays all databases and their properties.
112+
113+
**Syntax:**
114+
115+
```SQL
116+
SHOW DATABASES (DETAILS)?
117+
```
118+
119+
**Columns Explained:**
120+
121+
122+
| Column Name | Description |
123+
| ----------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
124+
| database | Name of the database. |
125+
| 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) . |
126+
| 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. |
127+
| 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. |
128+
| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. |
129+
| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). |
130+
131+
**Examples:**
132+
133+
```SQL
134+
IoTDB> show databases
135+
+---------+-------+-----------------------+---------------------+---------------------+
136+
| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|
137+
+---------+-------+-----------------------+---------------------+---------------------+
138+
|test_prop| 300| 3| 2| 100000|
139+
| test2| 300| 3| 2| 604800000|
140+
+---------+-------+-----------------------+---------------------+---------------------+
141+
IoTDB> show databases details
142+
+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+
143+
| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum|
144+
+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+
145+
|test_prop| 300| 3| 2| 100000| 1| 2|
146+
| test2| 300| 3| 2| 604800000| 1| 2|
147+
+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+
148+
```
149+
150+
### 1.5 Update a Database
151+
152+
Used to modify some attributes in the database.
153+
154+
**Syntax:**
155+
156+
```SQL
157+
ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments
158+
```
159+
160+
**Note:**
161+
162+
1. The `ALTER DATABASE` operation currently only supports modifications to the database's `SCHEMA_REGION_GROUP_NUM`, `DATA_REGION_GROUP_NUM`, and `TTL` attributes.
163+
164+
**Example:**
165+
166+
```SQL
167+
ALTER DATABASE database1 SET PROPERTIES TTL=31536000000;
168+
```
169+
170+
### 1.6 Delete a Database
171+
172+
Deletes the specified database and all associated tables and data.
173+
174+
**Syntax:**
175+
176+
```SQL
177+
DROP DATABASE (IF EXISTS)? <DATABASE_NAME>
178+
```
179+
180+
**Note:**
181+
182+
1. A database currently in use can still be dropped.
183+
2. Deleting a database removes all its tables and stored data.
184+
185+
**Example:**
186+
187+
```SQL
188+
DROP DATABASE IF EXISTS database1
189+
```
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<!--
2+
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
20+
-->
21+
22+
# Database Management
23+
24+
## 1. Database Management
25+
26+
### 1.1 Create a Database
27+
28+
This command is used to create a database.
29+
30+
**Syntax:**
31+
32+
```SQL
33+
CREATE DATABASE (IF NOT EXISTS)? <DATABASE_NAME> (WITH properties)?
34+
```
35+
36+
**Note: **
37+
38+
1. `<DATABASE_NAME>`: The name of the database, with the following characteristics:
39+
- Case-insensitive. After creation, it will be displayed uniformly in lowercase.
40+
- Can include commas (`,`), underscores (`_`), numbers, letters, and Chinese characters.
41+
- Maximum length is 64 characters.
42+
- Names with special characters or Chinese characters must be enclosed in double quotes (`""`).
43+
44+
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:
45+
46+
| Property | Description | Default Value |
47+
| ----------------------- | ------------------------------------------------------------ | -------------------- |
48+
| TTL | Automatic data expiration time, in milliseconds | `INF` |
49+
| TIME_PARTITION_INTERVAL | Time partition interval for the database, in milliseconds | `604800000` (7 days) |
50+
| SCHEMA_REGION_GROUP_NUM | Number of metadata replica groups; generally does not require modification | `1` |
51+
| DATA_REGION_GROUP_NUM | Number of data replica groups; generally does not require modification | `2` |
52+
53+
**Examples:**
54+
55+
```SQL
56+
CREATE DATABASE database1;
57+
CREATE DATABASE IF NOT EXISTS database1;
58+
59+
// Sets TTL to 1 year.
60+
CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000);
61+
```
62+
63+
### 1.2 Use a Database
64+
65+
Specify the current database as the namespace for table operations.
66+
67+
**Syntax:**
68+
69+
```SQL
70+
USE <DATABASE_NAME>
71+
```
72+
73+
**Example:**
74+
75+
```SQL
76+
USE database1
77+
```
78+
79+
### 1.3 View the Current Database
80+
81+
Displays the name of the currently connected database. If no USE statement has been executed, the default is `null`.
82+
83+
**Syntax:**
84+
85+
```SQL
86+
SHOW CURRENT_DATABASE
87+
```
88+
89+
**Example:**
90+
91+
```SQL
92+
IoTDB> SHOW CURRENT_DATABASE;
93+
+---------------+
94+
|CurrentDatabase|
95+
+---------------+
96+
| null|
97+
+---------------+
98+
99+
IoTDB> USE test;
100+
101+
IoTDB> SHOW CURRENT_DATABASE;
102+
+---------------+
103+
|CurrentDatabase|
104+
+---------------+
105+
| iot_database|
106+
+---------------+
107+
```
108+
109+
### 1.4 View All Databases
110+
111+
Displays all databases and their properties.
112+
113+
**Syntax:**
114+
115+
```SQL
116+
SHOW DATABASES (DETAILS)?
117+
```
118+
119+
**Columns Explained:**
120+
121+
122+
| Column Name | Description |
123+
| ----------------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
124+
| database | Name of the database. |
125+
| 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) . |
126+
| 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. |
127+
| 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. |
128+
| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. |
129+
| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). |
130+
131+
**Examples:**
132+
133+
```SQL
134+
IoTDB> show databases
135+
+---------+-------+-----------------------+---------------------+---------------------+
136+
| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|
137+
+---------+-------+-----------------------+---------------------+---------------------+
138+
|test_prop| 300| 3| 2| 100000|
139+
| test2| 300| 3| 2| 604800000|
140+
+---------+-------+-----------------------+---------------------+---------------------+
141+
IoTDB> show databases details
142+
+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+
143+
| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum|
144+
+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+
145+
|test_prop| 300| 3| 2| 100000| 1| 2|
146+
| test2| 300| 3| 2| 604800000| 1| 2|
147+
+---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+
148+
```
149+
150+
### 1.5 Update a Database
151+
152+
Used to modify some attributes in the database.
153+
154+
**Syntax:**
155+
156+
```SQL
157+
ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignments
158+
```
159+
160+
**Note:**
161+
162+
1. The `ALTER DATABASE` operation currently only supports modifications to the database's `SCHEMA_REGION_GROUP_NUM`, `DATA_REGION_GROUP_NUM`, and `TTL` attributes.
163+
164+
**Example:**
165+
166+
```SQL
167+
ALTER DATABASE database1 SET PROPERTIES TTL=31536000000;
168+
```
169+
170+
### 1.6 Delete a Database
171+
172+
Deletes the specified database and all associated tables and data.
173+
174+
**Syntax:**
175+
176+
```SQL
177+
DROP DATABASE (IF EXISTS)? <DATABASE_NAME>
178+
```
179+
180+
**Note:**
181+
182+
1. A database currently in use can still be dropped.
183+
2. Deleting a database removes all its tables and stored data.
184+
185+
**Example:**
186+
187+
```SQL
188+
DROP DATABASE IF EXISTS database1
189+
```

0 commit comments

Comments
 (0)