Repository navigation
Add the create_union_system_log_tables configuration option to create and update all_... system log tables - #112670
Conversation
…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]>
|
Workflow [PR], commit [d018ffd] Summary: ✅
AI ReviewSummaryThis PR adds the Findings
Final VerdictNeeds a follow-up before merge: keep the |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
| | `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. | |
There was a problem hiding this comment.
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 ...?
There was a problem hiding this comment.
We can hand it over to @clickgapai after the PR is merged.
There was a problem hiding this comment.
🕵 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.
There was a problem hiding this comment.
@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.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 190/210 (90.48%) · Uncovered code |
…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.
…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]>
Closes: #112653
A new optional server configuration section,
create_union_system_log_tables, requests the creation ofall_...tables next to the system log tables (system.all_query_logforsystem.query_logand 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 ofclusterAllReplicas(default, merge(system, '^query_log')) SETTINGS skip_unavailable_shards = 1that you don't have to remember, with the table structure automatically kept up to date with the structure of the latest table.At least one of
merge_rotated_tablesandclusterhas 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.SystemLogverifies 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 inAtomic,ReplicatedandShareddatabases 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_shardsin the table definition, theremote,remoteSecure,clusterandclusterAllReplicastable functions now accept a trailingSETTINGSclause with the settings of theDistributedstorage they create (previously such a clause was accepted bymysql,postgresqland other table functions, and theDistributedversion ofskip_unavailable_shardsalready existed for theDistributed/Remoteengines):A setting specified in the query has priority over the setting from the table function.
CREATE TABLE ... AS table_function(...)now parses theSETTINGSclause too (also required for loading the stored metadata of such tables).Note: a table definition with a
SETTINGSclause inside a table function cannot be loaded by servers of previous versions, so downgrading requires dropping such tables first (this applies to theall_...tables created with theclusteroption).Changelog category (leave one):
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 ofall_...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. Theremote,remoteSecure,clusterandclusterAllReplicastable functions now accept a trailingSETTINGSclause with the settings of theDistributedstorage they create, e.g.clusterAllReplicas('default', system.query_log, SETTINGS skip_unavailable_shards = 1).Version info
26.8.1.564(included in26.8and later)