[TDR Generic Table] [MySQL Protocol Compatibility Interface] TTL
1. Attribute Description
TTL is the abbreviation of Time To Live. It is used to indicate how long after a record expires. Expired records will no longer be accessible and will be deleted asynchronously by the system. TTL is the built-in field of TcaplusDB. It is represented by __ttl__, in milliseconds, and is the relative time.
The default value of __ttl__ field of a record is 0, which means that the record will never expire; If the value of __ttl__ field of a record is set to 1000, it means that the record expires after 1000 milliseconds.
2. Preparations
Refer to Preparation document, create mysql_table table, and use MySQL Client to connect to TcaplusDB successfully.
3. Limitations
For a record with TTL set, if it is an index query and only needs to return the key field (that is, it does not need to return the value field), it will not check whether the record is expired, that is, it may return the key field of the expired record.
If TTL has not been set for the record before,
__ttl__ = __ttl__ + xis equivalent to__ttl__ = x, and__ttl__ = __ttl__ - x (x > 0)is equivalent to making the records expire immediately; If TTL has been set for the record before, and the value of record__ttl__field is a when the current request is executed, then__ttl__ = __ttl__ - b (a < b)is equivalent to making the record expire immediately.
4. SQL Examples
- Set TTL to 10 seconds while inserting records into
mysql_tabletable, SQL statement has the following two forms:
INSERT INTO mysql_table (k1, k2, k3, v1, v2, v3, v4, __ttl__) VALUES (1, 2, 'one', 4, 5, 6.6, 'value4', 10000);
INSERT INTO mysql_table (k1, k2, k3, v1, v2, v3, v4, __ttl__) VALUES (1, 2, 'one', 4, 5, 6.6, 'value4', 10000) ON DUPLICATE KEY UPDATE;
- Query TTL while getting records from
mysql_tabletable, SQL statement has the following two forms:
SELECT k1, v1, __ttl__ FROM mysql_table WHERE k1=1 AND k2=2 AND k3='one';
- Update TTL while updating records to
mysql_tabletable, SQL statement has the following two forms:
UPDATE mysql_table SET v1=v1+1, v2=v2-2, __ttl__=__ttl__+10000 WHERE k1=1 AND k2=2 AND k3='one';
5. FAQ
For details, see Meaning and Handling of Error Codes.
6. Other Reference Documents
[TDR Generic Table] [C++ SDK] Interface Description for Setting Record Expiration
[TDR Generic Table] [Java SDK] Interface Description for Setting Record Expiration
[TDR Generic Table] [C++ SDK] Interface Description for Getting Data Expiration
[TDR Generic Table] [Go SDK] Interface Description for Getting Data Expiration