Repository navigation
Conversation
…ount estimate With automatic parallel replicas enabled, a query that sets force_primary_key = 1 together with a throwing max_rows_to_read and a non-zero parallel_replicas_min_number_of_rows_per_replica received TOO_MANY_ROWS instead of INDEX_NOT_USED, so the force-index guard was silently not enforced. The automatic-parallel-replicas optimization builds a throwaway probe plan purely to cost whether replicas pay off, and deliberately clears force_primary_key on it. That probe's planner-time index analysis, however, still ran with the user's throwing row limits enforced, and it runs before the real plan's analysis. So the probe's max_rows_to_read violation escaped to the client and preempted the INDEX_NOT_USED the real plan would have raised. The exception stack places the throw under considerEnablingParallelReplicas building that probe, not under the executed read. Select the estimation-only analysis when the query carries a throwing read-row limit, the same shape estimateReadRowsCount already uses for the same reason: later planning may make the executed read exempt from those limits, and the executed read analyzes again once its final mode is known. Queries without such a limit keep the memoizing selectRangesToRead path, so none pays a second index analysis it does not pay today. estimateRangesToReadWithoutQueryConditionCache takes check_row_limits as a required parameter, so its only caller states per query whether the analysis it asks for is throwaway. No setting is added and no default changes, so SettingsChangesHistory.cpp needs no entry; the only behaviour change is which error an already-failing query receives. Reported by Alexey Milovidov on ClickHouse#71028 as class 2 of the latent parallel-replicas bugs that randomizing parallel_replicas_min_number_of_rows_per_replica surfaced, via 04032_fixedstring_prefix_key_condition and 03171_indexing_by_hilbert_curve. Co-Authored-By: Claude Opus 5 <[email protected]>
…ver the remaining estimate paths Review follow-up to the previous commit. The gate that decides whether the replica-count estimate may enforce throwing row limits is now read from the analyzed step's context instead of from the query being planned, matching the sibling call site in RelationStatisticsEstimator.cpp. Range analysis takes the limits it enforces from that context (MergeTreeDataSelectExecutor::filterPartsByPrimaryKeyAndSkipIndexes), so that is the object the gate has to agree with. The two objects coincide for a direct read and for a read through a view the estimate cannot descend into, but they diverge when the outer planner finds the read inside an eligible view: there the row limit comes from the view's own context and the query selecting from it carries none. On that shape this is a behaviour change, and the view arm added in the following commit pins it. The regression test now pins every setting that gates building the probe plan. parallel_replicas_local_plan is randomized by the test runner and at 0 the probe is never built, so the arms could pass without observing anything; with the pins the unfixed binary fails 50 of 50 randomized runs. Three arms are added: * a read reached through a view, where the row limit comes from the view rather than from the query selecting from it; * the arm that skips the query condition cache, which needs use_query_condition_cache_for_top_k = 0 together with ORDER BY and LIMIT. No test reached it, so the new check_row_limits parameter survived being hard-coded back to true; * automatic_parallel_replicas_mode = 0 with parallel replicas enabled, the one configuration in which this change moves limit enforcement from planning to the executed read. It pins that TOO_MANY_ROWS is still raised there, now from the executed read's own re-analysis.
…eaf row limit Review follow-up. The fix's control flow is unchanged; a dead default argument is dropped and two arms are added. The view arm's inner query carried an ORDER BY, which makes the view ineligible for the view-over-MergeTree path, because getUnderlyingMergeTreeStorageForParallelReplicas accepts only a pass-through inner query. The estimate then ran inside the nested planner that StorageView::read builds, where the planner's settings and the read step's context are the same object, so the arm could not tell the two apart. Without the ORDER BY the view is eligible: the estimate runs in the outer plan on the read found inside the view, the outer query carries no row limit of its own, and the limit the analysis enforces comes from the view's context. The arm now discriminates, and reading the gate from the query being planned rather than from the analyzed step leaves it failing with TOO_MANY_ROWS. Two arms cover max_rows_to_read_leaf, the gate's second clause. No arm set it, so deleting that clause kept the whole test green while every leaf-limited query went back to receiving TOO_MANY_ROWS instead of INDEX_NOT_USED. estimateRangesToReadWithoutQueryConditionCache no longer defaults check_row_limits. Its only caller passes the argument, and a future caller should have to decide whether the analysis it asks for is throwaway. Co-Authored-By: Claude Opus 5 <[email protected]>
The arms were written A, B, D, C, E and on, so the file reads out of order. Arm C switches enable_parallel_replicas off, so whichever arm follows it has to set that setting again to observe anything. Arm D covers the row limit still biting when parallel replicas really are used and inherits the setting from the preamble, so moving arm C in front of it also gives arm D its own, the way the arms that already follow C carry theirs. Without that line arm D would still expect TOO_MANY_ROWS and still pass, from the single node path instead of the one it is there to cover. Co-Authored-By: Claude Opus 5 <[email protected]>
Tighten the estimate-path comment to two lines; no content removed.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 rounds, 5 gate findings plus my own
Severity: ❌ blocker / ⚠ major / 💡 nit. DISAGREE verdicts carry recorded evidence Two hazards this change could plausibly have introduced were checked and are absent. The extra One disclosure about the test: arm D re-asserts Also examined and deliberately not raised. Session id: cron:clickhouse-review-slot-8:20260921-080103 |
Pre-PR validation gate (a-i)
Regression sweeps, FAIL-set diffs against the unfixed binary on the same rig, same client binary, randomization off: the
|
|
Workflow [PR], commit [0aa5368] Summary: ✅ AI ReviewSummaryPR #121301, head Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units118 translation units recompiled, 1330 s compile time in total, 118 of them have a recent master baseline. |
CI finish ledger - ea4843dEvery 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 |
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]>
With the fix on master every arm gets the same error whether or not the automatic parallel replicas probe is built, so assert the probe counter per arm. With parallel_replicas_local_plan = 0 only this check goes red. Co-Authored-By: Claude Opus 5.5 <[email protected]>
force_primary_key with the automatic parallel replicas probe
Related: #71028
Related: #121269
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
Regression test for class 2 of #71028. With
automatic_parallel_replicas_mode1 or 2 andparallel_replicas_min_number_of_rows_per_replicaset, the probe plan's replica-count estimate enforcedmax_rows_to_readandmax_rows_to_read_leafwhileforce_primary_keywas cleared, so a query that must fail withINDEX_NOT_USEDfailed withTOO_MANY_ROWSinstead (04032_fixedstring_prefix_key_condition,03171_indexing_by_hilbert_curve).The fix landed in #121269. This PR carried the same fix and is now cut down to its test, as requested in #71028 (comment): the test of #121269,
05250, pinsautomatic_parallel_replicas_mode = 0and does not reach the probe.05233coversforce_primary_keythrough modes 1 and 2, the TopK read that skips the query condition cache, a read through a view whose ownSETTINGScarry the limit, the leaf row limit and the single-node path, plus controls where the read really exceeds the limit and must still fail withTOO_MANY_ROWS. Each arm also checksAutomaticParallelReplicasProbePlansBuilt, so it cannot pass by skipping the probe: withparallel_replicas_local_plan = 0every error still matches and only that check goes red.Validation: on current master (
d6c2532ef90) it passes 50 of 50 runs under default randomization and 50 of 50 under the #71028 reproduction settings. On a base without #121269 it fails withExpected server error code: 277 but got: 158.Workflow [PR]
Sync PR [sync-upstream/pr/121301]