Repository navigation
Conversation
With parallel_replicas_min_number_of_rows_per_replica > 0 the analyzer asks ReadFromMergeTree for a row estimate to size the replica set. That estimate ran selectRangesToRead(), which analyzes with check_row_limits = true, so MergeTreeDataSelectExecutor charged the whole-granule row count of the base table against max_rows_to_read and threw TOO_MANY_ROWS at plan-build time. The projection escape hatch cannot help there: has_projections does not see the implicit _minmax_count_projection (it lives in StorageInMemoryMetadata::minmax_count_projection, not hasProjections()), and projection selection only runs later, in optimizeTreeSecondPass. So SELECT max(i) FROM x SETTINGS max_rows_to_read = 2 was rejected on a 10-row table even though _minmax_count_projection answers it without reading a single data row. Route that estimate through the non-enforcing, non-memoizing analysis whenever a throwing read row limit is set, which is what PR ClickHouse#110283 ("Defer read limits until read order is known", 5b6b32b) already established for the join cardinality estimator. Commit 113ce6b kept this call site on the pre-existing row-limit path during a conflict resolution; that pre-existing behaviour is the defect. Enforcement is unchanged for the read that executes: neither estimation entry point memoizes into analyzed_result_ptr, so the executed ReadFromMergeTree analyzes again through selectRangesToRead() and still throws when the read really exceeds the budget. The new test pins both directions, including sum() (which no implicit projection can serve) and the same query with optimize_use_implicit_projections = 0. The two estimate entry points collapse into one: selectRangesToReadForEstimation now takes allow_query_condition_cache_, so the query-condition-cache axis and the row-limit axis are independent, and estimateRangesToReadWithoutQueryConditionCache is gone. RelationStatisticsEstimator reuses the new hasThrowingReadRowLimit() predicate instead of its own inline copy (no behaviour change there). Surfaced by the randomization in ClickHouse#71028. Related: ClickHouse#71028 Co-Authored-By: Claude Opus 5 <[email protected]>
…test The test set parallel_replicas_only_with_analyzer = 0, advertising that it also runs with the old analyzer, and then asserted that SELECT max(i) FROM x SETTINGS max_rows_to_read_leaf = 2 returns 9. That is false with enable_analyzer = 0: the old-analyzer estimator in adjustParallelReplicasAfterAnalysis caps query_info_copy.trivial_limit with max_rows_to_read only, so the leaf limit stays armed and the read still throws. The fix lives in src/Planner/, so pin enable_analyzer = 1 and drop the opt-out, matching 03560_parallel_replicas_projection.sql, which pins it on the very query this test copied. Every assertion was result-only, and the planner declines parallel replicas silently (it sets allow_experimental_parallel_reading_from_replicas = 0 itself when the estimate does not justify a second replica). A regression that stopped reaching the estimate under test would therefore have left the whole test green while covering nothing: the positives pass because the query is simply correct locally, and the negatives pass because a local read enforces the limit anyway. Add a ParallelReplicasQueryCount witness per shape under test, following 04830_pr_plan_based_clone_marked_read.sql. Both witnesses were mutation-tested rather than assumed live. Forcing parallel_replicas_for_non_replicated_merge_tree = 0, and separately forcing the silent-decline path with parallel_replicas_min_number_of_rows_per_replica = 1000, each flip exactly those two lines from 1 to 0 and fail the test, while all the other assertions stay green. Also flatten the estimate's call-site ternary. Two of its three arms called the same function, so the guard is just hasThrowingReadRowLimit() || !allow_query_condition_cache which is equivalent over the whole truth table. No behaviour change: the repro, both row-limit arms, the read-order pair, all four negative controls and the new test's FAIL-on-base / OK-on-fix pair were re-measured on the rebuilt binary. Co-Authored-By: Claude Opus 5 <[email protected]>
The ParallelReplicasQueryCount witnesses added earlier prove that parallel replicas engaged, which is a weaker proposition than the one the test needs: that the replica-count sizing estimate ran at all. At parallel_replicas_min_number_of_rows_per_replica = 1 neither branch of the sizing block fires (x sizes to 10 replicas, t clamps to 5 via trivial_limit), and parallel replicas are engaged by a later step, so a regression that stopped reaching the estimate would have left every assertion green. Pair the projection query with the same query under a threshold the 10-row table cannot meet, which reaches the block's silent decline, and assert zero engagement for it. Measured: making the block's threshold guard a no-op flips that row alone and reddens the test, while every other assertion stays green. The declined case is also fix-live in its own right (TOO_MANY_ROWS before the change, 9 after), and it is ordered first so no earlier coordinator can perturb its counter. The changelog entry covers max_rows_to_read and max_rows_to_read_leaf, and hasThrowingReadRowLimit() reads both, but every negative control used max_rows_to_read only, so nothing pinned that the executed read still enforces the leaf limit. Add the leaf counterpart of the sum() control; it throws on both binaries, naming max_rows_to_read_leaf in the message. Narrow the call-site comment: its reanalysis clause holds only on the branch it justifies, since the other arm memoizes the analysis the executed read reuses. Co-Authored-By: Claude Opus 5 <[email protected]>
clickhouse-test re-runs a FAILED test up to MAX_RETRIES = 3 times, and with
--database passed it reuses the same database on every attempt. The Stress test
and the Upgrade check pass a fixed database (ci/jobs/scripts/stress/stress.py
pins odd and replicated-database workers to test_{i}), and system.query_log rows
outlive the execution, so an earlier attempt's rows satisfied every predicate of
the two witnesses: the paired probe returned 4 rows against a 2-row reference and
the read-order probe 2 against 1. Because MESSAGES_TO_RETRY is dominated by the
transients the Stress lane manufactures on purpose, a transient the retry
machinery exists to absorb turned into a permanent red on this test.
Both probes now take the latest QueryFinish row per log_comment with
argMax(..., event_time_microseconds), the idiom of
04490_join_runtime_filters_index_analysis.sql. SYSTEM FLUSH LOGS query_log runs
immediately before each probe, so the current attempt's rows are the newest and
"latest" is exactly "this attempt". initial_query_id = query_id stays: with
parallel replicas engaged the secondary queries inherit log_comment and carry the
counter at 0, so dropping it would let a secondary row win the argMax. The
reference is unchanged, and both witnesses still redden under the mutations they
were added to catch, including the source-level one that makes the sizing block
unreachable and flips the paired row alone.
The comment above the paired case said a regression that stopped reaching the
sizing block would leave both counters unchanged. It is the opposite: the
declined counter goes 0 -> 1 there, which is why the pair is a live witness.
Co-Authored-By: Claude Opus 5 <[email protected]>
Drop the call-site narration in PlannerJoinTree.cpp and state the two new ReadFromMergeTree declarations' properties in one line each.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 8 findings over 4 rounds; 1 full pass plus
Also considered and declined, with evidence: pinning Checked and not a defect: this estimate no longer memoizes, so later passes see no memoized analysis. That is the ordinary state, since every query at the default Open #120011 gives Severity: ❌ blocker / Session id: cron:clickhouse-publish-slot-34:20260921-042300 |
|
Workflow [PR], commit [f2c235f] Summary: ✅
AI ReviewSummaryThis PR correctly routes the legacy Findings
Final Verdict
LLVM Coverage Report |
The read-order case took its `max_rows_to_read` budget from 02155_read_in_order_max_rows_to_read, whose read is single-node. Under parallel replicas each contributing replica charges whole granules of its slice and the initiator sums their progress, so the rows charged for `ORDER BY a LIMIT 5` depend on how many granules reach a reader: measured 8 on local disk and 32 on s3 storage with the same fixture. The two s3 parallel lanes therefore failed deterministically at `current rows: 20.00` while every local-disk lane passed. The throw came from the read that executes, not from the plan-build estimate this PR changes (that would have charged the whole 100 rows), so the product contract is unaffected. Widen the budget to 60 and pair the control with it at LIMIT 80, which keeps both propositions: on the unfixed binary the positive still throws at plan build charging the whole table, and on the fixed one the control still throws inside ReadPoolParallelReplicasInOrder. Verified with the reviewed fix binary against an s3-backed server (own MinIO, parts on cached_s3): 50/50 randomized and 50/50 not, plus 50/50 in both modes on local disk, and the charge measured at 32 in 51/51 runs.
CI fix on
|
| /// limits. In that case use an estimation-only analysis; execution will analyze again | ||
| /// after its final read mode is known. | ||
| analyzed_result = has_throwing_row_limit ? reading->selectRangesToReadForEstimation() : reading->selectRangesToRead(); | ||
| analyzed_result = reading->hasThrowingReadRowLimit() |
There was a problem hiding this comment.
This only fixes the legacy RelationStatisticsEstimator path. With make_distributed_plan = 1 and enable_cascades_optimizer = 1, optimizeTree.cpp:427-428 skips optimizeReadInOrder, but the Cascades stats code still does a direct selectRangesToRead() in src/Processors/QueryPlan/Optimizations/Cascades/Statistics.cpp:308-309 and src/Processors/QueryPlan/Optimizations/Cascades/StatisticsDerivation.cpp:382-383. A query like SELECT a FROM t ORDER BY a LIMIT 5 SETTINGS max_rows_to_read = 12, make_distributed_plan = 1, enable_cascades_optimizer = 1 can therefore still raise TOO_MANY_ROWS during statistics derivation, before the worker fragment is re-optimized into the exempt read-in-order shape. This needs the same non-enforcing estimate path (or a shared helper for all pre-final-shape statistics callers), otherwise the fix remains incomplete on the Cascades/distributed-plan path.
Reproduced, and wider than the two sites namedIt throws on this branch, so the finding is real. Stack: It is a false rejection, not just an early one. With the budget raised until the estimate stops Two corrections.
I am not widening this PR for it. Its scope is the parallel-replicas replica-count estimate, and the |
|
Follow-up on the pre-final estimate sites from the review comment above (this is the separate-tracking The sites. Under Measured false rejection. Why I did not simply make the four sites non-enforcing. For a distributed plan that coordinator
Control: Two adjacent gaps, for the record. A bucketed fragment's analysis-time check runs against the whole The decision I would like from a maintainer. Making the estimates non-enforcing requires the
Options 1 and 2 also make distributed fragments start enforcing a limit they ignore today, which is what |
CI finish ledger - cae048bEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Gates (a) to (d): 0 of 176 check runs queued or running, Session id: cron:our-pr-ci-monitor:20260921-140539 |
|
@copilot resolve the merge conflicts in this pull request |
…stimate-row-limit-71028-class1 # Conflicts: # src/Processors/QueryPlan/ReadFromMergeTree.cpp
|
Resolved the conflicts by merging current master in f2c235f. The only conflict was master's new |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units120 translation units recompiled, 1403 s compile time in total, 120 of them have a recent master baseline. |
|
Hi @nickitat, gentle ping on the question above: which option do you want for giving a distributed fragment the read's row limits (1 serialize |
create in issue for that and ask davenger for an advice |
ClickHouse#121269 fixed the same defect on master: the replica-count estimate takes the estimation-only analysis when the read step carries a throwing row limit. Drop this branch's src/ change and keep 05233, which covers the automatic parallel replicas probe with force_primary_key (05250 pins automatic_parallel_replicas_mode = 0). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
TOO_MANY_ROWSbeing raised for a query that stays within itsmax_rows_to_readbudget whenparallel_replicas_min_number_of_rows_per_replicais set. The estimate sizing the replica set enforced the limit against whole granules at planning time.Description
Surfaced by #71028's randomization (class 1 there). With
parallel_replicas_min_number_of_rows_per_replica > 0, a query whosemax_rows_to_readormax_rows_to_read_leafbudget is smaller than the table is rejected even when it reads no rows:Root cause. Sizing the replica set took its estimate from
selectRangesToRead(), which analyzes withcheck_row_limits = true, so whole granules are charged and it throws at plan build. Nothing exempts it that early:has_projectionsmisses the implicit_minmax_count_projection, projection selection runs later, andgetRowLimits's read-in-order exemption needs aninput_order_infothat does not exist yet.Change. Route that estimate through the non-enforcing, non-memoizing analysis whenever a throwing read row limit is set, as #110283 (
5b6b32b788904) did for the join estimator;RelationStatisticsEstimatornow shares the predicate.113ce6b061bdethen left this call site on the enforcing path during a conflict resolution. The executed read still enforces: it analyzes again, and neither estimation entry point memoizes. The price is one extra index analysis when both settings are set. Negative controls fail if enforcement is merely disarmed.This fixes
03560_parallel_replicas_projectionand the call site behind02155_read_in_order_max_rows_to_read, whose CI failure charges 100 rows at plan build forORDER BY a LIMIT 5withmax_rows_to_read = 12; the new test pins that shape in its read-order case.01585_use_index_for_global_inis a different mechanism (runtime double-charge of a duplicatedINsubquery), handled separately.Workflow [PR]
Sync PR [sync-upstream/pr/121269]
Version info
26.10.1.1856-master(included in26.10and later)