Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/.vuepress/sidebar/V1.3.x/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ export const enSidebar = {
},
],
},
{ text: 'Write & Delete', link: 'Write-Delete-Data' },
{ text: 'Write Data', link: 'Write-Data' },
{ text: 'Query Data', link: 'Query-Data' },
{
text: 'Delete Data',
collapsible: true,
children: [
{ text: 'Delete Data', link: 'Delete-Data' },
{ text: 'TTL Delete Data', link: 'TTL-Delete' },
],
},
],
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/.vuepress/sidebar/V1.3.x/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@ export const zhSidebar = {
{ text: '测点管理', link: 'Operate-Metadata_apache' },
],
},
{ text: '写入&删除', link: 'Write-Delete-Data' },
{ text: '数据写入', link: 'Write-Data' },
{ text: '数据查询', link: 'Query-Data' },
{
text: '数据删除',
collapsible: true,
children: [
{ text: '数据删除', link: 'Delete-Data' },
{ text: '自动过期删除', link: 'TTL-Delete' },
],
},
],
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/.vuepress/sidebar/V2.0.x/en-Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ export const enSidebar = {
text: 'Data Modeling',
link: 'Operate-Metadata_apache',
},
{ text: 'Write & Delete', link: 'Write-Delete-Data' },
{ text: 'Write Data', link: 'Write-Data' },
{ text: 'Query Data', link: 'Query-Data' },
{
text: 'Delete Data',
collapsible: true,
children: [
{ text: 'Delete Data', link: 'Delete-Data' },
{ text: 'TTL Delete Data', link: 'TTL-Delete' },
],
},
],
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/.vuepress/sidebar/V2.0.x/zh-Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,16 @@ export const zhSidebar = {
prefix: 'Basic-Concept/',
children: [
{ text: '测点管理', link: 'Operate-Metadata_apache' },
{ text: '写入&删除', link: 'Write-Delete-Data' },
{ text: '数据写入', link: 'Write-Data' },
{ text: '数据查询', link: 'Query-Data' },
{
text: '数据删除',
collapsible: true,
children: [
{ text: '数据删除', link: 'Delete-Data' },
{ text: '自动过期删除', link: 'TTL-Delete' },
],
},
],
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/.vuepress/sidebar_timecho/V1.3.x/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,16 @@ export const enSidebar = {
},
],
},
{ text: 'Write & Delete', link: 'Write-Delete-Data' },
{ text: 'Write Data', link: 'Write-Data' },
{ text: 'Query Data', link: 'Query-Data' },
{
text: 'Delete Data',
collapsible: true,
children: [
{ text: 'Delete Data', link: 'Delete-Data' },
{ text: 'TTL Delete Data', link: 'TTL-Delete' },
],
},
],
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/.vuepress/sidebar_timecho/V1.3.x/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ export const zhSidebar = {
{ text: '测点管理', link: 'Operate-Metadata_timecho' },
],
},
{ text: '写入&删除', link: 'Write-Delete-Data' },
{ text: '数据写入', link: 'Write-Data' },
{ text: '数据查询', link: 'Query-Data' },
{
text: '数据删除',
collapsible: true,
children: [
{ text: '数据删除', link: 'Delete-Data' },
{ text: '自动过期删除', link: 'TTL-Delete' },
],
},
],
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/.vuepress/sidebar_timecho/V2.0.x/en-Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@ export const enSidebar = {
text: 'Data Modeling',
link: 'Operate-Metadata_timecho',
},
{ text: 'Write & Delete', link: 'Write-Delete-Data' },
{ text: 'Write Data', link: 'Write-Data' },
{ text: 'Query Data', link: 'Query-Data' },
{
text: 'Delete Data',
collapsible: true,
children: [
{ text: 'Delete Data', link: 'Delete-Data' },
{ text: 'TTL Delete Data', link: 'TTL-Delete' },
],
},
],
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/.vuepress/sidebar_timecho/V2.0.x/zh-Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ export const zhSidebar = {
prefix: 'Basic-Concept/',
children: [
{ text: '测点管理', link: 'Operate-Metadata_timecho' },
{ text: '写入&删除', link: 'Write-Delete-Data' },
{ text: '数据写入', link: 'Write-Data' },
{ text: '数据查询', link: 'Query-Data' },
{
text: '数据删除',
collapsible: true,
children: [
{ text: '数据删除', link: 'Delete-Data' },
{ text: '自动过期删除', link: 'TTL-Delete' },
],
},
],
},
{
Expand Down
104 changes: 104 additions & 0 deletions src/UserGuide/Master/Tree/Basic-Concept/Delete-Data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

-->
# Delete Data

Users can delete data that meet the deletion condition in the specified timeseries by using the [DELETE statement](../SQL-Manual/SQL-Manual.md#delete-data). When deleting data, users can select one or more timeseries paths, prefix paths, or paths with star to delete data within a certain time interval.

In a JAVA programming environment, you can use the [Java JDBC](../API/Programming-JDBC.md) to execute single or batch UPDATE statements.

## 1. Delete Single Timeseries

Taking ln Group as an example, there exists such a usage scenario:

The wf02 plant's wt02 device has many segments of errors in its power supply status before 2017-11-01 16:26:00, and the data cannot be analyzed correctly. The erroneous data affected the correlation analysis with other devices. At this point, the data before this time point needs to be deleted. The SQL statement for this operation is

```sql
delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00;
```

In case we hope to merely delete the data before 2017-11-01 16:26:00 in the year of 2017, The SQL statement is:

```sql
delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00;
```

IoTDB supports to delete a range of timeseries points. Users can write SQL expressions as follows to specify the delete interval:

```sql
delete from root.ln.wf02.wt02.status where time < 10
delete from root.ln.wf02.wt02.status where time <= 10
delete from root.ln.wf02.wt02.status where time < 20 and time > 10
delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10
delete from root.ln.wf02.wt02.status where time > 20
delete from root.ln.wf02.wt02.status where time >= 20
delete from root.ln.wf02.wt02.status where time = 20
```

Please pay attention that multiple intervals connected by "OR" expression are not supported in delete statement:

```
delete from root.ln.wf02.wt02.status where time > 4 or time < 0
Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic
expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND'
```

If no "where" clause specified in a delete statement, all the data in a timeseries will be deleted.

```sql
delete from root.ln.wf02.wt02.status
```


## 2. Delete Multiple Timeseries

If both the power supply status and hardware version of the ln group wf02 plant wt02 device before 2017-11-01 16:26:00 need to be deleted, [the prefix path with broader meaning or the path with star](../Basic-Concept/Operate-Metadata.md) can be used to delete the data. The SQL statement for this operation is:

```sql
delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00;
```

or

```sql
delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00;
```

It should be noted that when the deleted path does not exist, IoTDB will not prompt that the path does not exist, but that the execution is successful, because SQL is a declarative programming method. Unless it is a syntax error, insufficient permissions and so on, it is not considered an error, as shown below:

```
IoTDB> delete from root.ln.wf03.wt02.status where time < now()
Msg: The statement is executed successfully.
```

## 3. Delete Time Partition (experimental)

You may delete all data in a time partition of a database using the following grammar:

```sql
DELETE PARTITION root.ln 0,1,2
```

The `0,1,2` above is the id of the partition that is to be deleted, you can find it from the IoTDB
data folders or convert a timestamp manually to an id using `timestamp / partitionInterval
` (flooring), and the `partitionInterval` should be in your config (if time-partitioning is
supported in your version).

Please notice that this function is experimental and mainly for development, please use it with care.
134 changes: 134 additions & 0 deletions src/UserGuide/Master/Tree/Basic-Concept/TTL-Delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

-->
# TTL Delete Data

## 1. Overview

IoTDB supports device-level TTL settings, which means it is able to delete old data automatically and periodically. The benefit of using TTL is that hopefully you can control the total disk space usage and prevent the machine from running out of disks. Moreover, the query performance may downgrade as the total number of files goes up and the memory usage also increases as there are more files. Timely removing such files helps to keep at a high query performance level and reduce memory usage.

The default unit of TTL is milliseconds. If the time precision in the configuration file changes to another, the TTL is still set to milliseconds.

When setting TTL, the system will look for all devices included in the set path and set TTL for these devices. The system will delete expired data at the device granularity.
After the device data expires, it will not be queryable. The data in the disk file cannot be guaranteed to be deleted immediately, but it can be guaranteed to be deleted eventually.
However, due to operational costs, the expired data will not be physically deleted right after expiring. The physical deletion is delayed until compaction.
Therefore, before the data is physically deleted, if the TTL is reduced or lifted, it may cause data that was previously invisible due to TTL to reappear.
The system can only set up to 1000 TTL rules, and when this limit is reached, some TTL rules need to be deleted before new rules can be set.

## 2. Set TTL
### 2.1 TTL Path Rule
The path can only be prefix paths (i.e., the path cannot contain \* , except \*\* in the last level).
This path will match devices and also allows users to specify paths without asterisks as specific databases or devices.
When the path does not contain asterisks, the system will check if it matches a database; if it matches a database, both the path and path.\*\* will be set at the same time. Note: Device TTL settings do not verify the existence of metadata, i.e., it is allowed to set TTL for a non-existent device.
```
qualified paths:
root.**
root.db.**
root.db.group1.**
root.db
root.db.group1.d1

unqualified paths:
root.*.db
root.**.db.*
root.db.*
```
### 2.2 TTL Applicable Rules
When a device is subject to multiple TTL rules, the more precise and longer rules are prioritized. For example, for the device "root.bj.hd.dist001.turbine001", the rule "root.bj.hd.dist001.turbine001" takes precedence over "root.bj.hd.dist001.\*\*", and the rule "root.bj.hd.dist001.\*\*" takes precedence over "root.bj.hd.**".
### 2.3 Set TTL
The set ttl operation can be understood as setting a TTL rule, for example, setting ttl to root.sg.group1.** is equivalent to mounting ttl for all devices that can match this path pattern.
The unset ttl operation indicates unmounting TTL for the corresponding path pattern; if there is no corresponding TTL, nothing will be done.
If you want to set TTL to be infinitely large, you can use the INF keyword.
The SQL Statement for setting TTL is as follow:
```
set ttl to pathPattern 360000;
```
Set the Time to Live (TTL) to a pathPattern of 360,000 milliseconds; the pathPattern should not contain a wildcard (\*) in the middle and must end with a double asterisk (\*\*). The pathPattern is used to match corresponding devices.
To maintain compatibility with older SQL syntax, if the user-provided pathPattern matches a database (db), the path pattern is automatically expanded to include all sub-paths denoted by path.\*\*.
For instance, writing "set ttl to root.sg 360000" will automatically be transformed into "set ttl to root.sg.\*\* 360000", which sets the TTL for all devices under root.sg. However, if the specified pathPattern does not match a database, the aforementioned logic will not apply. For example, writing "set ttl to root.sg.group 360000" will not be expanded to "root.sg.group.\*\*" since root.sg.group does not match a database.
It is also permissible to specify a particular device without a wildcard (*).
## 3. Unset TTL

To unset TTL, we can use follwing SQL statement:

```
IoTDB> unset ttl from root.ln
```

After unset TTL, all data will be accepted in `root.ln`.
```
IoTDB> unset ttl from root.sgcc.**
```

Unset the TTL in the `root.sgcc` path.

New syntax
```
IoTDB> unset ttl from root.**
```

Old syntax
```
IoTDB> unset ttl to root.**
```
There is no functional difference between the old and new syntax, and they are compatible with each other.
The new syntax is just more conventional in terms of wording.

Unset the TTL setting for all path pattern.

## 4. Show TTL

To Show TTL, we can use following SQL statement:

show all ttl

```
IoTDB> SHOW ALL TTL
+--------------+--------+
| path| TTL|
| root.**|55555555|
| root.sg2.a.**|44440000|
+--------------+--------+
```

show ttl on pathPattern
```
IoTDB> SHOW TTL ON root.db.**;
+--------------+--------+
| path| TTL|
| root.db.**|55555555|
| root.db.a.**|44440000|
+--------------+--------+
```

The SHOW ALL TTL example gives the TTL for all path patterns.
The SHOW TTL ON pathPattern shows the TTL for the path pattern specified.

Display devices' ttl
```
IoTDB> show devices
+---------------+---------+---------+
| Device|IsAligned| TTL|
+---------------+---------+---------+
|root.sg.device1| false| 36000000|
|root.sg.device2| true| INF|
+---------------+---------+---------+
```
All devices will definitely have a TTL, meaning it cannot be null. INF represents infinity.
Loading