Skip to content

Add the create_union_system_log_tables configuration option to create and update all_... system log tables - #112670

Merged
alexey-milovidov merged 2 commits into
masterfrom
union-system-log-tables
Aug 1, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
union-system-log-tables

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

Closes: #112653

A new optional server configuration section, create_union_system_log_tables, requests the creation of all_... tables next to the system log tables (system.all_query_log for system.query_log and so on). Such a table is a union of the corresponding log table, its rotated versions (query_log_0, query_log_1, ...) and/or the same tables across all replicas of a cluster — an equivalent of clusterAllReplicas(default, merge(system, '^query_log')) SETTINGS skip_unavailable_shards = 1 that you don't have to remember, with the table structure automatically kept up to date with the structure of the latest table.

<create_union_system_log_tables>
    <merge_rotated_tables>true</merge_rotated_tables>
    <cluster>default</cluster>
</create_union_system_log_tables>

At least one of merge_rotated_tables and cluster has to be specified; they define whether the table is a merge of the rotated tables, a distributed table over all replicas of a cluster, or a combination of both. The option applies to all system log tables.

The union table is a CREATE TABLE system.all_query_log (<columns of the log table>) AS merge('system', '^query_log(_[0-9]+)?$') / AS clusterAllReplicas('default', ..., SETTINGS skip_unavailable_shards = 1) proxy table. SystemLog verifies it against the expected definition at the first flush and at every rotation of the log table and recreates it with an atomic exchange (CREATE OR REPLACE) when it differs; if the table is dropped by a user, it is recreated at the next flush. The tables have no state, so it is always safe to drop them. Creation is supported only in Atomic, Replicated and Shared databases and is skipped otherwise. Failures to create the union table (e.g. a misconfigured cluster) are logged and never interfere with flushing the log itself.

To support skip_unavailable_shards in the table definition, the remote, remoteSecure, cluster and clusterAllReplicas table functions now accept a trailing SETTINGS clause with the settings of the Distributed storage they create (previously such a clause was accepted by mysql, postgresql and other table functions, and the Distributed version of skip_unavailable_shards already existed for the Distributed/Remote engines):

SELECT count() FROM clusterAllReplicas('default', system.query_log, SETTINGS skip_unavailable_shards = 1);
CREATE TABLE t AS remote('127.0.0.{1,2}', system.one, SETTINGS skip_unavailable_shards = 1);

A setting specified in the query has priority over the setting from the table function. CREATE TABLE ... AS table_function(...) now parses the SETTINGS clause too (also required for loading the stored metadata of such tables).

Note: a table definition with a SETTINGS clause inside a table function cannot be loaded by servers of previous versions, so downgrading requires dropping such tables first (this applies to the all_... tables created with the cluster option).

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

A new server configuration section, create_union_system_log_tables, requests the creation and automatic maintenance of all_... tables (e.g. system.all_query_log) that query the union of a system log table, its rotated versions and/or the same tables across all replicas of a cluster. The remote, remoteSecure, cluster and clusterAllReplicas table functions now accept a trailing SETTINGS clause with the settings of the Distributed storage they create, e.g. clusterAllReplicas('default', system.query_log, SETTINGS skip_unavailable_shards = 1).

Version info

  • Merged into: 26.8.1.564 (included in 26.8 and later)

alexey-milovidov and others added 2 commits July 30, 2026 21:45
…functions

The functions now accept a trailing SETTINGS clause with the settings of
the Distributed storage they create, e.g.
clusterAllReplicas('default', system.query_log, SETTINGS skip_unavailable_shards = 1).
A setting specified in the query has priority over the setting from the
table function. CREATE TABLE ... AS table_function(...) now parses the
SETTINGS clause too, and the clause is kept in the stored table definition.

Needed for: #112653

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
When the section is present, SystemLog creates and maintains all_...
tables next to the system log tables (e.g. system.all_query_log): a
union of the log table, its rotated versions (query_log_0, query_log_1,
...) and/or the same tables across all replicas of a cluster, as
requested by the merge_rotated_tables and cluster settings.

The union table is a proxy table over the merge / clusterAllReplicas
table functions (with SETTINGS skip_unavailable_shards = 1 in the
cluster case) with the columns pinned to the current structure of the
log. It is verified at the first flush and at every rotation of the log
table and recreated with an atomic exchange (CREATE OR REPLACE) when
its definition differs; when dropped by a user, it is recreated at the
next flush. Creation is supported in Atomic, Replicated and Shared
databases and never interferes with flushing the log itself.

Closes: #112653

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d018ffd]

Summary: ✅


AI Review

Summary

This PR adds the create_union_system_log_tables server option and teaches the remote / cluster table-function family to keep an inner SETTINGS clause alive through CREATE TABLE ... AS table_function(...) and metadata reloads. The main implementation looks coherent, but one user-facing contract is left inconsistent: the updated remote documentation now makes the persistent Remote / RemoteSecure counterpart look like it accepts the same new inner-clause syntax even though only the table-function path was extended.

Findings

⚠️ Majors

  • [docs/en/sql-reference/table-functions/remote.md:37] The page now documents SETTINGS ... as part of the remote / remoteSecure parameter list, but the sibling persistent-engine path still does not accept ENGINE = Remote(..., SETTINGS ...): engine arguments are parsed through ParserStorage / ParserFunction() in non-table-function mode, and registerStorageRemote only consumes outer storage_def->settings. Users following the "same parameters" guidance will hit a syntax error instead of getting a persistent counterpart of the documented table-function form.
    Suggested fix: either implement the inner SETTINGS clause for Remote / RemoteSecure as well, or narrow the docs here to say that persistent tables still use outer ENGINE = Remote(...) SETTINGS ....
Final Verdict

Needs a follow-up before merge: keep the Remote / RemoteSecure engine surface aligned with the new table-function syntax, or document the difference explicitly.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jul 30, 2026
@mintlify

mintlify Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Jul 30, 2026, 10:21 PM

| `user` | User name. If not specified, `default` is used. Type: [String](../../sql-reference/data-types/string.md). |
| `password` | User password. If not specified, an empty password is used. Type: [String](../../sql-reference/data-types/string.md). |
| `sharding_key` | Sharding key to support distributing data across nodes. For example: `insert into remote('127.0.0.1:9000,127.0.0.2', db, table, 'default', rand())`. Type: [UInt32](../../sql-reference/data-types/int-uint.md). |
| `SETTINGS name = value, ...` | [Settings of the Distributed table](../../engines/table-engines/special/distributed.md#distributed-settings) created by the function, for example `skip_unavailable_shards`. Optional. A setting specified in the query has priority over it. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new inner SETTINGS syntax is only wired for table-function parsing, not for the persistent Remote / RemoteSecure engine form that this page still presents as the same parameter surface. CREATE TABLE ... AS remote(..., SETTINGS ...) works because ParserCreateQuery now parses AS table functions in table-function mode, but ENGINE = Remote(..., SETTINGS ...) still goes through ParserStorage -> ParserIdentifierWithOptionalParameters -> ParserFunction() and registerStorageRemote only consumes outer storage_def->settings. That leaves users with a syntax error if they carry this new clause over to the engine counterpart. Could we either implement the inner-clause form for Remote / RemoteSecure too, or clarify here that persistent tables must still use ENGINE = Remote(...) SETTINGS ...?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can hand it over to @clickgapai after the PR is merged.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Picked this up as a follow-up: #112884

Confirmed on master (26.8.1.1): ENGINE = Remote('127.0.0.1', system, one, SETTINGS skip_unavailable_shards = 1) is a SYNTAX_ERROR, while ENGINE = Remote('127.0.0.1', system, one) SETTINGS skip_unavailable_shards = 1 works and is preserved in SHOW CREATE TABLE. Since the engines already accept exactly the same settings, just after the engine definition, the follow-up documents the difference on both sides - the remote table-function page and the Remote/RemoteSecure engine description - instead of adding a second syntax to the engines, and adds a test for the engine form, which was not covered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexey-milovidov I looked into #112670 but didn't land on a concrete change to make — the requested work looks like it may already be in the PR, or I couldn't pin down exactly what's still needed. If you have a specific case in mind (a query, a file, or the exact scenario to cover), point me to it and I'll follow up.

@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 190/210 (90.48%) · Uncovered code

Full report · Diff report

Comment thread src/Interpreters/SystemLog.cpp Resolved
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 1, 2026
Merged via the queue into master with commit 576be17 Aug 1, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the union-system-log-tables branch August 1, 2026 00:51
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 1, 2026
pull Bot pushed a commit to CrazyForks/ClickHouse that referenced this pull request Aug 3, 2026
…efinition

Follow-up to ClickHouse#112670, which added a
trailing `SETTINGS` clause to the arguments of the `remote`, `remoteSecure`,
`cluster` and `clusterAllReplicas` table functions.

The `remote` documentation states that the same parameters can be used with the
`Remote` and `RemoteSecure` table engines, so after that change it implied that
`ENGINE = Remote(..., SETTINGS skip_unavailable_shards = 1)` is valid. It is not:
engine arguments are parsed by `ParserStorage` in the non-table-function mode and
`registerStorageRemote` reads the settings from `storage_def->settings`, so the
inner clause is a syntax error. The engines take exactly the same settings, but
after the engine definition:

```sql
CREATE TABLE t ENGINE = Remote('127.0.0.1', system, one) SETTINGS skip_unavailable_shards = 1
```

Document the difference on both sides - the table-function page and the
`Remote`/`RemoteSecure` engine description - instead of adding a second syntax to
the engines, and add a test for the engine form, which was not covered.
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Oct 24, 2026
…runs

When the system log tables are prepared on startup (`prepare_system_log_tables_on_startup`,
implied by `startup_scripts`), `SystemLog::prepareUnionTable` replaces an obsolete `all_...`
union table with `CREATE OR REPLACE` and drops the old one before `loadMarkedAsDroppedTables`
runs. The dropped table is queued with its storage and still holds its UUID, so
`loadMarkedAsDroppedTables` found its metadata in `metadata_dropped` and failed the startup
with `TABLE_ALREADY_EXISTS` (UUID collision). The server started on the next attempt.

Union tables are created by default since ClickHouse#117943, and `all_trace_log` depends on the build id,
so this happened on every upgrade of a server with `startup_scripts`.

Related: ClickHouse#117943
Related: ClickHouse#112670

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

This branch was successfully deployed

1 active deployment
staging - docs — d018ffd7 Deployed Jul 30, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A configuration option to create and update all_..._log system tables.

4 participants