Skip to content

Avoid vertical TTL delete for TTLDrop merges - #108626

Merged
murphy-4o merged 3 commits into
ClickHouse:masterfrom
EmeraldShift:mj/ttldrop-no-vertical-ttl-delete
Sep 24, 2026
Merged

murphy-4o merged 3 commits into
ClickHouse:masterfrom
EmeraldShift:mj/ttldrop-no-vertical-ttl-delete

Conversation

@EmeraldShift

@EmeraldShift EmeraldShift commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

TTLDrop merges know that all source rows are expired. The vertical TTL-delete path still scans key rows to write an all-skipped row-source file, which can make fully expired large parts very expensive to drop. Use the existing horizontal all-data-dropped short-circuit for this case instead.

I think this behavior is a bug, because it doesn't match the expected behavior of efficiently TTL dropping expired parts, especially with ttl_only_drop_parts = 1. It would be nice to have this fix backported to recent stable releases, please.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed dropping whole parts with TTL (ttl_only_drop_parts = 1) still reading all data from large, fully-expired parts.


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

Version info

  • Merged into: 26.10.1.562-master (included in 26.10 and later)
  • Backported to: 26.9.2.25, 26.8.11.30, 26.7.14.36, 26.3.33.142

@EmeraldShift

EmeraldShift commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor Author

@Avogar We discovered a more expensive form of the issue #105639, where large / wide parts trigger a Vertical merge which doesn't just read the first block from all streams, it reads all blocks.

This is a much simpler patch than #105859 (which is great!), which moves from "all blocks" to "one block", and then your PR moves from "one block" to "zero blocks". Would you be willing to review and merge this as a first step, and can I ask that we backport this to stable and LTS releases since we're seeing some existing clusters degraded due to the current behavior?

@EmeraldShift

EmeraldShift commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Git blame points to #97332 as the potential culprit, so this is present in 26.4 and later, but not 26.3

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ddd4b8a]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) FAIL
The mutation submitted before the upgrade was not finished by the new server (see mutation_across_upgrade.txt) FAIL cidb IGNORED
Error message in clickhouse-server.log (see upgrade_error_messages.txt) FAIL cidb IGNORED
Performance Comparison (arm_release, master_head, 1/6) FAIL Performance dashboard
optimize_time_filter_with_preimage #1 FAIL dashboard IGNORED
arrow_format #0 unstable query history IGNORED
arrow_format #1 unstable query history IGNORED
rand #0 unstable query history IGNORED
rand #1 unstable query history IGNORED

AI Review

Summary

This PR forces TTLDrop merges backed by an unconditional rows TTL onto the horizontal path so fully expired parts avoid the vertical rows_sources scan, and it adds focused stateless coverage for both plain rows TTL and mixed rows TTL plus RECOMPRESS definitions. I reviewed the current code, the PR diff, and the full prior discussion history, and I did not find any new blocker or major issue beyond the already resolved thread history.

Final Verdict

✅ No new blocking findings. Residual risk is limited to performance evidence: the new test proves the observable contract (TTLDropMerge logs Horizontal) but does not benchmark the read-volume reduction directly.

LLVM Coverage Report

Measured on commit ddd4b8a.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.40% +0.00%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 26, 2026
Comment thread src/Storages/MergeTree/MergeTask.cpp Resolved
@EmeraldShift
EmeraldShift force-pushed the mj/ttldrop-no-vertical-ttl-delete branch 2 times, most recently from 8909d33 to 5cc5b80 Compare June 26, 2026 20:14
Comment thread src/Storages/MergeTree/MergeTask.cpp Resolved
TTLDrop merges with only an unconditional rows TTL know that all source rows are expired. The vertical TTL-delete path still scans key rows to write an all-skipped row-source file, which can make fully expired large parts expensive to drop.

Use the existing horizontal TTLTransform all-data-dropped short-circuit for that case instead, while keeping vertical TTL delete enabled for partial and conditional TTL deletes.

Add regression coverage that a background TTLDropMerge selected under vertical-merge thresholds uses the horizontal algorithm.
@EmeraldShift
EmeraldShift force-pushed the mj/ttldrop-no-vertical-ttl-delete branch from 5cc5b80 to 3585ceb Compare June 26, 2026 21:31
@clickhouse-gh

clickhouse-gh Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.40% +0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 5/5 (100.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code

Full report · Diff report

@murphy-4o

Copy link
Copy Markdown
Member

Hi @EmeraldShift, I’m closing this PR as #105859 has been merged and provides a more efficient solution. Please feel free to share any further ideas or suggestions you may have!

@murphy-4o murphy-4o closed this Sep 22, 2026
@murphy-4o

Copy link
Copy Markdown
Member

Correction: #97332 is in 26.4, while #105859 is in 26.8. We should merge and backport these changes to avoid regressions in the intermediate versions.

Why not backport #105859? While the fix itself is simple, the associated follow-up PRs make the backporting process more complex.

@murphy-4o murphy-4o reopened this Sep 22, 2026
@murphy-4o

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request.

Comment thread src/Storages/MergeTree/MergeTask.cpp Resolved
Comment thread src/Storages/MergeTree/MergeTask.cpp Resolved
murphy-4o and others added 2 commits September 23, 2026 12:49
…rop-no-vertical

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…l the test on timeout

canVerticalTTLDelete answers whether a TTL delete can run vertically; forcing a
TTLDrop merge horizontal is an algorithm choice, so it now lives in
chooseMergeAlgorithm, inside the need_remove_expired_values branch. A merge whose
TTL removal was cancelled after selection may therefore still go vertical.

04411_ttl_drop_not_vertical polls part_log in a single loop and fails with an
explicit error when the TTLDrop merge never shows up.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ddd4b8ac6 with master b1224b869 (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

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

Job report

@murphy-4o
murphy-4o added this pull request to the merge queue Sep 24, 2026
Merged via the queue into ClickHouse:master with commit fbb92cb Sep 24, 2026
173 of 176 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 24, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 24, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 24, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 24, 2026
Backport #108626 to 26.9: Avoid vertical TTL delete for TTLDrop merges
clickhouse-gh Bot added a commit that referenced this pull request Sep 24, 2026
Backport #108626 to 26.8: Avoid vertical TTL delete for TTLDrop merges
murphy-4o added a commit that referenced this pull request Sep 24, 2026
Backport of the 03737 part of f432f74 (#105859). With #108626 a
TTLDrop merge is always Horizontal, so a background TTLDrop merge that
races OPTIMIZE FINAL flips test1_algo, and test2 (all rows expired) is a
TTLDrop merge whose algorithm is no longer Vertical.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
murphy-4o added a commit that referenced this pull request Sep 24, 2026
Backport of the 03737 part of f432f74 (#105859). With #108626 a
TTLDrop merge is always Horizontal, so a background TTLDrop merge that
races OPTIMIZE FINAL flips test1_algo, and test2 (all rows expired) is a
TTLDrop merge whose algorithm is no longer Vertical.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
clickhouse-gh Bot added a commit that referenced this pull request Sep 24, 2026
Backport #108626 to 26.7: Avoid vertical TTL delete for TTLDrop merges
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
murphy-4o added a commit that referenced this pull request Sep 25, 2026
Backport #108626 to 26.3: Avoid vertical TTL delete for TTLDrop merges
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 2, 2026
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-ttl TTL rules and TTL merges (moving/recompressing/rolling-up/deleting parts). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants