Skip to content

Add create_union_system_log_tables to the default server configuration - #117943

Merged
alexey-milovidov merged 13 commits into
masterfrom
add-union-system-log-tables-default-config
Oct 3, 2026
Merged

alexey-milovidov merged 13 commits into
masterfrom
add-union-system-log-tables-default-config

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

Closes: #117945
Related: #112670
Related: #112653

Changelog category (leave one):

  • Improvement

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

The all_... union tables over the system log tables (system.all_query_log, system.all_text_log, and so on) are now created by default: the default server configuration enables the create_union_system_log_tables section with merge_rotated_tables, so queries over the rotated versions of a log no longer have to remember constructs like merge(system, '^query_log'). The cluster setting is shown as a commented-out example, because the table definitions would reference the cluster and require it to exist. The section is also mirrored in config.yaml.example, and the documentation mentions the new default.

Two safety fixes make the default flip possible:

  • A table that already exists under one of the all_... names and was not created by this feature (for example, a hand-made table with data or the target of a materialized view) is never replaced: it is left intact and a warning is written to the server log. Previously the union table was created with CREATE OR REPLACE on any definition mismatch, dropping such a table together with its data.
  • The COMMENT of a table created from a table function (CREATE TABLE t (...) AS <table function> COMMENT '...') is now shown in system.tables: it was stored in the metadata, but never applied to the storage, so all of the all_... tables appeared without a comment.

Workflow [PR]
Sync PR [sync-upstream/pr/117943]

Version info

  • Merged into: 26.10.1.1458-master (included in 26.10 and later)

Enable `merge_rotated_tables` in the default `config.xml`, so that the
`all_...` union tables (`system.all_query_log`, `system.all_text_log`,
and so on) exist out of the box and queries over the rotated versions
of a log do not have to remember constructs like
`merge(system, '^query_log')`. The `cluster` setting is left as a
commented-out example, because the definitions of the `all_...` tables
would reference the cluster and require it to exist.

Also mirror the section in `config.yaml.example` and mention the new
default in the documentation of `create_union_system_log_tables`.

Co-Authored-By: Claude Fable 5 <[email protected]>
@mintlify

mintlify Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 2, 2026, 11:51 PM

@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [36bef85]

Summary: ✅


AI Review

Summary

I reviewed the current PR diff and all prior discussion. The PR enables create_union_system_log_tables by default, preserves pre-existing user-owned system.all_* tables instead of replacing them, fixes comment propagation for table-function-backed tables, and updates the config/docs to match the new behavior. The earlier data-loss, retry-latch, secret-logging, and docs-accuracy issues are addressed in the current code, and I did not find a remaining correctness, safety, or performance blocker.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 36bef85.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 92.10% 91.70% -0.40%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 46/48 (95.83%) · Uncovered code

Full report · Diff report

@zlareb1

zlareb1 commented Sep 3, 2026

Copy link
Copy Markdown
Member

Before this becomes the default, please consider #117945: when the section is enabled, prepareUnionTable claims each system.all_<log> name with CREATE OR REPLACE (dependency checks disabled) whenever the existing definition mismatches, so a pre-existing stateful user table on one of those names — e.g. a hand-rolled all_query_log from the #112653 recipe, or an MV target accumulating query history across rotations — is silently dropped together with its data on the first flush after the upgrade. Reproduced on v26.8.2.7-lts and 26.9.1 master; with this PR that becomes pure-defaults behavior on every upgraded server. The log tables themselves rename the old table aside on a definition mismatch to preserve data; doing the same in the union path (or refusing to replace a definition that is not one of the feature's own generated ones) before the flip would make the default safe.

@clickhouse-gh clickhouse-gh Bot added the comp-config Server configuration infrastructure: XML/YAML config parsing, preprocessor (includes, substitutio... label Sep 4, 2026
alexey-milovidov and others added 4 commits September 10, 2026 14:41
Before making `create_union_system_log_tables` a default, make the union
table creation safe for a table that already occupies one of the
`all_...` names: `prepareUnionTable` replaced a mismatching definition
with `CREATE OR REPLACE` and both dependency checks disabled, which drops
the old table together with all of its data. The names are not reserved,
and a hand-made union table over the rotated logs - possibly a stateful
one, such as the target of a materialized view - is exactly what users
built before this feature existed.

Now a table is only replaced when its stored definition is one that this
feature could have generated: a stateless proxy over the `merge` or
`clusterAllReplicas` table function. A table of any other shape is left
intact, and a warning is written to the server log instead.

The cluster-only test node turns `merge_rotated_tables` off explicitly,
because the default configuration now enables it.

Closes: #117945

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A table engine receives the comment from the storage factory arguments,
while a table function does not receive it at all, so the comment of
`CREATE TABLE t (...) AS <table function> COMMENT '...'` was written to
the metadata but never shown in `system.tables`.

This became visible with the `all_...` union tables of the system logs:
they are proxies over the `merge`/`clusterAllReplicas` table functions
and carry a comment, and `02982_comments_in_system_tables` reported all
of them as having no comment once the feature is enabled by default.

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

Copy link
Copy Markdown
Member Author

🕵 Thank you - agreed, and fixed in this pull request before the flip.

prepareUnionTable now only replaces an existing table whose stored definition is one that this feature could have generated: a stateless proxy over the merge or clusterAllReplicas table function. A table of any other shape - e.g. the MergeTree table from the reproducer in #117945, or an MV target - is left completely untouched, and a warning is written to the server log instead:

<Warning> SystemLog (system.query_log): Not creating system.all_query_log: a table with this name already exists and it was not created by the `create_union_system_log_tables` feature, so it may contain data. Drop or rename it to let the union table be created.

Flushing of the log table itself is unaffected. Covered by a new integration test test_preexisting_user_table_is_preserved (create a MergeTree table on system.all_query_log with 10 rows, force a rotation and a restart, assert the rows and the engine are intact and that the log keeps flushing; then drop it and assert the union table is created as usual). test_recreated_on_rotation was adjusted to place a table-function proxy instead of a Memory table on the name, since only that shape is replaced now. The behaviour is documented in config.xml, config.yaml.example and in the server setting documentation.

Two other things in this update: the default flip made 02982_comments_in_system_tables red, because a table created from a table function never received its COMMENT (the comment is passed to a table engine by the storage factory, but not to a table function), so all ~30 all_... tables showed up without a comment - fixed on both the create and the metadata-load paths, with test 05175_comment_of_table_created_from_table_function. And the cluster-only test node now sets merge_rotated_tables to false explicitly, because the default configuration enables it.

Comment thread src/Interpreters/SystemLog.cpp Resolved
Comment thread src/Interpreters/SystemLog.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). and removed comp-config Server configuration infrastructure: XML/YAML config parsing, preprocessor (includes, substitutio... labels Sep 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 36bef855c with master b1f44e396 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

7 object files changed (+167.30 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Interpreters/SystemLog.cpp.o 4.80 MiB 4.91 MiB +115.19 KiB (+2.34%)
src/CMakeFiles/dbms.dir/Databases/DatabaseOnDisk.cpp.o 519.81 KiB 548.89 KiB +29.07 KiB (+5.59%)
src/CMakeFiles/dbms.dir/Interpreters/InterpreterCreateQuery.cpp.o 1.07 MiB 1.09 MiB +21.18 KiB (+1.94%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

10 translation units recompiled, 60 s compile time in total, 10 of them have a recent master baseline.

Job report

alexey-milovidov and others added 2 commits September 17, 2026 19:47
…over from a name conflict

`isGeneratedUnionTableDefinition` now requires, in addition to the stateless `merge`/`clusterAllReplicas` shape, the marker sentence that every union table generated by the `create_union_system_log_tables` feature carries at the end of its `COMMENT` (`It is safe to drop this table at any time: it will be recreated automatically.`). A hand-written proxy table without the marker is a user table and is preserved.

A name occupied by a user table no longer sets `union_table_broken`: only `union_table_check_pending` is cleared, so the check is not repeated while the table is in place, and the union table is created at the next flush as soon as it is dropped or renamed, matching the warning and the documentation.

Tests: `test_recreated_on_rotation` places a table imitating an obsolete generated one (with the marker); `test_preexisting_user_table_is_preserved` asserts the recovery at the next flush without a restart; new `test_preexisting_proxy_table_is_preserved`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Comment thread src/Interpreters/SystemLog.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (5e6f8a6) and addressed both review threads. The previous reds are unrelated: Stress test (arm_debug) Shard number is greater than shard count is the known parallel-replicas issue #101325 (fix in progress: #113589); Build profile diff failed on a CI logs cluster query (infra).

alexey-milovidov and others added 2 commits October 2, 2026 23:11
# Conflicts:
#	programs/server/config.xml
…_...` names in the docs

Existing user tables under the `all_...` names are preserved, so the names are
not reserved; describe instead which tables the feature considers its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failures: Stress test (arm_debug) — Hung check failed (also frequent on master, possibly related to #121413) and Upgrade check (amd_release) — AsynchronousInsertQueue: Failed insertion ... Query memory tracker: fault injected (same message seen on unrelated PRs #123464 and #120725), and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

groeneai commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Both have fixing PRs.

Stress test (arm_debug), Hung check failed: this is not #121413. Every hung-check connection was refused with (total) memory limit exceeded: would use 227.89 GiB (attempt to allocate chunk of 0.00 B), current RSS: 3.06 GiB, maximum: 42.92 GiB, so no processlist or stacks could be collected. The charge comes from the server-side AST fuzzer, which mutated the remote index-analysis query of 02354_vector_search_distributed_index_analysis into mergeTreeAnalyzeIndexesUUID(..., 'vector_search_index_analysis', array('vec', 'L2Distance', 2147483646, [0.3, 0.3], false, true)) (21:10:43, timed out at 21:11:48). Between 21:10:45 and 21:11:03 the server log has 8 Single charge of 16.00 GiB to the global memory tracker reports on the threads of that query, all aligned_alloc <- usearch::max_heap_gt::reserve / sorted_buffer_gt::reserve <- index_gt::search <- MergeTreeIndexConditionVectorSimilarity::calculateApproximateNearestNeighbors. usearch sizes its candidate buffers by the requested limit, so the tracked total runs far ahead of RSS. Fix: #122154 (mine, open), which makes mergeTreeAnalyzeIndexes[UUID] reject a limit above max_limit_for_vector_search_queries, the bound the planner already applies before it uses the index.

On master, most hung checks of the past week were the Freeform structure search of 05258 at the memory limit, fixed by #123238, which merged today: 11 true-master hung-check rows in the week before it, 0 in the roughly 600 Stress jobs since.

Upgrade check (amd_release), AsynchronousInsertQueue: Failed insertion ... Query memory tracker: fault injected: #123581 (mine, open). Stress worker 1 runs with memory_tracker_fault_probability, and a pending Distributed batch into test_1.local_01099_b keeps those settings and is flushed by the async insert queue after the upgrade restart. Nothing enables fault injection on the upgraded server, so the PR adds this message to the post-upgrade scan. I replayed the script's own scan over this job's clickhouse-server.upgrade.log: 1 line without the change (the reported one), 0 with it.

/// table holds no data of its own and can be replaced; a table of any other shape - a `MergeTree`
/// table or a hand-written proxy that a user happened to put on one of the `all_...` names - must
/// never be dropped automatically.
bool isGeneratedUnionTableDefinition(const ASTCreateQuery & create)

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.

Overkill.

@alexey-milovidov alexey-milovidov left a comment

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.

LGTM

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 3, 2026
clickgapai pushed a commit to clickgapai/ClickHouse that referenced this pull request Oct 3, 2026
…e log scan

Stress worker 1 (`--database=test_1`) runs with
`memory_tracker_fault_probability=0.05`. Work that the stress phase leaves
behind keeps the settings of the query that created it and is executed again
by the upgraded server after the restart:

- a distributed DDL entry stores the initiator's changed settings
  (`DDLLogEntry`) and `DDLTaskBase::makeQueryContext` applies them, so a
  queued `BACKUP ... ON CLUSTER` of `test_1` replays with fault injection and
  `BackupsWorker` logs `Failed to make internal backup ... fault injected` at
  `<Error>`;
- a pending `Distributed` batch is sent with its stored settings, and the
  receiving async-insert flush logs `AsynchronousInsertQueue: Failed insertion
  ... fault injected` at `<Error>` with an empty query id, so the existing
  `} <Error> executeQuery: Code:` entry does not cover it.

Seen on three unrelated PRs in 90 days (ClickHouse#123464, ClickHouse#117943, ClickHouse#120725); in each job
these lines were the only output of the scan. Nothing enables fault injection
on the upgraded server itself, so the message can only come from carried-over
stress work. Ignore it as a fixed string, the same string the stress smoke
check already tolerates (`ci/jobs/scripts/stress/stress.py`). It is
MemoryTracker's message for both injection sites and does not match a real
`memory limit exceeded` error.

The large DDL backlog in the ClickHouse#123464 job comes from the previous release
(26.9) wedging its DDLWorker on `KILL PART_MOVE_TO_SHARD ... ON CLUSTER`,
which ClickHouse#122132 fixed on master only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged via the queue into master with commit b60a41a Oct 3, 2026
149 checks passed
@alexey-milovidov
alexey-milovidov deleted the add-union-system-log-tables-default-config branch October 3, 2026 23:26
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 3, 2026
raimannma pushed a commit to raimannma/ClickHouse that referenced this pull request Oct 4, 2026
…base_hdfs_read_grant

test_hdfs_database_cache_is_checked proved that a cached HDFS database
table is served from the cache by diffing the server-wide
TableFunctionExecute counter in system.events across the read. Since
ClickHouse#117943 the default config.xml enables create_union_system_log_tables,
so the first flush of each system log runs
CREATE OR REPLACE TABLE system.all_<log> ... AS merge(...) on the
SystemLog thread, and that table function also increments the global
counter. On master 8a6b560 (Integration tests (amd_asan_ubsan,
db disk, 4/8)) five such creations landed between the two counter reads
and the test failed with `assert 6 == 1`, although the read itself was
a cache hit.

Read ProfileEvents['TableFunctionExecute'] of the read's own query_id
from system.query_log instead, for the cache hit and for the uncached
control. A cache miss executes the table function on the query's thread
in DatabaseHDFS::getTableImpl, so it is attributed to the query, while
background table functions are not.

Validated by recreating system.all_text_log between the reads (drop it,
then SYSTEM FLUSH LOGS text_log): the old test fails with
`assert 2 == 1`, the new one passes; 10 fresh-cluster runs and 50
repeated runs pass; pointing the cache-hit read at an uncached name
makes the new assertion fail with `assert 1 == 0`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 — 36bef855 Deployed Oct 2, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). pr-improvement Pull request with some product improvements 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 pre-existing table named system.all_<log> is silently dropped with its data when create_union_system_log_tables is enabled

4 participants