Skip to content

Add projection merge introspection to system.merges - #102611

Merged
CurtizJ merged 2 commits into
ClickHouse:masterfrom
amosbird:merge-projection-progress
May 27, 2026
Merged

CurtizJ merged 2 commits into
ClickHouse:masterfrom
amosbird:merge-projection-progress

Conversation

@amosbird

@amosbird amosbird commented Apr 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Projection merges were completely invisible in system.merges — during the projection stage, the parent merge's progress stalled with no indication of what was happening. This adds four new columns to expose projection merge state in real time.

Changes:

  • Add current_projection, current_projection_progress, projections_completed, projections_remaining columns to system.merges
  • Track projection state in MergeListElement (protected by mutex), updated from both the merge and rebuild code paths in MergeTask
  • Restore future_part.path for projection sub-merges (was commented out with a TODO)
  • Add merge_task_projection_stage_pause failpoint (PAUSEABLE) for testing
  • Add functional test with two projections that pauses at each projection transition and verifies all four columns

Changelog category (leave one):

  • Improvement

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

Add current_projection, current_projection_progress, projections_completed, and projections_remaining columns to system.merges to expose projection merge progress.

Documentation entry for user-facing changes

  • Documentation is required

Version info

  • Merged into: 26.6.1.185

@clickhouse-gh

clickhouse-gh Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e14a6e9]

Summary: ✅


AI Review

Summary

This PR adds projection-stage introspection to system.merges by wiring projection state/progress from merge and mutation paths into MergeListElement, exposing new columns in StorageSystemMerges, and adding a failpoint-based stateless test that covers merge, rebuild, and materialize flows. Based on the current code and existing discussion threads, I did not find any remaining correctness, safety, or performance blockers.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Apr 13, 2026
@amosbird
amosbird force-pushed the merge-projection-progress branch from c79436b to d233fba Compare April 13, 2026 19:11
Comment thread src/Storages/MergeTree/MergeTask.cpp Resolved
@amosbird
amosbird force-pushed the merge-projection-progress branch 2 times, most recently from 8f9f220 to 8ffef0b Compare April 14, 2026 02:33
@amosbird
amosbird force-pushed the merge-projection-progress branch 2 times, most recently from abb2d14 to 76277f9 Compare April 14, 2026 05:25
@amosbird
amosbird force-pushed the merge-projection-progress branch from 76277f9 to 1298e42 Compare April 14, 2026 06:44
Comment thread src/Storages/MergeTree/MergeTask.cpp Resolved
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@amosbird
amosbird force-pushed the merge-projection-progress branch 5 times, most recently from c373793 to bd6907b Compare April 15, 2026 07:33
@amosbird
amosbird force-pushed the merge-projection-progress branch 7 times, most recently from 7d8b3f7 to 924fb11 Compare April 16, 2026 04:57
Projection merges were completely invisible in `system.merges` — each
projection sub-merge created a standalone `MergeListElement` that was
never registered in the global `MergeList`, so the parent merge's
progress stalled during the projection stage with no indication of
what was happening.

Add six new columns to `system.merges`:

- `current_projection` — name of the projection currently being merged
  or rebuilt, empty when not in the projection stage.
- `current_projection_progress` — row-level progress 0..1 of the
  current projection sub-merge.
- `current_projection_parts_merging` — number of parts being merged
  in the current projection sub-merge step.
- `current_projection_parts_remaining` — number of parts remaining
  for the current projection.
- `projections_completed` — projections finished so far in this merge.
- `projections_remaining` — projections still pending.

Progress is reported via `parent_progress` pointer in child
`MergeListElement`: child writes its progress to parent's
`current_projection_progress` atomically. This is lifetime-safe
because parent always outlives child.

The introspection covers three code paths:

1. Merged projections (`MergeProjectionsStage::executeProjections`)
2. Rebuilt projections (`executeMergeProjections` via
   `MergeProjectionPartsTask`)
3. Mutation projection rebuilds
   (`PartMergerWriter::iterateThroughAllMergeSubtasks`)

Also restores `future_part.path` for projection sub-merges, which was
commented out with a TODO pending introspection support.

Add `merge_task_projection_stage_pause` failpoint (PAUSEABLE) and a
functional test that creates a table with two projections, triggers a
merge, and pauses at each projection transition to verify the
introspection columns.
@amosbird
amosbird force-pushed the merge-projection-progress branch from 924fb11 to bd60853 Compare April 16, 2026 09:35
@CurtizJ CurtizJ self-assigned this Apr 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 97.68% (253/259) | lost baseline coverage: 2 line(s) · Uncovered code

Full report · Diff report

@CurtizJ
CurtizJ enabled auto-merge May 27, 2026 11:41
@CurtizJ
CurtizJ added this pull request to the merge queue May 27, 2026
Merged via the queue into ClickHouse:master with commit de61f17 May 27, 2026
165 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product 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