-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
DOCSUP-3122: Document two expressions ALTER #17059
Changes from all commits
de5ed99
c6e7f7c
d9e2c92
47169cb
89ba453
05657b1
0042c4e
6111601
ac4e995
528dca0
3286ce1
e85a6c4
ba2c53c
dc6a6a4
2321d95
0c2b418
8b03bef
6b5a313
0892136
cbad45b
a3b63b8
cb2c4d3
fb966f3
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 |
---|---|---|
|
@@ -3,10 +3,83 @@ toc_priority: 44 | |
toc_title: TTL | ||
--- | ||
|
||
### Manipulations with Table TTL {#manipulations-with-table-ttl} | ||
# Manipulations with Table TTL {#manipulations-with-table-ttl} | ||
|
||
## MODIFY TTL {#modify-ttl} | ||
|
||
You can change [table TTL](../../../engines/table-engines/mergetree-family/mergetree.md#mergetree-table-ttl) with a request of the following form: | ||
|
||
``` sql | ||
ALTER TABLE table-name MODIFY TTL ttl-expression | ||
ALTER TABLE table_name MODIFY TTL ttl_expression; | ||
``` | ||
|
||
## REMOVE TTL {#remove-ttl} | ||
|
||
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. "#" missed in anchor. Should be {#remove-ttl} |
||
TTL-property can be removed from table with the following query: | ||
|
||
```sql | ||
ALTER TABLE table_name REMOVE TTL | ||
``` | ||
|
||
**Example** | ||
|
||
Consider the table with table `TTL`: | ||
|
||
```sql | ||
CREATE TABLE table_with_ttl | ||
( | ||
event_time DateTime, | ||
UserID UInt64, | ||
Comment String | ||
) | ||
ENGINE MergeTree() | ||
ORDER BY tuple() | ||
TTL event_time + INTERVAL 3 MONTH; | ||
SETTINGS min_bytes_for_wide_part = 0; | ||
|
||
INSERT INTO table_with_ttl VALUES (now(), 1, 'username1'); | ||
|
||
INSERT INTO table_with_ttl VALUES (now() - INTERVAL 4 MONTH, 2, 'username2'); | ||
``` | ||
|
||
Run `OPTIMIZE` to force `TTL` cleanup: | ||
|
||
```sql | ||
OPTIMIZE TABLE table_with_ttl FINAL; | ||
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. No table definition and now info about data. How reader can guess it? |
||
SELECT * FROM table_with_ttl FORMAT PrettyCompact; | ||
``` | ||
Second row was deleted from table. | ||
|
||
```text | ||
┌─────────event_time────┬──UserID─┬─────Comment──┐ | ||
│ 2020-12-11 12:44:57 │ 1 │ username1 │ | ||
└───────────────────────┴─────────┴──────────────┘ | ||
``` | ||
|
||
Now remove table `TTL` with the following query: | ||
|
||
```sql | ||
ALTER TABLE table_with_ttl REMOVE TTL; | ||
``` | ||
|
||
Re-insert the deleted row and force the `TTL` cleanup again with `OPTIMIZE`: | ||
|
||
```sql | ||
INSERT INTO table_with_ttl VALUES (now() - INTERVAL 4 MONTH, 2, 'username2'); | ||
OPTIMIZE TABLE table_with_ttl FINAL; | ||
SELECT * FROM table_with_ttl FORMAT PrettyCompact; | ||
``` | ||
|
||
The `TTL` is no longer there, so the second row is not deleted: | ||
|
||
```text | ||
┌─────────event_time────┬──UserID─┬─────Comment──┐ | ||
│ 2020-12-11 12:44:57 │ 1 │ username1 │ | ||
│ 2020-08-11 12:44:57 │ 2 │ username2 │ | ||
└───────────────────────┴─────────┴──────────────┘ | ||
``` | ||
|
||
### See Also | ||
|
||
- More about the [TTL-expression](../../../sql-reference/statements/create/table#ttl-expression). | ||
- Modify column [with TTL](../../../sql-reference/statements/alter/column#alter_modify-column). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,82 @@ toc_title: TTL | |
|
||
# Манипуляции с TTL таблицы {#manipuliatsii-s-ttl-tablitsy} | ||
|
||
## MODIFY TTL {#modify-ttl} | ||
|
||
Вы можете изменить [TTL для таблицы](../../../engines/table-engines/mergetree-family/mergetree.md#mergetree-column-ttl) запросом следующего вида: | ||
|
||
``` sql | ||
ALTER TABLE table-name MODIFY TTL ttl-expression | ||
``` | ||
|
||
[Оригинальная статья](https://clickhouse.tech/docs/ru/query_language/alter/ttl/) <!--hide--> | ||
## REMOVE TTL {#remove-ttl} | ||
|
||
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. "#" missed in anchor. Should be {#remove-ttl} |
||
Удалить табличный TTL можно запросом следующего вида: | ||
|
||
```sql | ||
ALTER TABLE table_name REMOVE TTL | ||
``` | ||
|
||
**Пример** | ||
|
||
Создадим таблицу с табличным `TTL` и заполним её данными: | ||
|
||
```sql | ||
CREATE TABLE table_with_ttl | ||
( | ||
event_time DateTime, | ||
UserID UInt64, | ||
Comment String | ||
) | ||
ENGINE MergeTree() | ||
ORDER BY tuple() | ||
TTL event_time + INTERVAL 3 MONTH; | ||
SETTINGS min_bytes_for_wide_part = 0; | ||
|
||
INSERT INTO table_with_ttl VALUES (now(), 1, 'username1'); | ||
|
||
INSERT INTO table_with_ttl VALUES (now() - INTERVAL 4 MONTH, 2, 'username2'); | ||
``` | ||
|
||
Выполним `OPTIMIZE` для принудительной очистки по `TTL`: | ||
|
||
```sql | ||
OPTIMIZE TABLE table_with_ttl FINAL; | ||
SELECT * FROM table_with_ttl; | ||
``` | ||
В результате видно, что вторая строка удалена. | ||
|
||
```text | ||
┌─────────event_time────┬──UserID─┬─────Comment──┐ | ||
│ 2020-12-11 12:44:57 │ 1 │ username1 │ | ||
└───────────────────────┴─────────┴──────────────┘ | ||
``` | ||
|
||
Удаляем табличный `TTL`: | ||
|
||
```sql | ||
ALTER TABLE table_with_ttl REMOVE TTL; | ||
``` | ||
|
||
Заново вставляем удаленную строку и снова принудительно запускаем очистку по `TTL` с помощью `OPTIMIZE`: | ||
|
||
```sql | ||
INSERT INTO table_with_ttl VALUES (now() - INTERVAL 4 MONTH, 2, 'username2'); | ||
OPTIMIZE TABLE table_with_ttl FINAL; | ||
SELECT * FROM table_with_ttl; | ||
``` | ||
|
||
`TTL` больше нет, поэтому данные не удаляются: | ||
|
||
```text | ||
┌─────────event_time────┬──UserID─┬─────Comment──┐ | ||
│ 2020-12-11 12:44:57 │ 1 │ username1 │ | ||
│ 2020-08-11 12:44:57 │ 2 │ username2 │ | ||
└───────────────────────┴─────────┴──────────────┘ | ||
``` | ||
|
||
### Смотрите также | ||
|
||
- Подробнее о [свойстве TTL](../../../engines/table-engines/mergetree-family/mergetree#table_engine-mergetree-ttl). | ||
|
||
[Оригинальная статья](https://clickhouse.tech/docs/ru/query_language/alter/ttl/) <!--hide--> |
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.
Missed anchor here