-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: RFC for TTL tables #39264
docs: RFC for TTL tables #39264
Changes from 1 commit
1c327a1
6cb2c91
91f78ac
02c30ac
e201649
25850fa
56f9da4
cb6b2d3
dbeeba5
d2a9605
3868907
bfe2ed7
4867da9
ce3fb33
501a330
c75ff9e
18fe079
e19989e
3511a2b
fa73868
51b87b7
29e3726
d4196fa
49b388a
a0137d3
c2f27da
2d094f2
7200043
9301a17
3a759ff
4b5aa55
1e6585c
630b1e6
2020fac
a290eea
c0cbec0
ed0c3f8
41b45fb
4a0cf1e
f9b0515
88b0077
a202c34
87c3465
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ The following example shows how to create a TTL table. The column `create_at` is | |
CREATE TABLE t1 ( | ||
id int PRIMARY KEY, | ||
created_at TIMESTAMP | ||
) TTL = `created_at` + INTERVAL 3 MONTHS; | ||
) TTL = `created_at` + INTERVAL 3 MONTH; | ||
``` | ||
|
||
We can use another `TTL_ENABLE` option to disable/enable the TTL job for the table. For example: | ||
|
@@ -57,7 +57,7 @@ We can use another `TTL_ENABLE` option to disable/enable the TTL job for the tab | |
CREATE TABLE t1 ( | ||
id int PRIMARY KEY, | ||
created_at TIMESTAMP | ||
) TTL = `created_at` + INTERVAL 3 MONTHS TTL_ENABLE = 'OFF'; | ||
) TTL = `created_at` + INTERVAL 3 MONTH TTL_ENABLE = 'OFF'; | ||
``` | ||
|
||
The above table will not delete expired rows automatically because `TTL_ENABLE` is set to `OFF`. When the `TTL_ENABLE` is omitted, it uses value `ON` by default. | ||
|
@@ -68,15 +68,15 @@ To make it compatible with mysql, TTL options also support the comment format. F | |
CREATE TABLE t1 ( | ||
id int PRIMARY KEY, | ||
created_at TIMESTAMP | ||
) /*T![ttl] TTL = `created_at` + INTERVAL 3 MONTHS TTL_ENABLE = 'OFF'*/; | ||
) /*T![ttl] TTL = `created_at` + INTERVAL 3 MONTH TTL_ENABLE = 'OFF'*/; | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the doc. We dont want to modify existing schema to add a 'DateTime' or 'Date' field, which may cause a lot of existing data to be rewritten. If so, can you please help document that (how to enable that on existing tables using long in a light way(without rewriting data))? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it supports generated column with some limitations. Because currently generated column can not be pushed down, so it make take more performance, we'll optimize it in the future. It is documented: https://github.com/pingcap/tidb/pull/39264/files#diff-3199b62f6b171f846c9c0c1670428817d339e0e2ee2b2a35822df8f532c51e58R202 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the quick response! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lcwangchao |
||
|
||
#### Alter a Table with TTL | ||
|
||
We can alter an exist table with TTL options, for example: | ||
|
||
```sql | ||
ALTER TABLE t1 TTL = `created_at` + INTERVAL 3 MONTHS; | ||
ALTER TABLE t1 TTL = `created_at` + INTERVAL 3 MONTH; | ||
``` | ||
|
||
We should allow to update the existed TTL options. When it is updated, the running background job for this table should stop or restart according to the newest settings. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we pass -3 MONTH here?
btw, seem here should be "3 MONTHS", plural.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, I prefer Spanner's TTL Clause https://cloud.google.com/spanner/docs/ttl/working-with-ttl#postgresql
creating a TTL "ON" a column may be more straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is allowed currently, but meaningless in most times. If one row is created using the real time, it will be deleted after next job scheduled, so it equals to setting the expire interval to a very small value. If user sets a time in one row with a past time, it may be some different, but I don't know any scene requires it. Maybe we can disallow user to setting it a a negative value or just leave it alone because it will not bring some big problem.
We are using an expression to parse the duration, so, it supports both
3 MONTH
and3 MONTHS
. I can update it plural in doc to make it more naturalI do not have a strong preference, PTAL @SunRunAway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer keeping it as an expression syntax instead of a particular syntax because there may be more syntax extensions in the future if you don't have a strong opinion.