Skip to content

Support Read Limits for Streaming Queries - #116531

Closed
Michicosun wants to merge 8 commits into
masterfrom
streaming_queries_forbid_read_limits
Closed

Michicosun wants to merge 8 commits into
masterfrom
streaming_queries_forbid_read_limits

Conversation

@Michicosun

@Michicosun Michicosun commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

This patch supports the usage of max_rows_to_read, max_bytes_to_read, max_rows_to_read_leaf, and max_bytes_to_read_leaf settings with streaming queries.


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

@rienath rienath self-assigned this Aug 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3d28a05]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, WasmEdge, parallel, 2/3) FAIL
05046_streaming_queries_storage_limits FAIL cidb
Stress test (arm_debug) FAIL
Logical error: 'Inconsistent AST formatting: the query: (STID: 1941-26fa) FAIL cidb

AI Review

Summary

This PR moves STREAM limit handling out of the inner MergeTree read plan so bounded streaming queries can stop cleanly instead of breaking stream alignment. The current implementation still changes the contract of max_*_to_read / max_*_to_sort in material ways and regresses other existing limit checks, so I think it still needs changes before merge.

Findings

❌ Blockers

  • [src/Storages/MergeTree/Streaming/MergeTreeCommitOrderSource.cpp:246] max_rows_to_read / max_bytes_to_read and the _leaf variants are now enforced from StreamReadProgress, which is incremented from the final round output in handleRunningPipeline. That counts rows after PREWHERE / row-policy filtering and after the projection in buildPartitionReadingPipeline, and watermark queries read a second metadata stream that is not counted at all. A streaming query can therefore read far more physical rows or bytes than the configured limit without read_overflow_mode firing at the right point.
  • [dismissed by author -- https://github.com/Support Read Limits for Streaming Queries #116531#discussion_r3871345857] [src/Storages/MergeTree/Streaming/ReadingPlan/buildReadRoundPipeline.cpp:146] The hidden commit-order SortingStep still runs with size_limits = {}. The new outer current_round_read_rows check only sees rows after the per-partition sort has already happened, and MergeSortingTransform drains its whole input before emitting anything, so a large partition round can still fully sort before any max_rows_to_sort / max_bytes_to_sort guardrail has a chance to stop it.
  • [dismissed by author -- https://github.com/Support Read Limits for Streaming Queries #116531#discussion_r3871345861] [src/Storages/MergeTree/Streaming/MergeTreeCommitOrderSource.cpp:86] The inner round plan still receives an empty storage_limits list, so ReadProgressCallback stops enforcing min_execution_speed, min_execution_speed_bytes, max_execution_speed, max_execution_speed_bytes, and max_estimated_execution_time for STREAM queries. The new outer accounting only restores row/byte and sort checks; the existing speed and estimate guardrails are still gone.
Tests
  • ⚠️ The new stateless test only proves "some rows are returned" or "an exception is thrown". It does not prove that max_*_to_read is driven by source-side read volume rather than post-filter output. A focused PREWHERE or watermark case would close that gap.
  • ⚠️ max_*_to_sort still needs a focused case that proves the limit is enforced at each hidden commit-order sort, not after the merged round output is already produced.
  • ⚠️ There is still no coverage showing that STREAM queries keep honoring max_execution_speed, max_execution_speed_bytes, or max_estimated_execution_time.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  • Drive max_*_to_read from actual source read progress, not from emitted round chunks.
  • Restore max_*_to_sort enforcement at the hidden sort boundary instead of after the round output is already produced.
  • Preserve the existing speed / estimated-execution limit checks for streaming queries.

LLVM Coverage Report

Measured on commit 3d28a05.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.70% 80.70% +0.00%

Changed lines: Changed C/C++ lines covered: 118/127 (92.91%) · Uncovered code

Full report · Diff report

@Michicosun
Michicosun force-pushed the streaming_queries_forbid_read_limits branch from cd72bd3 to 3d93866 Compare August 27, 2026 11:09
@Michicosun Michicosun changed the title Forbid Read Limits for Streaming Queries Support Read Limits for Streaming Queries Aug 27, 2026
}

auto chunk = input.pull(/*set_not_needed=*/true);
read_progress.accountChunk(chunk);

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.

StreamReadProgress here is counting the final read-round output, not the source-side read progress that max_rows_to_read / max_bytes_to_read / max_rows_to_read_leaf / max_bytes_to_read_leaf are defined on. buildPartitionReadingPipeline applies PREWHERE / row-policy filters and the final projection before these chunks reach MergeTreeCommitOrderSource, and watermark queries read a second metadata stream that never passes through this counter at all. A STREAM ... WATERMARK ... PREWHERE ... SETTINGS max_rows_to_read = 10 query can therefore read far more than 10 physical rows without tripping isReadLimitReached. I think the outer check needs to consume the existing source progress (ProcessListElement::getProgressIn() / ReadProgressCallback) instead of emitted chunks.

@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3d28a0514 with master b8cd25afc (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 712.33 MiB 709.28 MiB -3.05 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.

Object file sizes

9 object files changed (+46.42 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/MergeTree/Streaming/ReadingPlan/buildReadRoundPipeline.cpp.o 137.70 KiB 196.76 KiB +59.06 KiB (+42.89%)
src/CMakeFiles/dbms.dir/Storages/MergeTree/Streaming/MergeTreeCommitOrderSource.cpp.o 257.75 KiB 239.84 KiB -17.90 KiB (-6.95%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

1073 translation units recompiled, 7459 s compile time in total, 1072 of them have a recent master baseline.

Job report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants