Repository navigation
Pin the timezone in the default TimeSeries partition key - #120960
alexey-milovidov merged 19 commits into
Conversation
The inner recent samples table is partitioned by `toStartOfInterval(toDateTime(timestamp), toIntervalHour(5))` when the user declares no partition key of their own. `toStartOfInterval` counts hours from local midnight rather than from the epoch, and nothing in that expression pins a timezone, so every partition value already on disk means a different instant once the server timezone changes. The consequence is silent. Partition pruning maps the query bounds through the expression as it reads today, the values stored by the earlier timezone are no longer on that grid, and whole parts are eliminated from a range query that they match: a table returning 5079 rows for a predicate returns 1, with no error, and PromQL over it answers with an empty result for data that is present. The rows are not lost, and come back if the server timezone is put back. Pinning UTC in the generated default removes the dependency: someone who never chose a partition key should not inherit a silent one on the server's timezone. The expression is written in two places, the one that generates it and the one that recognises it to keep it out of `SHOW CREATE`, and both move together. Only tables created from here on are affected. An existing inner table already carries its own partition key, which this does not and cannot rewrite, so a table written under one timezone still needs that timezone to read its older parts. Whether those get a migration path is a separate question. Reported in ClickHouse#120944, where the timezone was diagnosed as the ingredient. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
|
Workflow [PR], commit [6a1a49c] Summary: ✅
AI ReviewSummaryThe PR pins the generated Findings
Tests
Final VerdictStatus: |
|
Thanks for picking this up. I had the same change in progress and yours covers the same two sites, so I am not opening a duplicate. Two things I hit while implementing it, both of which the 1. 2. The 3. A behavioural test is possible. The failure needs no absolute timestamp, so the 4-day TTL is not in the way: insert |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units81 translation units recompiled, 212 s compile time in total, 81 of them have a recent master baseline. |
…t change The previous commit changed the generated default for every table, including one created with an explicit `version`. `TimeSeriesVersion.h` requires the opposite: a change to the schema of the target tables either bumps the version or stays version-aware, so that `SETTINGS version = N` keeps reproducing the definition that version described and two nodes of different releases normalize the same DDL the same way. So the pinned timezone is version 6, and version 5 and below keep generating the expression they always generated. The spelling a version generates is also the spelling it recognises as generated, which is what lets `CREATE TABLE copy AS src` strip an older table's own default and regenerate it rather than carrying a clause that then looks explicit. An existing table therefore keeps the partition grid it was written on, which is the only thing that can be said for one: its parts are already placed, and no `ALTER` can move a partition key. Only a table created at version 6 gets a grid that survives a server timezone change. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
…plit with tests Bumping `LATEST` left the generated engine reference describing version 5: the example `SHOW CREATE` output, the default of the `version` setting, the prose naming the latest version, and a version history that stopped one row short, all on the same page that now shows the version 6 partition key. That documents a definition nobody can get. The tests only covered the latest version too, so neither half of the split was actually pinned. `SETTINGS version = 5` keeping the expression it always generated is now asserted, and so is the copy case: a version 5 source table has its generated key recognised by its own spelling, stripped, and regenerated with the timezone named, because a copy is a new table at the latest version. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
Three stateless tests failed, all on my own expectations rather than on the code. `engine_full` comes back with the quotes of a string literal escaped, so the generated partition key reads `toDateTime(timestamp, \'UTC\')`. I had rewritten those two references by substituting the unescaped spelling instead of taking what the server prints, which is the whole reason the server was run in the first place. `04612_timeseries_version_setting` extracts the version as a bare number, so it asserted `5` where nothing spelled `version = 5`, which is why searching for that string did not find it. Its four per-version checks create versions 0 to 3 explicitly and are unaffected. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
… copy When copying a TimeSeries table with an inner engine declared with arguments (such as `RECENT SAMPLES ENGINE = ReplicatedMergeTree(...)`), `removeGeneratedInnerEngine` previously returned early before checking `partition_by`, leaving the source table's legacy partition key in place and preventing `normalizeInnerEngine` from regenerating the pinned UTC key for the new version 6 table. Strip generated partition keys, TTL, sorting keys, and settings even when the engine has arguments or is a custom kind, while preserving the custom engine itself so that copies remain replicated or custom.
Dropping the early returns for engines with arguments left the sorting-key stripping running for them. A source like SAMPLES ENGINE = ReplacingMergeTree(timestamp) PRIMARY KEY id ORDER BY (id, timestamp) matches the generated key, so `CREATE TABLE ... AS` cleared its ORDER BY. Nothing put one back: the regeneration is guarded on there being no primary key, and the primary key survives. The copy then reaches MergeTree with neither and is rejected with "ORDER BY cannot be empty". The three branches that drop a sorting key on its own now refuse to while a primary key is present. The tags branch is untouched, since it already drops the pair together and only when both were generated. Coverage goes next to the existing copy test: a custom samples engine carrying its own primary key is copied, and the copy keeps both clauses. The expected output was taken from a build without this branch, where the early return kept the same behaviour. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
|
@groeneai , do your magic with the CI once again, please. |
|
Three reds on
One thing in the report that looks alarming but is not: If the remaining jobs red on something else, ping me and I will attribute it. |
# Conflicts: # src/Storages/StorageTimeSeries.cpp # src/Storages/TimeSeries/TimeSeriesVersion.h # src/Storages/TimeSeries/normalizeTimeSeriesDefinitionImpl.cpp
…cenario `Storage memory check` fails unrelated PRs with a byte-constant `change=+1,056`. Since ClickHouse#120487 removed the one-time initialization offset, 9 heads had `+1,056` as their only failing scenario, on `03_add_secondary_indexes.sql` and `04_add_projection.sql`. A pooled thread that runs a mutation step attaches to the task's `ThreadGroup` through `ThreadGroupSwitcher`, and that attach constructs thread-local performance-counter state: `TasksStatsCounters`, a `ProcfsMetricsProvider`, and two `__cxa_thread_atexit_impl` registrations which by construction live until the thread exits. `GlobalThreadPool` keeps its threads, so those bytes stay live once a thread has participated, and the quantity the checkpoint diff measures is how many distinct pool threads have ever served the scenario. Which window a thread's first participation lands in is a scheduling draw. It is one cluster of 7 stacks costing exactly 528 bytes per participating thread: +384 `TasksStatsCounters::create`, -64 `ThreadGroup::SharedData::SharedData`, +64 `detachFromGroup`, +48 `make_shared<ProcfsMetricsProvider>`, +32 and +32 for the two `__cxa_thread_atexit_impl` registrations, +32 for the query-id string copy in `applyQuerySettings`. The gate is `absolute_change > 1024 AND percent_change > 1.0`, so one unit passes and two clear it by 32 bytes: the threshold sits inside the noise quantum. PR ClickHouse#120702 at `b48703670359` has rows for `04_add_projection.sql` at both 528 and 1,056, the same commit measured twice with different answers, so no threshold value could measure this quantity. Raising the threshold is the move that already failed: `150d1f2d0290b` raised this lane from the parser lane's 100 to 1,024 for this exact mechanism, and two units cleared it three days later. Waiting for background tasks to quiesce cannot work either, because this state is registered with `__cxa_thread_atexit_impl` and is not a teardown tail. Pinning the pools to one thread would be C++-side, and the master arm binary is downloaded from the merge base, so such a fix is asymmetric until it reaches master. Instead add the three thread attach/detach frames to the analyzer's existing `EXCLUDED_STACK_FRAME_PREFIXES`, which `compute_diff` already consults before a stack reaches the gated total. Both arms of a run are analysed by the same script from the same checkout, so the change applies symmetrically from the first run, and keying on the allocation site covers every pool at once rather than enumerating pools or settings. On the production reports for ClickHouse#118967, ClickHouse#120960, ClickHouse#121251 and ClickHouse#120702, removing this cluster takes every failing scenario's change to exactly 0, with the largest residual anywhere 64 bytes against the 1,024-byte threshold. Locally, 20 repeated two-pass runs of one binary reproduce the 528-byte unit with the same 7-row composition and a multiplicity that varies run to run; an injected 64 KiB-per-table allocation is still reported at full size; and reverting only these three prefixes restores the pre-fix numbers byte-for-byte. Two consequences are deliberate. The cluster rows also leave the HTML report, exactly as `dumpProfile` overhead already does, because a row the check must not gate on should not be presented as a finding. And thread-accounting regressions are no longer measured here, which the same-commit pair above shows was never possible anyway. `STORAGE_CHANGE_THRESHOLD_BYTES` is left at 1,024. Removing this noise is what would make lowering it toward the parser lane's 100 possible, but that is a calibration decision with its own data. Related: ClickHouse#120487 Related: ClickHouse#119480 Co-Authored-By: Claude Opus 5 <[email protected]>
|
Should be ready for review. |
Master changed the link on the version 6 row of the TimeSeries version table, next to the version 7 row this branch adds. Keep master's row 6 and the branch's row 7. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`master` took version 7 of `TimeSeries` for the deduplication caches (ClickHouse#121915), so the pinned timezone of the default recent samples partition key moves to version 8: `MIN_WITH_UTC_PARTITION_KEY = 8`, `LATEST = 8`, and the version history in `TimeSeriesVersion.h` and in the engine documentation gets both rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The latest version is 8 now, and version 7 is the last one generating the partition key without a timezone, so the unit test checks the boundary on it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Should be ready for review. |
Upstream used `TimeSeries` version 8 for moving `min_time` and `max_time` into the time ranges target table (`MIN_WITH_TIME_RANGES_TARGET`), so the pinned `UTC` partition key of the recent samples table becomes version 9: - `TimeSeriesVersion.h` (moved to `src/Parsers/Prometheus/`): `MIN_WITH_UTC_PARTITION_KEY = 9`, `LATEST = 9`, the version history has both entries. - `removeGeneratedInnerEngine`: the `TimeRanges` kind and the tags engine kind from `getGeneratedTagsEngineKind` use the `engine_is_generated` flag, so an engine with arguments is kept as it is. - The docs in `StorageTimeSeries.cpp`, the `gtest_normalize_time_series_definition.cpp` expectations and the reference of `04612_timeseries_version_setting` say version 9; the explicit version 8 keeps the partition key without a timezone. Review: ClickHouse#120960 (review) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@groeneai , please check why the CI is failing, and prepare fix if applicable. |
|
One red on
|
`CREATE TABLE ... AS` strips the parts of the source's inner engines that look generated, so they are generated again for the new table. Since the stripping also runs for engines with arguments and for engines of another kind, it removed `allow_nullable_key = 1` together with tags keys that look generated, for example `ReplacingMergeTree(v) PRIMARY KEY metric_name ORDER BY (metric_name, id)` over a `Nullable(String)` metric name. The nullable column is kept and the keys are generated again, but the setting was not, so the copy failed with ILLEGAL_COLUMN. The generator adds `allow_nullable_key` only for the nullable `min_time` and `max_time` in the sorting key of older versions, so the setting is now removed only together with that key. A declared one is kept for the user's own nullable key column. This also fixes the same copy for a generated tags engine without arguments, which failed before this PR as well. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The only red on @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/120960/80b5fcbc7daca99387d33940e3158e947ad6c062/pr/performance_comparison_arm_release_master_head_4_6/job.log and provide a fix in a separate PR. If the fix is already in progress, link it here. |
|
This PR didn't cause it. The 4/6 shard lost an hour in the CI Logs export setup before
The fix is #126217, merged on 2026-10-16 at 19:58 UTC, after this run. It caps every query that script sends to the CI Logs cluster at 90 s of wall-clock time, so an overloaded cluster now costs a job minutes instead of an hour. Your |
…lumn The generated `allow_nullable_key = 1` of a pre-v8 tags engine was removed on `CREATE TABLE ... AS` together with its `min_time, max_time` sorting key. But the same setting also lets a user's nullable column, like a `Nullable(String)` `metric_name`, stay in the regenerated key, so the copy failed with ILLEGAL_COLUMN. Now the setting is removed only if no copied column of the inner table is nullable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PromQL Compliance ReportBaseline: S3 master
Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream Note: Prometheus compliance score is unchanged vs baseline. |
Master's ClickHouse#120960 changed removeGeneratedInnerEngine: each target now sets engine_is_generated, and a sorting key is dropped only while no primary key is declared. The histograms case kept the old early-return form, so after the merge its generated engine was never stripped and a declared PRIMARY KEY lost its ORDER BY on CREATE TABLE ... AS. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
The default partition key of the inner recent samples table of a
TimeSeriestable is now anchored to UTC. Previously it depended on the server timezone, so changing that timezone made range queries silently skip whole parts.Documentation entry for user-facing changes
The engine reference states the default partition key; it is regenerated from the changed source strings.
Closes the defect reported in #120944.
When the user declares no partition key, the inner recent samples table is generated with:
toStartOfIntervalcounts hours from local midnight, not from the epoch (DateLUTImpl.h,toStartOfHourInterval: "We will round the hour number since the midnight. It may split the day into non-equal intervals."), and nothing in that expression pins a timezone. Every partition value already written therefore means a different instant once the server timezone changes.The failure is silent. Pruning maps the query bounds through the expression as it reads today, the values written under the earlier timezone are no longer on that grid, and parts that match the predicate are eliminated:
The discarded part is not damaged: its partition value is what the declared expression yields for its rows, and its min-max index decodes to exactly its true range. Reached through PromQL, this returns an empty result for data that is present. The rows are not lost — they come back when the server timezone is put back, and the row written under the other timezone becomes the hidden one instead.
@groeneai diagnosed the timezone as the ingredient in #120944, including the minimal reproduction and the confirmation that pinning the timezone removes the failure mode. This is that change.
What it changes
'UTC'is pinned in the generated default from table version 8, which this PR adds as the latestTimeSeriesversion. A table of an earlier version, including one created with an explicit olderversion, keeps the old default. The expression lives in two places — the one that builds it and the one that recognises it, so a redundant declared key is still elided fromSHOW CREATE— and both move together, otherwise normalization stops recognising its own default. The engine and setting documentation strings move with it; the.mdxreference pages are insideAUTOGENERATEDmarkers and are regenerated from those strings.recent_samples_partition_by, when set explicitly, is untouched: a user who chose an expression keeps exactly what they chose.The TTL expression is deliberately left alone.
toDateTime(timestamp) + toIntervalSecond(N)compared againstnow()is epoch arithmetic and carries no timezone dependency.Scope, stated plainly
Only tables created from here on benefit. An existing inner table already carries its own materialized partition key, which this change does not and cannot rewrite —
MergeTreehas noMODIFY PARTITION BY. A table written under one timezone still needs that timezone to read its older parts. Whether existing tables get a migration path is a separate question for the engine owner, and I have not attempted one here.Two guards. The generated DDL is asserted in
05019_time_series_recent_samples_table.reference,05026_time_series_recent_samples_default.referenceandgtest_normalize_time_series_definition, all of which fail the moment the pin is removed. Andtest_timeseries_partition_key_timezoneis behavioural: insertnow()-relative samples, restart the server with a different<timezone>in its config, then re-run the range query. That recipe is @groeneai's, from his review comment — it sidesteps the 4-day TTL, which is what I had wrongly concluded made a behavioural test impossible here.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/120960]
Version info
26.11.1.157-master(included in26.11and later)