Skip to content

Do not estimate a column's compressed size with a codec its sample does not match - #118335

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-autopr-sparse-column-codec-estimate
Sep 6, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-autopr-sparse-column-codec-estimate

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

Related: #114535

The AutoPR input-bytes estimate for a compact part serializes a sample of every column it reads and compresses it with the column's CODEC, resolved once per read task from the table metadata. The metadata does not describe that sample on its own, and the estimate applied the type-specific codec regardless:

  • the serialization is chosen per block from the column at hand, so a column stored Sparse (or Replicated) arrives as several substreams funnelled into one buffer;
  • a column read from a part keeps its pre-ALTER type until the mutation that rewrites it has run, while the codec was resolved for the new type.

A type-specific codec then measures a stream it was never resolved for. Most only mismeasure it, but ALP validates its input and fails the query outright:

Code: 270. DB::Exception: Cannot compress with ALP(RD) codec, data size 19209 is not aligned to 4:
While executing MergeTreeSelect(pool: ReadPoolInOrder, algorithm: InOrder). (CANNOT_COMPRESS)

This broke 04035_alp_rd_codec_special_values and 03743_alp_codec_special_values on master whenever the settings randomizer turned on both automatic parallel replicas and sparse serialization. The failures start on 2026-09-05, the day #114535 was merged, and there is no open issue tracking them.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=3324e948a5143641935d0389afbe55193545c4f2&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29

The fix resolves both the type-specific and the generic-only codec up front and picks between them from the serialization and the type the sample actually has, keeping only the generic codecs for every other shape - exactly what the writer does for structural substreams.

Both triggers are reproduced by the new test 05099_autopr_input_bytes_estimation_sparse_column_codec, which fails on master and passes here.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Version info

  • Merged into: 26.9.1.850 (included in 26.9 and later)

…es not match

The input-bytes estimate for a compact part serializes a sample of every column it
reads and compresses it with the column's `CODEC`, resolved once per read task from
the table metadata. The metadata does not describe that sample on its own, and the
estimate used the type-specific codec regardless:

- the serialization is chosen per block from the column at hand, so a column stored
  `Sparse` (or `Replicated`) arrives as several substreams funnelled into one buffer;
- a column read from a part keeps its pre-`ALTER` type until the mutation that
  rewrites it has run, while the codec was resolved for the new type.

A type-specific codec then measures a stream it was never resolved for. Most only
mismeasure it, but `ALP` validates its input and fails the query outright:

    Cannot compress with ALP(RD) codec, data size 19209 is not aligned to 4.
    (CANNOT_COMPRESS)

Resolve both the type-specific and the generic-only codec up front and pick between
them from the serialization and the type the sample actually has, keeping only the
generic codecs for every other shape - exactly what the writer does for structural
substreams.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=3324e948a5143641935d0389afbe55193545c4f2&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29
Caused by: #114535
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2a455ec]

Summary: ✅


AI Review

Summary

This PR fixes the compact-part input-bytes estimator so it stops recompressing samples with a type-specific CODEC when the sampled serialization is multi-stream or still carries a stale pre-ALTER type. I reviewed the current diff together with the surrounding MergeTree read path and RuntimeDataflowStatistics code, and I did not find a remaining correctness, safety, or coverage issue that warrants an inline comment.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 2a455ec.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.10% -0.10%

Changed lines: Changed C/C++ lines covered: 44/44 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... labels Sep 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2a455ec89 with master 5cbca3e09 (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

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

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

Job report

@alexey-milovidov alexey-milovidov left a comment

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.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 6, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 6, 2026
Merged via the queue into master with commit 6c33583 Sep 6, 2026
174 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-autopr-sparse-column-codec-estimate branch September 6, 2026 15:26
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... 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.

2 participants