Skip to content

Adjust a copied TimeSeries definition to the settings of the new table - #118517

Merged
nikitamikhaylov merged 2 commits into
ClickHouse:masterfrom
vitlibar:adjust-copied-timeseries-definition-to-settings
Sep 8, 2026
Merged

nikitamikhaylov merged 2 commits into
ClickHouse:masterfrom
vitlibar:adjust-copied-timeseries-definition-to-settings

Conversation

@vitlibar

@vitlibar vitlibar commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Experimental Feature

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

Adjust a copied TimeSeries definition to the settings of the new table

Follow-up to #111204, also fixes #117839 (comment) and #117839 (comment)

Changes:

  • The copy follows its own settings. Inner columns and engines generated for the old table are generated again for the new one, so changing a setting in the copy (for example tags_to_columns or recent_samples_ttl_seconds) gives a consistent definition.

  • Customizations survive. Extra inner columns, custom codecs and defaults, engines with arguments, custom sorting keys and engine settings of the old table are copied as they are.

  • Settings are merged sensibly. Settings written in the query win, version is never copied so a copy always gets the latest schema, obsolete settings are dropped, and settings that make no sense with the new values are removed together, such as id_generator when the id type changes.

  • Types and replication are inherited. The timestamp, value and id types and the MergeTree/Replicated/Shared family come from the old table unless the query declares them. Mixed replication types among inner tables are rejected.

  • External targets are handled explicitly. They are not copied, so the query has to declare them or declare inner columns instead. A target replaced with an external table takes its types from that table.

  • Privileges. The copy requires SHOW COLUMNS on the old table and on any external table whose columns are read.


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

Version info

  • Merged into: 26.9.1.956 (included in 26.9 and later)

@vitlibar vitlibar added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Sep 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [469fab8]

Summary: ✅


AI Review

Summary

This PR teaches CREATE TABLE ... AS ... for TimeSeries to merge copied settings and re-derive generated inner definitions from the destination table. The main local path is much stronger now, but there are still correctness gaps around old-format ON CLUSTER, replicated/shared inner engines, and version-0 customization detection, so the change is not ready to merge yet.

Findings

❌ Blockers

  • [src/Interpreters/InterpreterCreateQuery.cpp:3657-3692, src/Interpreters/InterpreterCreateQuery.cpp:3707-3764] distributed_ddl_entry_format_version < NORMALIZE_CREATE_ON_INITIATOR_VERSION still exits through executeQueryOnCluster() before getTablePropertiesAndNormalizeCreateQuery() runs. params.access_to_check = getRequiredAccess() does not include SHOW_COLUMNS on the AS source or its external targets, while the default distributed_ddl_use_initial_user_and_roles = 0 makes worker legs execute without the caller's grants. A user who can CREATE TABLE can still clone TimeSeries-backed types through CREATE TABLE ... AS secret_ts ENGINE = TimeSeries ON CLUSTER ... on the old DDL path. Suggested fix: either materialize the AS source on the initiator and extend access_to_check with the source / external-target SHOW_COLUMNS grants, or reject this old-format ON CLUSTER combination before dispatch the same way the use_legacy_to_time branch already rejects unsupported AS cases.
  • [src/Storages/TimeSeries/normalizeTimeSeriesDefinition.cpp:747-750] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/118517#discussion_r3948380574] removeGeneratedInnerEngine still returns immediately for any Replicated* / Shared* engine because those engines always carry arguments. That means copied generated inner engines keep the source engine kind, sorting key, partitioning and TTL verbatim instead of being re-derived from the destination settings. A replicated source copied with SETTINGS aggregate_min_time_and_max_time = 0 will still keep ReplicatedAggregatingMergeTree ORDER BY (metric_name, id) instead of switching to the ReplicatedReplacingMergeTree shape the new table requires. Suggested fix: preserve only the replication arguments / family from the old engine and still clear or rebuild the generated engine kind, keys, partitioning, TTL, and generated engine settings around them.
  • [src/Storages/TimeSeries/normalizeTimeSeriesDefinition.cpp:622-635, src/Storages/TimeSeries/normalizeTimeSeriesDefinition.cpp:646-662] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/118517#discussion_r3951255099, https://github.com/ClickHouse/ClickHouse/pull/118517#discussion_r3947860904] The version-0 heuristics still treat any non-canonical sample codec and any non-canonical tags.id DEFAULT as generated. For supported old tables that silently rewrite explicit user customizations during CREATE TABLE ... AS ...: custom timestamp / value codecs are replaced with today's defaults, and a custom id generator such as DEFAULT sipHash64(metric_name) is dropped and regenerated as the current canonical expression. Suggested fix: match only the historical version-0 generated forms explicitly instead of using the current is_version_0 catch-all when the codec or DEFAULT differs from today's canonical one.

⚠️ Majors

  • [src/Interpreters/InterpreterCreateQuery.cpp:3584-3589, src/Interpreters/InterpreterCreateQuery.cpp:3657-3692] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/118517#discussion_r3949549695] The same old-format ON CLUSTER branch still calls prepareOnClusterQuery() before setEngine(), so CREATE TABLE dst AS src ON CLUSTER ... with omitted ENGINE never marks the query as TimeSeries on the initiator and therefore never pins version. Each worker then infers TimeSeriesVersion::LATEST independently when it normalizes the query locally, which lets a mixed-version cluster persist different metadata for the same table. Suggested fix: reject this old-format AS form unless version is explicit, or move enough AS-source detection to the initiator to pin the version before enqueueing the DDL.
Tests
  • ⚠️ Add an ON CLUSTER regression that forces distributed_ddl_entry_format_version = 2 and distributed_ddl_use_initial_user_and_roles = 0, then verifies that CREATE TABLE ... AS <TimeSeries> is denied without SHOW_COLUMNS on the source and its external targets.
  • ⚠️ Add a copy-from-replicated / copy-from-shared case where the destination flips aggregate_min_time_and_max_time or another engine-shaping setting; the current 05137 coverage exercises only no-argument engines and cannot catch the early return at removeGeneratedInnerEngine.
  • ⚠️ Add a version-0 copy case with a user-written tags.id DEFAULT and a non-default sample codec. The current tests only prove canonical or current-version definitions, so they do not protect the backward-compatibility path this PR now documents.
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit 469fab8.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.10% 81.20% +0.10%

Changed lines: Changed C/C++ lines covered: 515/569 (90.51%) · Uncovered code

Full report · Diff report

Comment thread src/Storages/StorageTimeSeries.cpp Resolved
@vitlibar
vitlibar force-pushed the adjust-copied-timeseries-definition-to-settings branch from 5de4a29 to 26f127d Compare September 7, 2026 08:53
@vitlibar
vitlibar force-pushed the adjust-copied-timeseries-definition-to-settings branch from 26f127d to 82d7614 Compare September 7, 2026 10:10
@vitlibar
vitlibar force-pushed the adjust-copied-timeseries-definition-to-settings branch 3 times, most recently from dde5caa to 79b8cd8 Compare September 7, 2026 11:24
@vitlibar
vitlibar force-pushed the adjust-copied-timeseries-definition-to-settings branch from 79b8cd8 to 64098d3 Compare September 7, 2026 12:17
@vitlibar
vitlibar force-pushed the adjust-copied-timeseries-definition-to-settings branch from 64098d3 to b6ecea3 Compare September 7, 2026 13:45
@vitlibar
vitlibar force-pushed the adjust-copied-timeseries-definition-to-settings branch 2 times, most recently from b8e6132 to 2acf90e Compare September 7, 2026 15:24
@vitlibar
vitlibar force-pushed the adjust-copied-timeseries-definition-to-settings branch from 2acf90e to eb315bf Compare September 7, 2026 16:34
@vitlibar
vitlibar force-pushed the adjust-copied-timeseries-definition-to-settings branch 3 times, most recently from 6f8717c to 4a1c8d9 Compare September 7, 2026 21:45
@vitlibar
vitlibar force-pushed the adjust-copied-timeseries-definition-to-settings branch 2 times, most recently from b01acc4 to bbdb205 Compare September 7, 2026 23:07

/// The definition of the old table is read below.
auto old_database = context->resolveDatabase(create_query.as_database);
context->checkAccess(AccessType::SHOW_COLUMNS, old_database, create_query.as_table);

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.

distributed_ddl_entry_format_version < NORMALIZE_CREATE_ON_INITIATOR_VERSION still bypasses this whole authorization path for ON CLUSTER. InterpreterCreateQuery::execute returns from the old-format branch before getTablePropertiesAndNormalizeCreateQuery() runs (src/Interpreters/InterpreterCreateQuery.cpp:3658-3692), and getRequiredAccess() does not add SHOW_COLUMNS on the AS source or its external targets. The worker legs then execute as internal queries (src/Interpreters/InterpreterCreateQuery.cpp:3660-3661), so the new checks here and in readTypesFromExternalTargets never run as the calling user.

A user with only CREATE TABLE and engine grants can therefore still do CREATE TABLE ... AS secret_ts ENGINE = TimeSeries ON CLUSTER ... with an old distributed DDL format and clone the source-backed types through worker-local normalization. This needs an initiator-side authorization or rejection before dispatch, because the worker-side checkAccess calls cannot enforce the caller's SHOW_COLUMNS privileges.

DataTypeLowCardinality.h was included twice, tripping readability-duplicate-include in the arm_tidy build.
@vitlibar
vitlibar force-pushed the adjust-copied-timeseries-definition-to-settings branch from bbdb205 to 469fab8 Compare September 7, 2026 23:57
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 469fab812 with master 4d21de5fa (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

10 object files changed (+59.55 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/TimeSeries/normalizeTimeSeriesDefinition.cpp.o 456.30 KiB 512.75 KiB +56.45 KiB (+12.37%)

716 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

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

Job report

@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

PromQL Compliance Report

Baseline: S3 master 4d21de5fa

Metric Baseline Current Δ
Score 81.82% 81.82% +0.00%
Passed 441 441 +0
Failed 3 3 +0
Unsupported 95 95 +0

Note: score is unchanged vs baseline.

Uploaded compliance JSON for this PR commit

@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Sep 8, 2026
Merged via the queue into ClickHouse:master with commit 3a3cf12 Sep 8, 2026
174 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... pr-experimental Experimental 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.

4 participants