Skip to content

Allow multi-component identifiers in TimeSeries tables - #112799

Merged
nikitamikhaylov merged 3 commits into
ClickHouse:masterfrom
vitlibar:timeseries-multi-component-id
Aug 3, 2026
Merged

nikitamikhaylov merged 3 commits into
ClickHouse:masterfrom
vitlibar:timeseries-multi-component-id

Conversation

@vitlibar

@vitlibar vitlibar commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Allow multi-component identifiers in TimeSeries tables.

For example, the following command will create a table with two-component identifier:

CREATE TABLE mytable ENGINE=TimeSeries 
TAGS INNER COLUMNS (id Tuple(UInt64, UInt64) DEFAULT tuple(xxHash64(metric_name), xxHash64(all_tags)))

Version info

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

@vitlibar
vitlibar requested a review from a team as a code owner July 31, 2026 19:16
@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ba1dadc]

Summary: ✅


AI Review

Summary

This PR broadens TimeSeries identifiers to arbitrary comparable types, rewrites the per-query tags collector to key IDs by serialized values, and changes the default id type to Tuple(UInt64, UUID). The collector rewrite and tuple-ID plumbing mostly line up, but the new implicit id type still breaks an existing id_generator-only DDL pattern and defers the failure to first insert.

Findings

❌ Blockers

  • [dismissed by author -- https://github.com/Allow multi-component identifiers in TimeSeries tables #112799#discussion_r3695311678] [src/Storages/TimeSeries/normalizeTimeSeriesDefinition.cpp:315] Changing the implicit id type to Tuple(UInt64, UUID) breaks previously working CREATE TABLE ... ENGINE=TimeSeries SETTINGS id_generator = 'reinterpretAsUUID(sipHash128(metric_name, all_tags))' definitions that do not also declare TAGS INNER COLUMNS (id ...). CREATE still accepts that DDL, but the insert path later builds a cast from the scalar generator result to the implicit tuple type in TimeSeriesSink / PrometheusRemoteWriteProtocol, so the failure moves to runtime. I still consider this real because the current head still defaults id at line 315 and still has no CREATE/ALTER-time validation that the configured generator matches the declared or implicit id type. Suggested fix: either keep the implicit id compatible with the established scalar-generator path, or reject id_generator unless its result type matches the resolved id type. Add a focused integration test that customizes only id_generator on an otherwise default TimeSeries table and verifies insert-time behavior.
Final Verdict

❌ Changes required before merge.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 31, 2026
@vitlibar
vitlibar requested a review from Copilot July 31, 2026 19:22

Copilot AI left a comment

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.

Pull request overview

This PR broadens TimeSeries identifier support to allow multi-component IDs (e.g. Tuple(UInt64, UInt64)), updating type validation and moving the per-query tag mapping (timeSeriesStoreTags / timeSeriesIdTo*) to work with arbitrary comparable identifier columns. It also updates user-facing docs and adds an integration test for tuple IDs.

Changes:

  • Allow TimeSeries id columns to be any comparable non-Nullable type, with automatic ID expression selection only for the legacy set (UInt64, UInt128, UUID, FixedString(16)).
  • Rework ContextTimeSeriesTagsCollector and time-series SQL functions to accept identifier columns instead of a small fixed set of ID C++ types.
  • Add integration coverage for tuple identifiers and update engine documentation.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/integration/test_prometheus_protocols/test_different_table_engines.py Adds integration test creating TimeSeries tables with Tuple(UInt64, UInt64) identifiers.
src/Storages/TimeSeries/TimeSeriesIDGenerator.cpp Improves error reporting when auto-selecting an ID generator is not possible for the chosen id type.
src/Storages/TimeSeries/normalizeTimeSeriesDefinition.cpp Expands id type validation from a fixed allowlist to “comparable non-Nullable”.
src/Storages/StorageTimeSeries.cpp Updates in-source engine documentation to describe broader allowed id types and defaulting behavior.
src/Interpreters/ContextTimeSeriesTagsCollector.h Changes collector API to work with identifier columns; documents serialized-ID storage approach.
src/Interpreters/ContextTimeSeriesTagsCollector.cpp Implements serialized-ID keying for storing/looking up tags by arbitrary identifier columns (incl. Nullable skipping for storeTags).
src/Functions/TimeSeries/TimeSeriesTagsFunctionHelpers.h Adjusts ID argument validation API to no longer return a specific ID C++ type.
src/Functions/TimeSeries/TimeSeriesTagsFunctionHelpers.cpp Updates ID type validation to accept any comparable non-Nullable type (optionally wrapped in Nullable).
src/Functions/TimeSeries/timeSeriesStoreTags.cpp Uses column-based storage into the per-query collector (supports nullable IDs by skipping NULL rows).
src/Functions/TimeSeries/timeSeriesIdToTags.cpp Switches to column-based lookup in the per-query collector.
src/Functions/TimeSeries/timeSeriesIdToGroup.cpp Switches to column-based lookup in the per-query collector.
docs/en/engines/table-engines/integrations/time-series.md Updates public docs to describe broader allowed id types and default generator selection constraints.

@nikitamikhaylov

Copy link
Copy Markdown
Member

@vitlibar what's the default one?

CREATE TABLE mytable ENGINE=TimeSeries 
TAGS INNER COLUMNS (id Tuple(UInt64, UInt64) DEFAULT tuple(xxHash64(metric_name), xxHash64(all_tags)))

The 64-bit hash is not enough, we need 128bit.

@nikitamikhaylov nikitamikhaylov added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Jul 31, 2026
@vitlibar

vitlibar commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

@vitlibar what's the default one?

CREATE TABLE mytable ENGINE=TimeSeries 
TAGS INNER COLUMNS (id Tuple(UInt64, UInt64) DEFAULT tuple(xxHash64(metric_name), xxHash64(all_tags)))

The 64-bit hash is not enough, we need 128bit.

I switched the default id type to Tuple(UInt64, UUID).
So after this PR a TimeSeries table created by default will have the following id column:

`id` Tuple(UInt64, UUID) DEFAULT tuple(sipHash64(metric_name), reinterpretAsUUID(sipHash128(metric_name, all_tags)))

@vitlibar
vitlibar force-pushed the timeseries-multi-component-id branch from 4e58a1e to 042b11a Compare August 1, 2026 08:52
@vitlibar
vitlibar force-pushed the timeseries-multi-component-id branch from 042b11a to ba1dadc Compare August 1, 2026 10:57
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 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: 191/228 (83.77%) · Uncovered code

Full report · Diff report

@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Aug 3, 2026
Merged via the queue into ClickHouse:master with commit d7972dc Aug 3, 2026
352 of 353 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 3, 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-not-for-changelog This PR should not be mentioned in the changelog 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