forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[doc] ttl doc modification (vesoft-inc#1939)
* ttl doc modification * fix comments * yt comments * silver days comments * timestamp update
- Loading branch information
Showing
2 changed files
with
76 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 59 additions & 27 deletions
86
...nual-EN/2.query-language/4.statement-syntax/1.data-definition-statements/TTL.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,111 @@ | ||
# TTL (time-to-live) | ||
|
||
With **TTL**, **Nebula Graph** provides the ability to filter the expired data automatically when traversing vertices and edges. The system will automatically delete the expired data during the compaction phase, without a delete operation that is explicitly issued by the console. | ||
With **TTL**, **Nebula Graph** provides the ability to delete the expired vertices or edges automatically. The system will automatically delete the expired data during the compaction phase. Before compaction, query will filter the expired data. | ||
|
||
`ttl_col` indicates the TTL column, while `ttl_duration` indicates the duration of the TTL. When the sum of the TTL column and the ttl_duration is less than the current time, we consider the data as expired. The `ttl_col` type is integer or timestamp, and is set in seconds. `ttl_duration` is also set in seconds. | ||
TTl requires `ttl_col` and `ttl_duration` together. `ttl_col` indicates the TTL column, while `ttl_duration` indicates the duration of the TTL. When the sum of the TTL column and the ttl_duration is less than the current time, we consider the data as expired. The `ttl_col` type is integer or timestamp, and is set in seconds. `ttl_duration` is also set in seconds. | ||
|
||
## TTL configurations | ||
## TTL configuration | ||
|
||
The time to live value is set in seconds. | ||
- The `ttl_duration` is set in seconds. If it is set to -1 or 0, the vertex properties of this tag does not expire. | ||
|
||
- If TTL is set, when the sum of the `ttl_col` and the `ttl_duration` is less than the current time, we consider the data as expired. | ||
- If TTL is set, when the sum of the `ttl_col` and the `ttl_duration` is less than the current time, we consider the vertex properties of this tag as expired after the specified seconds configured by `ttl_duration` has passed since the `ttl_col` field value. | ||
|
||
- If TTL is not set or the `ttl_col` is null, then the time to live has no effect. | ||
|
||
- If TTL is set to -1 or 0, then data in the field does not expire. | ||
- When the vertex has multiple tags, the TTL of each tag is processed separately. | ||
|
||
## Setting a TTL Value | ||
|
||
Setting a TTL value allows you to specify the living time of the data. | ||
- Setting a TTL value for the existed tag. | ||
|
||
```ngql | ||
nebula> CREATE TAG t1(a timestamp); | ||
nebula> ALTER TAG t1 ttl_col = "a", ttl_duration = 5; -- Setting ttl | ||
nebula> INSERT VERTEX t1(a) values 101:(now()); | ||
``` | ||
|
||
Creating a tag then adding TTL attribute. | ||
The vertex 101 property in tag t1 will expire after 5 seconds since specified by now(). | ||
|
||
- Or you can set the TTL attribute when creating the tag. | ||
|
||
```ngql | ||
nebula> CREATE TAG t(a int, b int, c string); | ||
nebula> ALTER TAG t ADD ttl_col = "a", ttl_duration = 1000; -- add ttl attribute | ||
nebula> SHOW CREATE TAG t; | ||
nebula> CREATE TAG t2(a int, b int, c string) ttl_duration= 100, ttl_col = "a"; | ||
nebula> INSERT VERTEX t2(a, b, c) values 102:(1584441231, 30, "Word"); | ||
``` | ||
|
||
Or you can set the TTL attribute when creating the tag. | ||
The vertex 102 property in tag t2 will expire after 100 seconds since March 17 2020 at 18:33:51 CST i.e. the timestamp is 1584441231. | ||
|
||
- When a vertex has multiple TAGs, the TTL of each TAG is independent from each other. | ||
|
||
```ngql | ||
nebula> CREATE TAG t(a int, b int, c string) ttl_duration= 100, ttl_col = "a"; | ||
nebula> CREATE TAG t3(a string); | ||
nebula> INSERT VERTEX t1(a),t3(a) values 200:(now(), "hello"); | ||
``` | ||
|
||
## Dropping TTL | ||
The vertex 200 property in tag t1 will expire after 5 seconds. | ||
|
||
If you have set a TTL value for a field and later decide do not want it to ever automatically expire, you can drop the TTL value or invalidate it. For example, using the previous example. | ||
```ngql | ||
nebula> FETCH PROP ON t1 200; | ||
Execution succeeded (Time spent: 5.945/7.492 ms) | ||
nebula> FETCH PROP ON t3 200; | ||
====================== | ||
| VertexID | t3.a | | ||
====================== | ||
| 200 | hello | | ||
---------------------- | ||
nebula> FETCH PROP ON * 200; | ||
====================== | ||
| VertexID | t3.a | | ||
====================== | ||
| 200 | hello | | ||
---------------------- | ||
``` | ||
|
||
## Dropping TTL | ||
|
||
Drop the TTL attribute: | ||
If you have set a TTL value for a field and later decide do not want it to ever automatically expire, you can drop the TTL value, set it to an empty string or invalidate it by setting it to 0 or -1. | ||
|
||
```ngql | ||
nebula> ALTER TAG t ttl_col = ""; -- drop ttl attribute | ||
nebula> ALTER TAG t1 ttl_col = ""; -- drop ttl attribute; | ||
``` | ||
|
||
Drop the field a with the ttl attribute: | ||
|
||
```ngql | ||
nebula> ALTER TAG t DROP a; -- drop field a with the ttl attribute | ||
nebula> ALTER TAG t1 DROP (a); -- drop ttl_col | ||
``` | ||
|
||
Invalidate the TTL: | ||
|
||
```ngql | ||
nebula> ALTER TAG t ttl_duration = 0; -- keep the ttl but the data never expires | ||
nebula> ALTER TAG t1 ttl_duration = 0; -- keep the ttl but the data never expires | ||
``` | ||
|
||
## Tips on TTL | ||
|
||
- If a field contains a TTL value, you can't make any change on the field. | ||
- If a field contains a `ttl_col` field, you can't make any change on the field. | ||
|
||
``` ngql | ||
nebula> ALTER TAG t ADD ttl_col = "b", ttl_duration = 1000; | ||
nebula> ALTER TAG t CHANGE (b string); -- failed | ||
nebula> CREATE TAG t1(a int, b int, c string) ttl_duration = 100, ttl_col = "a"; | ||
nebula> ALTER TAG t1 CHANGE (a string); -- failed | ||
``` | ||
|
||
- Note that the a tag or an edge cannot have both the TTL attribute and index at the same time. | ||
- Note that the a tag or an edge cannot have both the TTL attribute and index at the same time, even if the `ttl_col` column is different from that of the index. | ||
|
||
``` ngql | ||
nebula> CREATE TAG t(a int, b int, c string) ttl_duration = 100, ttl_col = "a"; | ||
nebula> CREATE TAG t1(a int, b int, c string) ttl_duration = 100, ttl_col = "a"; | ||
nebula> CREATE TAG INDEX id1 ON t(a); -- failed | ||
``` | ||
|
||
``` ngql | ||
nebula> CREATE TAG t1(a int, b int, c string) ttl_duration = 100, ttl_col = "a"; | ||
nebula> CREATE TAG INDEX id1 ON t(b); -- failed | ||
``` | ||
|
||
```ngql | ||
nebula> CREATE TAG t1(a int, b int, c string); | ||
nebula> CREATE TAG INDEX id1 ON t1(a); | ||
nebula> ALTER TAG t1 ADD ttl_col = "a", ttl_duration = 100; -- failed | ||
nebula> ALTER TAG t1 ttl_col = "a", ttl_duration = 100; -- failed | ||
``` | ||
|
||
- Adding TTL to an edge is similar to a tag. |