CREATE TTL statement¶
The CREATE TTL statement sets a time-to-live (TTL) duration on graph elements by element type. Currently, TTL durations can be set on only edges in a graph.
To specify the graph, use either of the following methods:
- Add a USE clause before this statement to set the working graph.
- Use SESSION SET to set the graph for the current session in advance.
If both methods are used, the one specified in the USE clause takes precedence. If neither is used, an error occurs.
TTL is a mechanism used in NebulaGraph Database Developer Edition to define lifespans for graph elements. After its lifespan expires, the graph element is no longer retrievable in queries, but it is not immediately deleted from the Storage service. The actual deletion happens during the next compaction operation.
Note
An operation involving a non-default schema or an object in it requires access to the schema, either implicitly or through an explicit USAGE grant, as well as the privilege required for the operation. The schema access check and the privilege check for the requested operation are independent; satisfying one does not satisfy the other. Schema access control does not apply to temporary graphs or built-in procedures and functions. For more information, see Schema access control.
Prerequisites¶
- A graph is created and at least one edge type of the graph has a property of data type
ZONED DATETIME. For more information, see CREATE GRAPH.
- To set a TTL duration, you must either be the owner of the graph, be granted to perform the action
ALTERon the graph, or be granted to perform the actionALTER ANY GRAPHon the used schema. For more information, see Roles and privileges.
Limitations¶
- TTL durations can be set on properties of edge types only, which are known as TTL properties.
- For each edge type, only one TTL property can be specified.
- TTL properties must be of date type
ZONED DATETIME. - TTL durations must be specified in days, hours, minutes, seconds, milliseconds, or microseconds.
Syntax¶
- create_ttl_statement
create_ttl_statement ::=
'CREATE' 'TTL' 'ON' 'EDGE' edge_type_name '(' property_name ')' ttl_duration
Parameters¶
edge_type_name¶
The name of the edge type for which you want to set the TTL duration.
property_name¶
The name of the property of the edge type based on which you want to set the TTL duration. The property must be of data type ZONED DATETIME. For more information, see Temporal instants.
If the sum of the property's value and the TTL duration (ttl_duration) is earlier than the current time, the edge with this property is considered expired and is deleted in the next compaction operation.
If the value of the property is NULL, the edge with this property never expires.
ttl_duration¶
A duration value that specifies the TTL duration. The duration value must be larger than 0 and specified by using the function duration() in days, hours, minutes, seconds, milliseconds, or microseconds.
Examples¶
The following examples are based on the example dataset.
Set a TTL duration on an edge type¶
'''
// Add a property of data type ZONED DATETIME to edge type Watch
ALTER GRAPH TYPE movie_type {
ALTER EDGE TYPE Watch ADD PROPERTIES {ttl_test ZONED DATETIME DEFAULT zoned_datetime("1990-01-01T05:06:07.0890", "%Y-%m-%dT%H:%M:%S") }
}
'''
'''
// Set a TTL duration on the edge type Watch
USE movie CREATE TTL ON EDGE Watch(ttl_test) duration({days:1, hours:2, minutes:3, seconds:4, milliseconds:5, microseconds:6})
'''