Skip to content

Improve TimeSeries table engine - #99083

Merged
nikitamikhaylov merged 31 commits into
ClickHouse:masterfrom
vitlibar:improve-time-series-table-engine
May 26, 2026
Merged

nikitamikhaylov merged 31 commits into
ClickHouse:masterfrom
vitlibar:improve-time-series-table-engine

Conversation

@vitlibar

@vitlibar vitlibar commented Mar 9, 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):

This PR improves the TimeSeries table engine in several ways:

  • Support INNER COLUMNS clause in CREATE TABLE for fine-grained control over inner table columns
  • Add new setting id_generator to allow customizing ID generation even for a TimeSeries table with external targets
  • Support ALTER MODIFY SETTINGS for TimeSeries tables
  • Rename inner target table DATA to SAMPLES
  • Simplify outer columns: replace timestamp/value pair with a single time_series column; remove redundant outer columns id, all_tags, min_time, max_time, per-tag columns; rename outer column metric_family_name to metric_family
  • Support INSERT into TimeSeries tables

Version info

  • Merged into: 26.6.1.171

@clickhouse-gh

clickhouse-gh Bot commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9758a35]

Summary: ✅


AI Review

Summary

This PR substantially refactors TimeSeries (new normalization path, INNER COLUMNS, id_generator, new sink/remote-write wiring, and migration coverage), but there are still correctness/rollout gaps where invalid configurations pass DDL and fail at runtime, and one failure path can leave partial writes. Verdict: ⚠️ Request changes.

Findings

❌ Blockers

  • [src/Storages/TimeSeries/TimeSeriesSink.cpp:752] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/99083#discussion_r3291577227] tags_pipeline->push happens before full samples validation (fillSamplesColumns). A mixed batch can write tags, then throw on an invalid sampled row, leaving orphaned tag state from a failed INSERT.
  • [tests/integration/test_prometheus_protocols/backups/time_series_prealpha.zip:1] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/99083#discussion_r3294305224] A committed archive fixture remains in git. Per ClickHouse review policy, binary archives should not be committed because they permanently bloat history and are hard to audit.

⚠️ Majors

  • [src/Storages/TimeSeries/normalizeTimeSeriesDefinition.cpp:1008] id_generator is syntax-parsed but not semantically validated at CREATE/ALTER. Invalid identifiers/types are accepted and fail only on first insert when defaults are evaluated. This should fail at DDL time against the resolved tags source header and id_type.
  • [src/Storages/TimeSeries/normalizeTimeSeriesDefinition.cpp:835] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/99083#discussion_r3294306214] check_column_min_max_time accepts any SimpleAggregateFunction/AggregateFunction wrapper without checking wrapper argument compatibility. Incompatible external min_time/max_time schemas can pass CREATE TABLE and then fail during writes/queries.

💡 Nits

  • [docs/en/sql-reference/table-functions/timeSeriesSamples.md:33] The SQL alias timeSeriesData is kept, but docs/en/sql-reference/table-functions/timeSeriesData.md was removed; existing bookmarks/inbound docs links to the old path now break.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Validate id_generator semantics at CREATE/ALTER (identifier set + convertibility to id_type).
  2. Tighten min_time/max_time wrapper-type validation to require timestamp-compatible arguments.
  3. Eliminate partial side effects on failed inserts in TimeSeriesSink (validate before writing tags or make writes atomic).
  4. Restore docs compatibility for timeSeriesData path (redirect or compatibility page).
  5. Replace the committed zip fixture with generated/runtime test data (or another non-binary reproducible mechanism).

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Mar 9, 2026
@vitlibar
vitlibar force-pushed the improve-time-series-table-engine branch 3 times, most recently from 68184be to d3ca5c1 Compare March 18, 2026 16:14
@vitlibar
vitlibar force-pushed the improve-time-series-table-engine branch from d3ca5c1 to f2b51f8 Compare April 13, 2026 13:59
@vitlibar vitlibar changed the title [WIP] Some improvements of TimeSeries table engine [WIP] Improve TimeSeries table engine Apr 13, 2026
@vitlibar
vitlibar requested a review from Copilot April 13, 2026 14:05

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 refactors and extends the TimeSeries table engine to support a simplified outer schema, customizable type/id settings, explicit INNER COLUMNS definitions for inner targets, ALTER ... MODIFY SETTINGS, INSERT support, and a rename of the inner “data” target to “samples” (with compatibility aliases). It also updates Prometheus protocol handling and expands integration tests for upgrades/backups and new behavior.

Changes:

  • Introduces normalized TimeSeries definition/settings pipeline (normalizeTimeSeriesDefinition, new SettingField types, new inner-table creation helpers) and removes older normalizer/validator/creator code.
  • Adds INSERT support via a new TimeSeriesSink, plus Prometheus remote-write/read adjustments to the new schema/settings.
  • Adds/updates integration tests (including upgrade + restore-from-backup coverage) and docs for timeSeriesSamples / SAMPLES terminology.

Reviewed changes

Copilot reviewed 48 out of 49 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/integration/test_prometheus_protocols/test_write_read.py Updates regex expectations for Prometheus read/write responses.
tests/integration/test_prometheus_protocols/test_upgrade_from_old_version.py Adds upgrade + restore coverage for old TimeSeries layouts (old inner table naming and backup layout).
tests/integration/test_prometheus_protocols/test_insert_select.py Adds integration tests for INSERT into TimeSeries outer table.
tests/integration/test_prometheus_protocols/test_different_table_engines.py Expands integration coverage for new settings, SAMPLES/DATA aliasing, external targets, and toleranced comparisons.
tests/integration/test_prometheus_protocols/configs/backups_disk.xml Adds backup disk configuration for integration tests.
tests/integration/test_prometheus_protocols/backups/time_series_version_1.zip Test fixture backup archive for restore-compatibility testing.
src/TableFunctions/TableFunctionTimeSeries.h Renames the “data” table function to timeSeriesSamples for the Samples target.
src/TableFunctions/TableFunctionTimeSeries.cpp Registers timeSeriesSamples and adds timeSeriesData alias for compatibility.
src/Storages/TimeSeries/TimeSeriesSink.h Introduces sink interface for inserting into TimeSeries inner targets.
src/Storages/TimeSeries/TimeSeriesSink.cpp Implements insert transformation/pipelines for Tags/Samples/Metrics.
src/Storages/TimeSeries/TimeSeriesSettings.h Extends TimeSeries settings API (DataType/ASTFunction setting fields, change tracking, apply/copy).
src/Storages/TimeSeries/TimeSeriesSettings.cpp Implements new settings fields and change/copy/apply logic.
src/Storages/TimeSeries/TimeSeriesInnerTablesCreator.h Removed (replaced by new normalization + inner table creation helpers).
src/Storages/TimeSeries/TimeSeriesInnerTablesCreator.cpp Removed (replaced by new normalization + inner table creation helpers).
src/Storages/TimeSeries/TimeSeriesDefinitionNormalizer.h Removed (replaced by normalizeTimeSeriesDefinition).
src/Storages/TimeSeries/TimeSeriesDefinitionNormalizer.cpp Removed (replaced by normalizeTimeSeriesDefinition).
src/Storages/TimeSeries/TimeSeriesColumnsValidator.h Removed (validation moved into new normalization/settings flow).
src/Storages/TimeSeries/TimeSeriesColumnsValidator.cpp Removed (validation moved into new normalization/settings flow).
src/Storages/TimeSeries/TimeSeriesColumnNames.h Updates naming (samples, metric_family) while keeping obsolete constants for compatibility.
src/Storages/TimeSeries/PrometheusRemoteWriteProtocol.cpp Reworks remote-write ingestion to use target-table metadata + new settings/types.
src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.cpp Uses normalized settings for timestamp/scalar types.
src/Storages/TimeSeries/normalizeTimeSeriesDefinition.h Adds new API for normalization + normalized settings/columns generation.
src/Storages/TimeSeries/normalizeTimeSeriesDefinition.cpp Implements normalization, inner columns computation, default engines, and backward-compat upgrades.
src/Storages/TimeSeries/createTimeSeriesInnerTable.h Adds helper API to create inner tables from precomputed columns/engines.
src/Storages/TimeSeries/createTimeSeriesInnerTable.cpp Implements inner table creation + canonical inner table naming.
src/Storages/StorageTimeSeriesSelector.cpp Switches selector config/type derivation to use TimeSeries settings and Samples target.
src/Storages/StorageTimeSeries.h Refactors storage to use normalized settings + new target initialization APIs.
src/Storages/StorageTimeSeries.cpp Implements new target resolution/creation, ALTER MODIFY SETTINGS, backup/restore layout updates, and INSERT via TimeSeriesSink.
src/Storages/StoragePrometheusQuery.cpp Switches query evaluation typing to TimeSeries settings.
src/Parsers/ParserViewTargets.h Updates parser API to accept target kinds explicitly and adds canAccept().
src/Parsers/ParserViewTargets.cpp Adds support for SAMPLES + INNER UUID/INNER COLUMNS parsing (and DATA alias).
src/Parsers/ParserCreateQuery.cpp Parses TimeSeries targets as {Samples, Tags, Metrics}.
src/Parsers/CreateQueryUUIDs.cpp Updates UUID serialization/parsing for renamed targets and legacy data kind.
src/Parsers/CommonParsers.h Adds SAMPLES, INNER UUID, INNER COLUMNS keywords; removes old per-target *_INNER_UUID keywords.
src/Parsers/ASTViewTargets.h Adds per-target inner_columns, renames Data->Samples target kind, removes old string conversion helpers.
src/Parsers/ASTViewTargets.cpp Implements formatting/parsing changes for INNER UUID/INNER COLUMNS and new target keywords.
src/Parsers/ASTCreateQuery.h Adds getters/setters for per-target inner columns.
src/Parsers/ASTCreateQuery.cpp Formats TimeSeries targets using Samples instead of Data.
src/Parsers/ASTColumnDeclaration.h Adds resetChild() + convenience reset for default expression.
src/Parsers/ASTColumnDeclaration.cpp Implements child reset with index maintenance.
src/Interpreters/InterpreterCreateQuery.cpp Runs new TimeSeries normalization during create/restore.
src/Core/SettingFieldDataType.h Adds a new Settings field type for DataTypePtr.
src/Core/SettingFieldDataType.cpp Implements parsing/serialization for the new DataTypePtr setting field.
src/Core/SettingFieldASTFunction.h Adds a new Settings field type for ASTFunction.
src/Core/SettingFieldASTFunction.cpp Implements parsing/serialization for the new ASTFunction setting field.
src/Backups/BackupUtils.cpp Normalizes TimeSeries create queries during restore comparison to handle upgrades.
docs/en/sql-reference/table-functions/timeSeriesSamples.md Adds docs for timeSeriesSamples (and mentions timeSeriesData alias).
docs/en/sql-reference/table-functions/timeSeriesData.md Removes old timeSeriesData docs (superseded by timeSeriesSamples).
docs/en/engines/table-engines/integrations/time-series.md Updates docs for SAMPLES terminology and new settings, plus other adjustments.
Comments suppressed due to low confidence (1)

src/Storages/TimeSeries/PrometheusRemoteWriteProtocol.cpp:530

  • toString(table_kind) is used for logging/query-id suffixes, but toString(ViewTarget::Kind) was removed in this PR (see ASTViewTargets). This will not compile and also affects the setCurrentQueryId() call below. Replace it with an explicit conversion (e.g., magic_enum::enum_name(table_kind) or a dedicated helper producing the desired casing).
                const auto & target_table_id = time_series_storage.getTargetTableID(table_kind, context);

                LOG_INFO(log, "{}: Inserting {} rows to the {} table",
                         time_series_storage_id.getNameForLogs(), block.rows(), toString(table_kind));

Comment thread src/Core/SettingFieldDataType.cpp Resolved
Comment thread src/Storages/StorageTimeSeries.cpp Resolved
@nikitamikhaylov nikitamikhaylov self-assigned this Apr 13, 2026
@JTCunning JTCunning added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Apr 13, 2026
@nikitamikhaylov

Copy link
Copy Markdown
Member

@vitlibar we need to increase the index_granularity on the main table 10 times maybe. Based on my research the average size of the granule on this table (uncompressed size) is 250Kb.

@vitlibar
vitlibar force-pushed the improve-time-series-table-engine branch 2 times, most recently from 84ce2ed to e92c9e8 Compare April 16, 2026 20:08
@vitlibar
vitlibar force-pushed the improve-time-series-table-engine branch from e92c9e8 to 3b833b3 Compare April 16, 2026 22:21
@vitlibar
vitlibar requested a review from Copilot April 16, 2026 22:28

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

Copilot reviewed 49 out of 50 changed files in this pull request and generated 5 comments.

Comment thread src/Storages/StorageTimeSeries.h Resolved
Comment thread src/Storages/StorageTimeSeries.cpp Resolved
@vitlibar
vitlibar force-pushed the improve-time-series-table-engine branch from 3b833b3 to c167610 Compare April 16, 2026 23:05
@vitlibar
vitlibar requested a review from Copilot April 16, 2026 23:07

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

Copilot reviewed 49 out of 50 changed files in this pull request and generated 4 comments.

Comment thread src/Storages/StorageTimeSeries.cpp Resolved
@vitlibar
vitlibar force-pushed the improve-time-series-table-engine branch from c167610 to 10d6656 Compare April 17, 2026 01:12
@vitlibar
vitlibar requested a review from Copilot April 17, 2026 01:13

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

Copilot reviewed 49 out of 50 changed files in this pull request and generated 3 comments.

@vitlibar
vitlibar force-pushed the improve-time-series-table-engine branch from 10d6656 to 9e40053 Compare April 17, 2026 01:23
@vitlibar
vitlibar force-pushed the improve-time-series-table-engine branch from 8111c3c to 931ab30 Compare May 22, 2026 22:59
@vitlibar
vitlibar requested a review from Copilot May 22, 2026 22:59

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

Copilot reviewed 48 out of 49 changed files in this pull request and generated 4 comments.

Comment thread src/Storages/StorageTimeSeries.cpp Resolved
Comment thread src/Storages/StorageTimeSeries.cpp Resolved
@vitlibar
vitlibar force-pushed the improve-time-series-table-engine branch from 5c5fce4 to 223c0a0 Compare May 23, 2026 15:04

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

Copilot reviewed 48 out of 49 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/Storages/StorageTimeSeriesSelector.cpp:453

  • filter_by_min_time_and_max_time is applied unconditionally, but min_time/max_time columns may be absent when store_min_time_and_max_time=0 (inner TAGS schema omits them). In that case queries will reference missing columns and fail. Consider guarding this with store_min_time_and_max_time (or checking TAGS table metadata for the columns) so disabling storage of min/max automatically disables filtering-by-min/max.
    if ((*time_series_settings)[TimeSeriesSetting::filter_by_min_time_and_max_time])
    {
        min_time_to_filter_ids = config.min_time;
        max_time_to_filter_ids = config.max_time;
    }

Comment thread src/Storages/StorageTimeSeries.cpp Resolved

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

Copilot reviewed 49 out of 50 changed files in this pull request and generated 3 comments.

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

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

Comment thread src/Parsers/ParserViewTargets.h Resolved
…INNER COLUMNS are enough for customization).

Simplify normalization of TimeSeries create query.
Improve implementation and tests.
@clickhouse-gh

clickhouse-gh Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 80.59% (1590/1973) | lost baseline coverage: 36 line(s) · Uncovered code

Full report · Diff report

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.

5 participants