Skip to content

Use Delta, T64, and ALP for TimeSeries sample tables - #120454

Merged
nikitamikhaylov merged 12 commits into
masterfrom
timeseries-alp-samples
Sep 18, 2026
Merged

nikitamikhaylov merged 12 commits into
masterfrom
timeseries-alp-samples

Conversation

@nikitamikhaylov

@nikitamikhaylov nikitamikhaylov commented Sep 16, 2026 •

Copy link
Copy Markdown
Member
image

Use CODEC(Delta, T64, ZSTD(3)) for generated timestamp columns and CODEC(ALP, ZSTD(3)) for generated Float32 and Float64 value columns in the samples and recent samples tables of TimeSeries. Enable ALP in the internal creation context so the default works with enable_alp_codec=0. Explicit column declarations retain their codecs, and CREATE TABLE AS recognizes historical and current defaults.

Related: #120589

The measurements below isolate the value codec change; the timestamp codecs remained unchanged. The combined timestamp and value defaults have not been benchmarked together.

Measured on a dataset containing 413,232 series and 71.4 billion samples over 30 days.

Stored data Before After Change
Main value column 27.38 GB 7.80 GB −71.5%
Main samples table 162.69 GB 143.11 GB −12.0%
Recent value column 3.73 GB 6.75 GB +81.1%
Recent samples table 21.77 GB 24.79 GB +13.9%
All engine target tables 184.48 GB 167.92 GB −9.0%

ZSTD remains useful after ALP: on a stratified 120.3-million-row sample, it reduced the encoded values from 87.8 MB to 13.8 MB.

All 40 queries returned matching results. For the 12 queries reading main samples, geometric-mean latency decreased 4.2% cold and 3.5% warm. The two 30-day CPU panels improved 13–14% cold and 9–11% warm. An additional eight-round check found d09_7d_last_running_by_ns 2.7% slower warm (958 → 984 ms). The 28 queries reading recent samples had essentially unchanged cold latency and 0.3% higher warm latency. Across all 40 queries, measured geometric-mean latency decreased 1.3% cold and 0.9% warm.

Query measurements used the same release binary for both codecs on a Ryzen 9 9950X with 16 physical cores and local NVMe. Each query/codec had two rounds of one cold and two warm requests; results use the median cold time and the median of each round's best warm time. Cold runs restarted the server and evicted the measured files from the page cache. Only the value streams were rewritten.

Changelog category (leave one):

  • Performance Improvement

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

Use Delta, T64, and ZSTD(3) for generated timestamp columns and ALP followed by ZSTD(3) for generated value columns in the samples and recent samples tables of the TimeSeries engine.


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

Version info

  • Merged into: 26.10.1.121 (included in 26.10 and later)

Apply `ALP` before `ZSTD(3)` to generated main sample values and enable
it in the internal creation context. Keep recent samples on `ZSTD(3)`,
which compresses their shorter partitions better in the measured dataset.

Update normalized definitions and document the defaults. Check `Float32`
and `Float64` bit patterns with `enable_alp_codec=0`.
@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [30eb03a]

Summary: ❌

job_name test_name status info comment
Performance Comparison (amd_release, master_head, 2/6) FAIL Performance dashboard
Check Results FAIL IGNORED
Performance Comparison (arm_release, master_head, 5/6) FAIL Performance dashboard
join_convert_to_fixed_hash_table #9 unstable query history IGNORED

AI Review

Summary

This PR switches auto-generated TimeSeries samples and recent-samples codecs to Delta + T64 + ZSTD(3) for timestamp and ALP + ZSTD(3) for value, teaches CREATE TABLE ... AS to treat both historical and current defaults as generated, and enables ALP during internal inner-table creation. The codec round-trip tests look reasonable, but the current implementation still breaks the documented version compatibility contract and changes CREATE TABLE AS semantics for explicit default-looking codecs.

Missing context / blind spots
  • ⚠️ The PR body explicitly says the published benchmark isolates only the value codec change; the final patch also changes the generated timestamp codec, so the combined performance and storage effect is still unmeasured here.
Findings

❌ Blockers

  • [src/Storages/TimeSeries/normalizeTimeSeriesDefinitionImpl.cpp:971-982] [dismissed by author -- https://github.com/Use Delta, T64, and ALP for TimeSeries sample tables #120454#discussion_r4030010889] TimeSeries version is documented as the thing that fixes the target-table structure, but this path now emits CODEC(Delta, T64, ZSTD(3)) and CODEC(ALP, ZSTD(3)) for every version. A CREATE TABLE ... SETTINGS version = 1 therefore no longer reproduces the version-1 schema described in TimeSeriesVersion.h / StorageTimeSeries.cpp, and replaying that DDL on a pre-PR server will still hit the old enable_alp_codec gate during inner-table creation. Suggested fix: bump the TimeSeries schema version and generate the new codecs only from that version onward, or make codec generation explicitly version-aware for older versions.

⚠️ Majors

  • [src/Storages/TimeSeries/normalizeTimeSeriesDefinitionImpl.cpp:628-645] [dismissed by author -- https://github.com/Use Delta, T64, and ALP for TimeSeries sample tables #120454#discussion_r4030010884] CREATE TABLE ... AS is documented to keep customized inner columns, including columns "with a codec", but isGeneratedInnerColumn now strips any source timestamp / value column whose codec text matches either the historical or current defaults. That means a table created with an explicit CODEC(ZSTD(3)) or explicit CODEC(ALP, ZSTD(3)) is silently reinterpreted as "generated" and can change on the next default switch. Suggested fix: either preserve explicit-vs-generated codec intent in metadata, or narrow the CREATE TABLE AS contract and docs instead of claiming that all codec-bearing columns are preserved.
Tests
  • ⚠️ Not run locally. Review is based on the current diff, the added TimeSeries unit/stateless tests, and the available Praktika report.
Final Verdict

Changes requested. The version contract needs to stay stable, and the CREATE TABLE AS contract around explicitly declared codecs is still overstated by the current implementation.

LLVM Coverage Report

Measured on commit 30eb03a.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 80.60% 80.60% +0.00%

Changed lines: Changed C/C++ lines covered: 143/145 (98.62%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 16, 2026
auto create_context = Context::createCopy(context);
/// The default samples codec uses `ALP` independently of the query setting.
if (inner_table_kind == ViewTarget::Samples)
create_context->setSetting("enable_alp_codec", true);

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.

create_context->setSetting("enable_alp_codec", true) lifts the ALP gate for the whole inner samples CREATE, not just for the engine-generated default value codec. A query like CREATE TABLE t ENGINE = TimeSeries SAMPLES INNER COLUMNS (value Float64 CODEC(ALP(RD))) now succeeds even when the user session keeps enable_alp_codec = 0, because the first codec validation happens inside this internal InterpreterCreateQuery. If the goal is only to allow the synthesized default, the bypass needs to be scoped to that generated column instead of turning ALP on for the entire inner-table definition.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's kinda Ok. The TimeSeries has "private preview" tier and ALP is "Beta. Nice to fix for the sake of completeness.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Nikita. I also plan to deprecate the setting soon, so long-term it doesn't matter

if (!codec || is_version_0)
return true;
auto codec_name = codec->formatWithSecretsOneLine();
return (codec_name == "CODEC(ZSTD(3))")

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.

This now classifies SAMPLES INNER COLUMNS (... value Float64 CODEC(ZSTD(3))) as "generated". In the CREATE TABLE copy AS src ENGINE = TimeSeries path, removeGeneratedInnerColumns will drop a source column that the user explicitly declared with plain ZSTD(3), and normalizeInnerColumns later recreates it as CODEC(ALP, ZSTD(3)). That breaks the PR's promise that explicit column declarations keep their codecs. We need some way to distinguish the historical default from an explicit user choice before treating plain ZSTD(3) as auto-generated here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also Ok. We unfold the TimeSeries inner table create statements and store them this way.

{
auto zstd = makeASTFunction("ZSTD", make_intrusive<ASTLiteral>(UInt64{3}));
if (inner_table_kind == ViewTarget::Samples)
value_decl->setCodec(makeASTFunction("CODEC", make_intrusive<ASTIdentifier>("ALP"), zstd));

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.

This applies CODEC(ALP, ZSTD(3)) for every TimeSeries version, including explicitly pinned old versions. The updated EarlierVersionDoesNotRecordIdType expectation now shows version = 1 generating ALP, even though that path is supposed to preserve an older definition that another server can still read. If the default codec changes without a version guard, SETTINGS version = 1 no longer reproduces the historical samples-table definition. This needs to stay CODEC(ZSTD(3)) for older TimeSeries versions, or the codec change needs a new version with version-aware generation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codecs have interoperability.

@rienath rienath self-assigned this Sep 16, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Sep 16, 2026
@nikitamikhaylov

Copy link
Copy Markdown
Member Author

We had similar PRs in the past #114790 and #112110 where the review bot highlighted the same issues.

auto create_context = Context::createCopy(context);
/// The default samples codec uses `ALP` independently of the query setting.
if (inner_table_kind == ViewTarget::Samples)
create_context->setSetting("enable_alp_codec", true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Nikita. I also plan to deprecate the setting soon, so long-term it doesn't matter

Set `CODEC(ALP, ZSTD(3))` as the generated `value` codec for both sample
targets. Enable `ALP` in each internal creation context and recognize the
codec as generated for both targets.

Update the documented defaults and the `Float32` and `Float64` regression
expectations, including round trips with `enable_alp_codec=0`.
@nikitamikhaylov nikitamikhaylov changed the title Use ALP for TimeSeries sample values Use ALP for TimeSeries samples and recent samples Sep 17, 2026
Apply the codec to generated timestamps in both sample targets. Recognize
historical and current generated codecs when copying table definitions.
@clickhouse-gh

clickhouse-gh Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 30eb03ac9 with master 9622a4a67 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of ffb737b38; 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.

Compile time of recompiled translation units

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

Job report

@clickhouse-gh

clickhouse-gh Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

⚠️ AI verdict: not_sure — no significant changes across 39 queries analysed

This PR changes the default compression codecs for auto-generated TimeSeries samples/recent-samples inner tables (timestamp to Delta+T64+ZSTD(3), value to ALP+ZSTD(3)), plus docs and tests. The only flagged query, TPC-H Q1, is a plain scan/aggregation that never creates or reads a TimeSeries table, so the change cannot plausibly touch its execution path. Combined with a noisy, era-unstable baseline (already marked low-confidence), the -20.3% delta reads as run-to-run variance rather than a real effect, so it is downgraded to not_sure. No genuine performance impact from this change is expected on these benchmarks.

clickbench

🟢 No significant changes

tpch_adapted_1_official

⚠️ 1 inconclusive

Flagged queries (1 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 1 not_sure 64 51 -20.3% <0.0001 This PR only changes TimeSeries inner-table default codecs (Delta/T64/ALP), which TPC-H Q1 never touches; the flagged -20.3% on an already noisy, era-unstable baseline is variance, not a PR effect.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: 7ea827c9-78f6-4b89-9537-76cf23eaad78
  • MIRAI run: d1582da8-e57d-4465-80c9-7a436d6d24db
  • PR check IDs:
    • clickbench_704730_1789735643
    • clickbench_704743_1789735642
    • clickbench_704749_1789735642
    • tpch_adapted_1_official_704755_1789735642
    • tpch_adapted_1_official_704766_1789735642
    • tpch_adapted_1_official_704800_1789735642

@nikitamikhaylov

Copy link
Copy Markdown
Member Author

The performance test doesn't even use the TimeSeries engine:

<allow_experimental_time_series_aggregate_functions>1</allow_experimental_time_series_aggregate_functions>

Move the `Delta`, `T64`, and `ZSTD(3)` timestamp defaults into
the `ALP` value codec change for both sample targets.
Preserve both functional tests and combine overlapping expectations.

Related: #120589
Related: #120454
@nikitamikhaylov nikitamikhaylov changed the title Use ALP for TimeSeries samples and recent samples Use Delta, T64, and ALP for TimeSeries sample tables Sep 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

PromQL Compliance Report

Baseline: S3 master 9622a4a67

Metric Baseline Current Δ
Score 96.47% 96.47% +0.00%
Passed 520 520 +0
Failed 3 3 +0
Unsupported 16 16 +0

Note: score is unchanged vs baseline.

Uploaded compliance JSON for this PR commit

@nikitamikhaylov

Copy link
Copy Markdown
Member Author

The two failed performance shards for 30eb03ac92caedffb237c39211b91efab05bee69 hit a timeout on the reference master build. CI report.

  • AMD 2/6 and ARM 5/6 both fail in iceberg_suite_tpch.query4.run0 (TPC-H Q5) with Code: 159, exceeding the 15-second execution limit.
  • The failing measured execution is on reference master commit 9622a4a6709357b33c47dad356ec312c6daef6e3, before the candidate's measured execution. Both prewarm executions succeeded.
  • The reported 10 errors are ten traceback lines from this single test failure in each shard. The too long and unstable-query diagnostics are not what makes these jobs fail; neither failed shard has a flagged slowdown.

This matches the existing join-ordering regression introduced by #120176: relations without row estimates are costed as one row, leading to a poor join order. Fix #120762 is currently open and absent from the tested build. After it merges, merge master into this branch and rerun the failed shards.

Completed comparisons show eight PromQL improvements:

Test / query AMD speedup ARM speedup
promql_selector_pk_range #3 1.473× 1.231×
promql_selector_id_range_row_cost #0 1.264× 1.276×
promql_selector_id_range_row_cost #1 1.211× 1.203×
promql_selector_id_range_row_cost #2 1.241× 1.251×

These comparisons had no faster, slower, or unstable entries in the preceding 30 days of direct master history. They are promising signals from this CI run; they have not been reproduced locally.

The only flagged slowdown is ARM rand #0: 31.5 → 39.5 ms (1.253× slower). It has a history of noise: 23 slower and four unstable results in 727 direct master runs. Its shard passed. ARM also reports improvements in optimize_time_filter_with_preimage #1 (1.514×) and #6 (1.222×); their history makes attribution to this PR uncertain.

Related: #120762

Related: #120176

@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Sep 18, 2026
Merged via the queue into master with commit 7542208 Sep 18, 2026
174 of 177 checks passed
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-performance Pull request with some performance improvements 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