Skip to content

Add unordered stream modifier - #111794

Merged
SmitaRKulkarni merged 7 commits into
masterfrom
Add_unordered_stream_modifier
Aug 13, 2026
Merged

SmitaRKulkarni merged 7 commits into
masterfrom
Add_unordered_stream_modifier

Conversation

@SmitaRKulkarni

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Add STREAM UNORDERED modifier: skip the per-snapshot commit-order sort

depends on #110653
(not for functional reason, only test)

cc @alesapin @Michicosun

@clickhouse-gh

clickhouse-gh Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1223514]

Summary: ✅


AI Review

Summary

This PR adds STREAM UNORDERED by plumbing a new modifier through parsing/analyzer state and by skipping the per-snapshot commit-order sort in MergeTree streaming reads. The parser-side changes look straightforward, but I do not think the runtime contract is mergeable yet: UNORDERED currently breaks cursor-based resume semantics, the older replicated bounded-snapshot enrichment gap is still present, and the new stateless test still does not exercise the CURSOR path it adds risk to.

Findings

❌ Blockers

  • [src/Storages/MergeTree/Streaming/MergeTreeCommitOrderSequentialSource.cpp:152] STREAM CURSOR only works while emitted rows are a prefix in commit order. Once UNORDERED skips the _block_number / _block_offset sort, a merged part can emit a higher cursor before later rows from a lower block, and BuildUnorderedStreamingChunkCursorTransform plus buildPartitionFilter will treat that higher cursor as a checkpoint and filter out unseen rows on resume. Either reject UNORDERED when cursor-resume semantics are in play, or keep a monotone commit-order checkpoint on that path.
  • [src/Storages/MergeTree/Streaming/SubscriptionEnrichment.cpp:35] The enrichment loop still stops reasoning at the last visible local part. If local_parts["p"] is [0,3] while virtual_parts already collapsed an in-flight covering range [0,5], the round advances the safe cursor to 3 and bounded reads can finish even though blocks 4..5 are still only in the queue. That can miss committed rows from the first snapshot on replicated tables. After consuming the last visible local part, the code still needs a promoter check for a covering/pending range above the current cursor.

⚠️ Majors

  • [tests/queries/0_stateless/04627_streaming_queries_unordered.sql:24] The new test only compares aggregate totals for a one-snapshot bounded read. It never exercises the new BuildUnorderedStreamingChunkCursorTransform branch with CURSOR, so it cannot catch resume/checkpoint bugs in the feature this PR changes. A focused STREAM UNORDERED CURSOR ... regression that spans a multi-row chunk and then resumes from that cursor is still missing.
Final Verdict

Changes requested. STREAM UNORDERED is not safe to merge until cursor-resume semantics are either preserved or explicitly rejected, and the replicated bounded-snapshot enrichment gap is closed.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.10% 79.10% +0.00%

Changed lines: Changed C/C++ lines covered: 153/162 (94.44%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jul 24, 2026
@Michicosun Michicosun self-assigned this Jul 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.30% +0.10%
Functions 91.90% 92.00% +0.10%
Branches 78.20% 78.40% +0.20%

Changed lines: Changed C/C++ lines covered: 423/458 (92.36%) · Uncovered code

Full report · Diff report

sort_settings,
/*is_sorting_for_merge_join=*/false));
/// Commit-order sort (_block_number, _block_offset); skipped for unordered streams (ordering holds only between snapshots).
if (!unordered)

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.

STREAM CURSOR only stays correct while the emitted rows are a prefix in commit order. Once this branch skips the _block_number / _block_offset sort, a merged part can legally emit (block 2, offset 0) before later rows from (block 1, offset N) because the physical read order is the table's ORDER BY, not commit order.

BuildUnorderedStreamingChunkCursorTransform keeps only the maximum cursor seen in each emitted chunk, and buildPartitionFilter resumes by dropping every row <= that cursor. If a client checkpoints after the first chunk, the later (1, *) rows from the same snapshot are filtered out even though they were never delivered. Please either reject STREAM UNORDERED CURSOR ... (or otherwise disable resumable cursors on unordered reads), or keep a monotone commit-order checkpoint on any path that promises cursor-based resume semantics.

@Michicosun Michicosun left a comment

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.

LGTM

@clickhouse-gh

clickhouse-gh Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 122351410 with master cf3674390 (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
Binary Master PR Δ
programs/clickhouse-stripped 691.71 MiB 688.71 MiB -3.00 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

@SmitaRKulkarni
SmitaRKulkarni added this pull request to the merge queue Aug 13, 2026
Merged via the queue into master with commit af51155 Aug 13, 2026
182 checks passed
@SmitaRKulkarni
SmitaRKulkarni deleted the Add_unordered_stream_modifier branch August 13, 2026 16:43
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 13, 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.

3 participants