Skip to content

Implement SELECT query from TimeSeries (part 1) - #115622

Merged
nikitamikhaylov merged 3 commits into
ClickHouse:masterfrom
vitlibar:select-from-time-series-1
Aug 24, 2026
Merged

nikitamikhaylov merged 3 commits into
ClickHouse:masterfrom
vitlibar:select-from-time-series-1

Conversation

@vitlibar

@vitlibar vitlibar commented Aug 20, 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):

Implement SELECT query from TimeSeries

This is part 1 of #106010 (SELECT works, but no push-down filters yet - they will be in a follow-up PR)

@vitlibar vitlibar added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Aug 20, 2026
@vitlibar vitlibar changed the title Select from TimeSeries (part 1) Implement SELECT query from TimeSeries (part 1) Aug 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a3f4a3d]

Summary: ✅


AI Review

Summary

This PR wires SELECT support for TimeSeries tables by rebuilding outer rows from the inner samples, tags, and metrics tables, and adds helper functions used by that reconstruction. The approach is close, but there are two correctness gaps in the current join shape: queries that request time_series drop valid rows whose series array is empty, and the metadata join can duplicate or misattribute rows when different metric families expand to the same member name. CI is green, but these cases are not covered.

PR Metadata
  • 💡 Not for changelog does not match the actual change. This adds user-visible SELECT support for the experimental TimeSeries engine and two new SQL functions, so the category should be Experimental Feature.
  • 💡 Suggested changelog entry: You can now query experimental TimeSeries tables with SELECT, including reconstructed tags, samples, and metric metadata.
Findings

❌ Blockers

  • [src/Storages/TimeSeries/makeASTSelectFromTimeSeries.cpp:673-677] Rows with non-empty metric_name/tags but an empty time_series array are valid on write, but every branch that requests time_series starts from the samples table and therefore drops them completely. INSERT INTO t (metric_name, tags, time_series) VALUES ('x', {'job':'a'}, []) will round-trip through SELECT metric_name, tags FROM t, but disappear from SELECT metric_name, time_series FROM t and from the all-columns read. Suggested fix: build time_series reads from the deduplicated tags side and left-join aggregated samples, or otherwise synthesize [] when a series has no samples row.
  • [src/Storages/TimeSeries/makeASTSelectFromTimeSeries.cpp:505-507] Reconstructing metadata by joining on metric_name = metric_family_name + suffix is ambiguous for accepted data. A counter family errors expands to errors_total, and a gauge family errors_total also expands to errors_total, so a series named errors_total matches both metadata rows and the query returns duplicated/wrong (metric_family, type) pairs. Suggested fix: persist a stable family identifier on the series side and join on that, or fail explicitly when more than one metadata row matches the reconstructed member name.
Tests
  • ⚠️ Add an integration case that inserts metric_name/tags with time_series = [] and verifies that SELECT metric_name, time_series and the all-columns query still return the row with an empty array.
  • ⚠️ Add a case with two families that expand to the same member name, such as ('errors', 'counter') and ('errors_total', 'gauge'), and verify that reads keep the inserted family/type association instead of duplicating rows.
Final Verdict

❌ Request changes. The read plan still loses valid empty-series rows and can return incorrect metadata when family-name expansions collide.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 81.60% 87.00% +5.40%
Functions 91.40% 91.90% +0.50%
Branches 73.60% 79.30% +5.70%

Changed lines: Changed C/C++ lines covered: 410/430 (95.35%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a3f4a3d64 with master bddae8d72 (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
Binary Master PR Δ
programs/clickhouse-stripped 704.40 MiB 701.42 MiB -2.99 MiB (-0.42%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

24 object files changed (+415.28 KiB total), 3 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/TimeSeries/makeASTSelectFromTimeSeries.cpp.o new 172.78 KiB +172.78 KiB
src/Functions/TimeSeries/CMakeFiles/clickhouse_functions_time_series.dir/timeSeriesMetricTypeToSuff… new 112.20 KiB +112.20 KiB
src/Functions/TimeSeries/CMakeFiles/clickhouse_functions_time_series.dir/timeSeriesTagsToMap.cpp.o new 109.42 KiB +109.42 KiB
src/CMakeFiles/dbms.dir/Storages/StorageTimeSeries.cpp.o 469.23 KiB 488.88 KiB +19.64 KiB (+4.19%)

737 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

34 translation units recompiled, 295 s compile time in total, 31 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +13.1 s (+5%) in total before that adjustment.

Translation units without a recent master baseline:

  • src/Storages/TimeSeries/makeASTSelectFromTimeSeries.cpp: 5.4 s

Job report

Comment thread src/Storages/StorageTimeSeries.h Resolved
@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Aug 24, 2026
Merged via the queue into ClickHouse:master with commit e1fe8d8 Aug 24, 2026
182 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 24, 2026
alexey-milovidov added a commit that referenced this pull request Aug 24, 2026
Edited following .claude/skills/edit-changelog/SKILL.md, by hand on a
workstation: the editing step of the NightlyChangelog job has been failing
its own verification since 2026-08-12, so three raw blocks had accumulated
(47 + 84 + 628 entries).

Of the 759 raw entries, 482 are integrated into the in-progress 26.8 section
and 277 are dropped:

- Section 3: the 300 `NOT FOR CHANGELOG / INSIGNIFICANT` entries are dropped,
  except 41 that describe a user-visible change and are promoted into a real
  category, among them a server abort on a corrupt `ORC` stripe footer
  (#114924), `EXPLAIN ANALYZE` for streaming queries (#112445), `SELECT` from
  `TimeSeries` (#115622), streaming watermarks (#106169), and the
  `clickhouse-local` CORS overrides (#115129).
- Section 2: every revert in the range cancels out inside it, so neither side
  appears. Two are re-applications: #114912 re-applies the
  `accurateCastOrDefault` fix, so #109946 keeps its entry with both links and
  the intervening revert #114911 is gone; #114409 re-applies the PromQL
  streaming plan, recorded on the #113656 entry.
- Section 4: `Build/Testing/Packaging Improvement` keeps the seven entries a
  user, packager or from-source builder notices (musl `getaddrinfo` and
  `sched_getcpu`, signed macOS artifacts, Debian packages for release builds
  only, zstd-compressed Docker layers, `unit_tests_dbms` without the full
  library set, vendored Rust built with optimizations locally) and drops the
  CI plumbing.
- Sections 5 and 6: bare pull request URLs converted to links, settings put
  in backticks, four entries rewritten from developer notes into user-visible
  descriptions, and three moved into `Performance Improvement`.

No entry of a strict-retention category was deleted: the job's own
`verify_edit` passes on this edit.

Not done here, because the release manager does it at release time: the full
significance sort, the aggressive merging of sibling pull requests, and the
`FIXME` release date and presentation links.
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.

3 participants