Repository navigation
Ship a LIMIT without ORDER BY to replicas in plan-based parallel replicas - #129811
Conversation
…replicas The split marker of plan-based parallel replicas was lifted through expressions, filters, aggregation and sorting, but not through a `LimitStep`, so a `LIMIT` without `ORDER BY` stayed on the initiator. Every replica then read its whole share of the table and was cancelled by the initiator once it had enough rows. A cancelled replica never reports its progress, which made `02841_parallel_replicas_summary` fail in the plan-based job. Add a copy of the `LIMIT` with `limit + offset` rows to the fragment, as classic parallel replicas does by sending the `LIMIT` in the query, and keep the original step on the initiator. It is not shipped with `WITH TIES`, when a `LIMIT` must read till the end (`exact_rows_before_limit`), or when `limit + offset` overflows. The limits that optimizations attach to the read itself are not enough: `ReadFromMergeTree` does not use `SourceStepWithFilterBase::limit`, and `trivial_limit` only tunes the read (row estimate, read pool), so only a `LimitStep` in the replica's pipeline stops its read early. Related: #128413 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [d93dbe4] Summary: ✅
AI ReviewSummaryReviewed Missing context / blind spots
Final Verdict✅ Approve — no unresolved review findings. No new inline comments are needed. |
… slowed local replica Instead of switching off `parallel_replicas_local_plan`, slow the local replica down with the `slowdown_parallel_replicas_local_plan_read` failpoint, so the remote replicas always take part in the query. Pin `parallel_replicas_plan_based = 0` for now: plan-based parallel replicas does not ship a `LIMIT` without `ORDER BY` to the replicas yet, so a remote replica reads until the initiator cancels it, and a cancelled replica never reports its progress. The `interactive_delay = 99999999999` query then reports `read_rows = 0` (3 of 40 local runs failed that way with the plan-based profile). Remove the pin once #129811 is merged; with it the test passed 30 of 30. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128413&sha=4190a1cf64c1c5b703453654c52118dcab70ffe0&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20plan-based%2C%20s3%20storage%2C%20parallel%29 Related: #129811 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 17 s compile time in total, 7 of them have a recent master baseline. |
groeneai
left a comment
There was a problem hiding this comment.
The flaky check is red in amd_msan and amd_tsan on 550a394, and the cost is one arm: SELECT 1 AS x FROM t_pr_ship_limit LIMIT 5 FORMAT JSON SETTINGS exact_rows_before_limit = 1. The LIMIT is not shipped there, so each replica streams its whole share back to the initiator, and that is slow when the random MergeTree settings make the part Wide (min_bytes_for_wide_part = 0). From the jobs' query_log.tsv: under tsan that statement took 235 s median in all 17 runs with a Wide part, and at most 4.4 s in the other 33; under msan 352 s median in all 11 such runs, at most 2.2 s in the other 22. Locally (debug, nothing else running) it is 2.5 s with a Wide part and 32 ms with a Compact one.
I think the fix belongs in the code rather than the test: ship the copy in that case too, with always_read_till_end, and mark it as a shard limit, like the local-shard preliminary LIMIT (Planner.cpp#L1777-L1778). The replica still reads everything but returns only limit + offset rows, and rows_before_limit_at_least stays exact. Suggestion inline. I checked it on a debug build of 550a394 with the 3-replica localhost cluster:
rows_before_limit_at_leastis exact withparallel_replicas_local_plan0 and 1, Wide and Compact parts: 1000000 for the test's query, 333334 forWHERE n % 3 = 0 LIMIT 10 OFFSET 20, 100 forSELECT * FROM (... LIMIT 100) LIMIT 5. Each replica returns 5 rows instead of its share.- The shard mark is needed: without it, with the local plan the count is 606789 (131102 for the filtered query), because the initiator's counter does not pass a non-shard
LIMIT(QueryPipeline.cpp#L253). 05546then differs only in the expectedexact_rows_before_limit 1line (and the section title above it).02841,03174,04504,04509,04510,04836,05212,05256pass.05546at 18 workers with random settings: max 1.69 s over 48 runs, against 5.45 s over 36 runs on 550a394.
If you prefer to keep the exclusion, that arm needs a smaller table (or a pinned part type) to stay under 180 s in the flaky check.
The flaky check ran it past its time limit under the sanitizers. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129811&sha=550a39465dbc&name_0=PR Co-Authored-By: Claude Opus 5.5 <[email protected]>
… end as a shard limit Each replica then returns only `limit + offset` rows instead of its whole share, and `rows_before_limit_at_least` stays exact. The flaky check ran `05546` past its time limit on that query. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129811&sha=550a39465dbfbc33c1fa8401cd36e7f98036ec4a&name_0=PR Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the plan fragment An outer `WITH TOTALS` or exact `LIMIT` made the `Limit` under an inner `LIMIT` read till the end, so the local replica drained its whole share. Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai
left a comment
There was a problem hiding this comment.
Re-checked 0c84e22 on a local debug build; the change is right. limitAlwaysReadsTillEnd and addPreliminaryLimitStep take the flag from exact_rows_before_limit at each query level, so the matched step still carries it when it is needed:
rows_before_limit_at_leastwithexact_rows_before_limit = 1equals the non-parallel value atparallel_replicas_local_plan0 and 1, Wide and Compact parts (1000000 plain, 333334 with a filter andOFFSET, 100 over an innerLIMIT 100).- The new arm's query reads 128 rows; with
|| mustReadTillEnd()restored a replica read all 100000. An innerLIMITwithSETTINGS exact_rows_before_limit = 0under an outerexact_rows_before_limit = 1also stops at 128. - 02841 and 05546 pass 10/10 each with plan-based parallel replicas forced at local plan 0 and 1; 05546 passes 50/50 with 18 workers and random settings (max 0.60 s).
One suggestion for the new arm, inline: as written it does not reliably catch the old behaviour.
A cancelled replica does not report its progress, so the read rows did not catch the old behaviour reliably. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove the `parallel_replicas_plan_based=0` pins: the `LIMIT` is shipped to the replicas since #129811. Wait for the replicas' `query_log` entries, not only the initiator's. Regenerate the workflows after the merge. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the subquery query result cache tests: the cache is not used with plan-based parallel replicas since #130376. Add `03707_autopr_unsupported_cases` (the `LIMIT` is shipped since #129811) and `03401_..._no_sorting` (#128537). Remove the tests that pass now: the temporary table ones (#129223), the `LIMIT` ones (#129811), and those fixed on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…for the replicas' `query_log` entries The failpoint slowed the local replica by 20 ms per request, which is not enough under load: the local replica read the whole `LIMIT` alone, and no remote replica ran. With `parallel_replicas_local_plan = 0` every read is a remote query. Plan-based parallel replicas passes it since #129811 ships the `LIMIT`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #128413
Plan-based parallel replicas (
parallel_replicas_plan_based) did not ship aLIMITwithoutORDER BYto the replicas. The split marker is lifted through expressions, filters, aggregation and sorting (anORDER BY ... LIMITalready ships a local top-N), but not through aLimitStep, so theLIMITstayed on the initiator. Every replica then read its whole share of the table until the initiator cancelled it.A cancelled replica never reports its progress. With a large
interactive_delaythis is what makes02841_parallel_replicas_summaryfail in the plan-based job added in #128413: the CIquery_logof the failing run shows the replica cancelled after reading 100000 rows, and the initial query withread_rows = 0.This adds a copy of the
LIMIT, withlimit + offsetrows, to the fragment (Limit (local LIMIT)), and keeps the original step on the initiator, which applies the offset and the final limit. Classic parallel replicas gets the same effect by sending theLIMITin the query. The copy is not shipped withWITH TIES, when aLIMITmust read till the end (exact_rows_before_limit), forLIMIT 0, or whenlimit + offsetoverflows.The limits that optimizations attach to the read itself do not stop it:
ReadFromMergeTreedoes not useSourceStepWithFilterBase::limit, andtrivial_limitonly tunes the read (row estimate, read pool). Shippingtrivial_limitalone was tried, and the replicas still read until cancelled.Changelog category (leave one):
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129811]
Version info
26.11.1.1866-master(included in26.11and later)