Skip to content

Avoid rewriting compact parts during TTL recalculation - #125025

Merged
alesapin merged 15 commits into
ClickHouse:masterfrom
seva-potapov:fix/124351-compact-ttl-recalculate
Nov 17, 2026
Merged

alesapin merged 15 commits into
ClickHouse:masterfrom
seva-potapov:fix/124351-compact-ttl-recalculate

Conversation

@seva-potapov

@seva-potapov seva-potapov commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Reuse the partial-mutation path without a data writer for compact parts with Full storage. Exclude uuid.txt from hardlinks and capture materialize_ttl_recalculate_only once during mutation preparation.

Closes: #124351

Changelog category (leave one):

  • Performance Improvement

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

Avoid rewriting non-packed compact parts during MATERIALIZE TTL when materialize_ttl_recalculate_only = 1.


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

Version info

  • Merged into: 26.11.1.2571-master (included in 26.11 and later)

@seva-potapov seva-potapov added the can be tested Allows running workflows for external contributors label Oct 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [31b5ce9]

Summary: ✅


AI Review

Summary

This PR avoids rewriting eligible Compact parts with Full storage during MATERIALIZE TTL when materialize_ttl_recalculate_only = 1, snapshots the TTL settings used for mutation planning, and preserves the hardlinked data's metadata. No actionable findings remain in the current code, including the issues from previous review threads. The current-head Fast test passed the deferred-projection regression. Focused local checks with the PR binary passed for payload inode preservation, source TTL metadata preservation, block columns, missing default-column TTL inputs, changed format policies, type changes, recompression codec metadata, complex serializations, and reloads.

Missing context / blind spots
  • ⚠️ The current-head integration jobs were still pending when inspected. The setting-race tests were reviewed but were not executed locally; passing results for test_mutations_hardlinks would complete that runtime validation.
Final Verdict

Status: ✅ Approve. No code changes requested. Integration CI remains pending.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 10, 2026
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). label Oct 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 31b5ce9a2 with master d6bf47a42 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 5c48e43bc; 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

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

Job report

seva-potapov and others added 3 commits October 10, 2026 07:23
When canRecalculateTTLWithoutRewritingData() rejects the in-place path,
ctx->recalculate_ttl_only is correctly set to false, but the interpreter
was still receiving the raw table setting. This caused getUpdatedHeader()
to prune write columns even when a full rewrite was needed, breaking the
compact-part fallback with "none of its columns would remain".

Co-Authored-By: Claude Opus 4.6 <[email protected]>
When ctx->recalculate_ttl_only is false (wide parts where
canRecalculateTTLWithoutRewritingData returns false), unconditionally
setting settings.materialize_ttl_recalculate_only = false overrides the
table-level materialize_ttl_recalculate_only = 1 setting. This causes
the interpreter to apply the TTL (deleting rows) instead of only
recalculating TTL metadata, breaking the existing 02129_add_column_add_ttl
test.

Only set the optional when the compact-part optimisation is active;
otherwise leave it as nullopt so the interpreter falls back to reading
the table setting.
The false value was not being passed to MutationsInterpreter::Settings,
causing the interpreter to fall back to re-reading the live table setting.
This created a race when the setting was changed between mode selection
and interpreter preparation.
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@seva-potapov
seva-potapov requested a review from alesapin October 19, 2026 01:22
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@alesapin alesapin self-assigned this Oct 21, 2026
Comment thread src/Interpreters/MutationsInterpreter.h Resolved
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@seva-potapov
seva-potapov force-pushed the fix/124351-compact-ttl-recalculate branch from 8d2c948 to 4092d97 Compare October 22, 2026 14:52
The else branch in MutateTask::prepare() had multiple statements without
braces, causing only the first (a redundant variable declaration) to be
conditional. This triggered -Wshadow, -Wmisleading-indentation, and
-Wunused-variable errors.

The redeclared suitable_for_ttl_optimization is unnecessary — it was
already computed above using the snapshotted merge_tree_settings.
…ttl-recalculate

Conflicts in src/Storages/MergeTree/MutateTask.cpp:
- collectFilesToSkip: keep both new entries, secondary_index_column_types.json (ClickHouse#122846) and uuid.txt.
- PartMergerWriter::prepare: keep the recalculate_ttl_only chassert, drop the squash memory cap
  that master reverted (ClickHouse#128706).
@alesapin
alesapin added this pull request to the merge queue Nov 17, 2026
Merged via the queue into ClickHouse:master with commit 3467bc1 Nov 17, 2026
186 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 17, 2026
Master's ClickHouse#125025 skips the column writer of MutateSomePartColumnsTask when
the mutation only recalculates TTL. Keep that guard around the writer, after
the TTL transforms, which still read the rewritten column list computed above.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 18, 2026
…-only-mutation-space

Conflicts in MutateTask.cpp, ReplicatedMergeTreeQueue.cpp and StorageMergeTree.cpp:
- mutationRequiresFullPartRewrite, which replaced the shape predicate in rewritesAllPartColumns
  and splitAndModifyMutationCommands, now uses isPerFilePartStorage (ClickHouse#126865), and
  splitAndModifyMutationCommands keeps master's future_storage_type condition and
  getColumnNameInStorage.
- processStatisticsChanges takes master's new parameters and rename handling and keeps
  the bool result and the early return for unchanged statistics.
- The !recalculate_ttl_only condition (ClickHouse#125025) moves into requires_full_part_rewrite,
  which rewrites_all_columns reuses.
- The queue keeps both master's source_parts and mutation_source_part.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). 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.

MATERIALIZE TTL with materialize_ttl_recalculate_only = 1 rewrites compact parts completely

3 participants