Skip to content

Commit a301301

Browse files
authored
Merge pull request #4046 from ClickHouse/melvynator-patch-4
Fix the documentation page to align with the new lightweight update page
2 parents 53e8a8e + c402a43 commit a301301

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

docs/guides/developer/lightweight-update.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
22
slug: /guides/developer/lightweight-update
3-
sidebar_label: 'Lightweight Update'
4-
title: 'Lightweight Update'
5-
keywords: ['lightweight update']
6-
description: 'Provides a description of lightweight updates'
3+
sidebar_label: 'On-the-fly mutation'
4+
title: 'On-the-fly Mutations'
5+
keywords: ['On-the-fly mutation']
6+
description: 'Provides a description of on-the-fly mutations'
77
---
88

9-
## Lightweight Update {#lightweight-update}
9+
## On-the-fly mutations {#lightweight-update}
1010

11-
When lightweight updates are enabled, updated rows are marked as updated immediately and subsequent `SELECT` queries will automatically return with the changed values. When lightweight updates are not enabled, you may have to wait for your mutations to be applied via a background process to see the changed values.
11+
When on-the-fly mutations are enabled, updated rows are marked as updated immediately and subsequent `SELECT` queries will automatically return with the changed values. When on-the-fly mutations are not enabled, you may have to wait for your mutations to be applied via a background process to see the changed values.
1212

13-
Lightweight updates can be enabled for `MergeTree`-family tables by enabling the query-level setting `apply_mutations_on_fly`.
13+
On-the-fly mutations can be enabled for `MergeTree`-family tables by enabling the query-level setting `apply_mutations_on_fly`.
1414

1515
```sql
1616
SET apply_mutations_on_fly = 1;
@@ -24,7 +24,7 @@ CREATE TABLE test_on_fly_mutations (id UInt64, v String)
2424
ENGINE = MergeTree ORDER BY id;
2525

2626
-- Disable background materialization of mutations to showcase
27-
-- default behavior when lightweight updates are not enabled
27+
-- default behavior when on-the-fly mutations are not enabled
2828
SYSTEM STOP MERGES test_on_fly_mutations;
2929
SET mutations_sync = 0;
3030

@@ -39,8 +39,9 @@ ALTER TABLE test_on_fly_mutations DELETE WHERE v = 'e';
3939
```
4040

4141
Let's check the result of the updates via a `SELECT` query:
42+
4243
```sql
43-
-- Explicitly disable lightweight updates
44+
-- Explicitly disable on-the-fly-mutations
4445
SET apply_mutations_on_fly = 0;
4546

4647
SELECT id, v FROM test_on_fly_mutations ORDER BY id;
@@ -56,10 +57,10 @@ Note that the values of the rows have not yet been updated when we query the new
5657
└────┴───┘
5758
```
5859

59-
Let's now see what happens when we enable lightweight updates:
60+
Let's now see what happens when we enable on-the-fly mutations:
6061

6162
```sql
62-
-- Enable lightweight updates
63+
-- Enable on-the-fly mutations
6364
SET apply_mutations_on_fly = 1;
6465

6566
SELECT id, v FROM test_on_fly_mutations ORDER BY id;
@@ -73,17 +74,17 @@ The `SELECT` query now returns the correct result immediately, without having to
7374
└────┴───┘
7475
```
7576

76-
## Performance Impact {#performance-impact}
77+
## Performance impact {#performance-impact}
7778

78-
When lightweight updates are enabled, mutations are not materialized immediately but will only be applied during `SELECT` queries. However, please note that mutations are still being materialized asynchronously in the background, which is a heavy process.
79+
When on-the-fly mutations are enabled, mutations are not materialized immediately but will only be applied during `SELECT` queries. However, please note that mutations are still being materialized asynchronously in the background, which is a heavy process.
7980

8081
If the number of submitted mutations constantly exceeds the number of mutations that are processed in the background over some time interval, the queue of unmaterialized mutations that have to be applied will continue to grow. This will result in the eventual degradation of `SELECT` query performance.
8182

8283
We suggest enabling the setting `apply_mutations_on_fly` together with other `MergeTree`-level settings such as `number_of_mutations_to_throw` and `number_of_mutations_to_delay` to restrict the infinite growth of unmaterialized mutations.
8384

8485
## Support for subqueries and non-deterministic functions {#support-for-subqueries-and-non-deterministic-functions}
8586

86-
Lightweight updates have limited support with subqueries and non-deterministic functions. Only scalar subqueries with a result that have a reasonable size (controlled by the setting `mutations_max_literal_size_to_replace`) are supported. Only constant non-deterministic functions are supported (e.g. the function `now()`).
87+
On-the-fly mutations have limited support with subqueries and non-deterministic functions. Only scalar subqueries with a result that have a reasonable size (controlled by the setting `mutations_max_literal_size_to_replace`) are supported. Only constant non-deterministic functions are supported (e.g. the function `now()`).
8788

8889
These behaviours are controlled by the following settings:
8990

docs/managing-data/updating-data/overview.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ There are several ways to update data in ClickHouse, each with its own advantage
1818
For both operations, if the number of submitted mutations constantly exceeds the number of mutations that are processed in the background over some time interval, the queue of non-materialized mutations that have to be applied will continue to grow. This will result in the eventual degradation of `SELECT` query performance.
1919

2020
In summary, update operations should be issued carefully, and the mutations queue should be tracked closely using the `system.mutations` table. Do not issue updates frequently as you would in OLTP databases. If you have a requirement for frequent updates, see [ReplacingMergeTree](/engines/table-engines/mergetree-family/replacingmergetree).
21-
2221
| Method | Syntax | When to use |
2322
|---------------------------------------------------------------------------------------|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2423
| [Update mutation](/sql-reference/statements/alter/update) | `ALTER TABLE [table] UPDATE` | Use when data must be updated to disk immediately (e.g. for compliance). Negatively affects `SELECT` performance. |
25-
| [Lightweight update](/guides/developer/lightweight-update) | `ALTER TABLE [table] UPDATE` | Enable using `SET apply_mutations_on_fly = 1;`. Use when updating small amounts of data. Rows are immediately returned with updated data in all subsequent `SELECT` queries but are initially only internally marked as updated on disk. |
24+
| [Lightweight updates](/sql-reference/statements/update) | `UPDATE [table] SET ... WHERE` | Use for updating small amounts of data (up to ~10% of table). Creates patch parts for immediate visibility without rewriting entire columns. Adds overhead to `SELECT` queries but has predictable latency. Currently experimental. |
25+
| [On-the-fly updates](/guides/developer/lightweight-update) | `ALTER TABLE [table] UPDATE` | Enable using `SET apply_mutations_on_fly = 1;`. Use when updating small amounts of data. Rows are immediately returned with updated data in all subsequent `SELECT` queries but are initially only internally marked as updated on disk. |
2626
| [ReplacingMergeTree](/engines/table-engines/mergetree-family/replacingmergetree) | `ENGINE = ReplacingMergeTree` | Use when updating large amounts of data. This table engine is optimized for data deduplication on merges. |
2727
| [CollapsingMergeTree](/engines/table-engines/mergetree-family/collapsingmergetree) | `ENGINE = CollapsingMergeTree(Sign)` | Use when updating individual rows frequently, or for scenarios where you need to maintain the latest state of objects that change over time. For example, tracking user activity or article stats. |
28-
2928
Here is a summary of the different ways to update data in ClickHouse:
3029

3130
## Update Mutations {#update-mutations}
@@ -40,9 +39,21 @@ These are extremely IO-heavy, rewriting all the parts that match the `WHERE` exp
4039

4140
Read more about [update mutations](/sql-reference/statements/alter/update).
4241

43-
## Lightweight Updates {#lightweight-updates}
42+
## Lightweight updates {#lightweight-updates}
43+
44+
Lightweight updates are a ClickHouse feature that updates rows using "patch parts" - special data parts containing only the updated columns and rows, rather than rewriting entire columns like traditional mutations. The Lightweight UPDATE
45+
Key characteristics:
46+
47+
- Uses the standard `UPDATE` syntax and creates patch parts immediately without waiting for merges
48+
- Updated values are immediately visible in `SELECT` queries through patch application, but physically materialized only during subsequent merges
49+
- Designed for small updates (up to ~10% of table) with predictable latency
50+
- Adds overhead to `SELECT` queries that need to apply patches, but avoids rewriting entire columns
51+
52+
For more details see ["The Lightweight UPDATE Statement"](/sql-reference/statements/update)
53+
54+
## On-the-fly Updates {#on-the-fly-updates}
4455

45-
Lightweight updates provide a mechanism to update rows such that they are updated immediately, and subsequent `SELECT` queries will automatically return with the changed values (this incurs an overhead and will slow queries). This effectively addresses the atomicity limitation of normal mutations. We show an example below:
56+
On-the-fly updates provide a mechanism to update rows such that they are updated immediately, and subsequent `SELECT` queries will automatically return with the changed values (this incurs an overhead and will slow queries). This effectively addresses the atomicity limitation of normal mutations. We show an example below:
4657

4758
```sql
4859
SET apply_mutations_on_fly = 1;
@@ -52,7 +63,7 @@ FROM posts
5263
WHERE Id = 404346
5364

5465
┌─ViewCount─┐
55-
26762
66+
26762
5667
└───────────┘
5768

5869
1 row in set. Elapsed: 0.115 sec. Processed 59.55 million rows, 238.25 MB (517.83 million rows/s., 2.07 GB/s.)
@@ -73,9 +84,9 @@ WHERE Id = 404346
7384
1 row in set. Elapsed: 0.149 sec. Processed 59.55 million rows, 259.91 MB (399.99 million rows/s., 1.75 GB/s.)
7485
```
7586

76-
Note that for lightweight updates, a mutation is still used to update the data; it is just not materialized immediately and applied during `SELECT` queries. It will still be applied in the background as an asynchronous process and incurs the same heavy overhead as a mutation and thus is an I/O intense operation that should be used sparingly. The expressions that can be used with this operation are also limited (see here for [details](/guides/developer/lightweight-update#support-for-subqueries-and-non-deterministic-functions)).
87+
Note that for on-the-fly updates, a mutation is still used to update the data; it is just not materialized immediately and applied during `SELECT` queries. It will still be applied in the background as an asynchronous process and incurs the same heavy overhead as a mutation and thus is an I/O intense operation that should be used sparingly. The expressions that can be used with this operation are also limited (see here for [details](/guides/developer/lightweight-update#support-for-subqueries-and-non-deterministic-functions)).
7788

78-
Read more about [lightweight updates](/guides/developer/lightweight-update).
89+
Read more about [on-the-fly updates](/guides/developer/lightweight-update).
7990

8091
## Collapsing Merge Tree {#collapsing-merge-tree}
8192

0 commit comments

Comments
 (0)