Repository navigation
Fix flaky tests 02317_distinct_in_order_optimization and 02733_fix_distinct_in_order_bug_49622 under parallel replicas - #127002
Conversation
…plicas Since ClickHouse#114550 the final DISTINCT hash-partitions its input (DistinctStep::tryScatterStreams) when it has more than one input stream and max_threads > 1. Under parallel replicas the initiator's final DISTINCT always has several input streams (local plan plus remote replicas, or only remote replicas with parallel_replicas_local_plan = 0), so the single chunk of `sorting_key_empty_tuple` is split into partitions whose outputs reach the client in scheduling order: `0, 1` instead of `1, 0` in 4 of 198 ParallelReplicas runs since the merge, 0 of 2846 in the week before. The returned set is unchanged and a DISTINCT without ORDER BY has no defined row order (allow_parallel_distinct documents it), so pin the order with ORDER BY, as ClickHouse#114550 did for 02733_distinct and 01213_optimize_skip_unused_shards_DISTINCT. The bug 42185 path stays covered: the preliminary DISTINCT is still planned directly above the in-order read with an empty sort description; ORDER BY only adds a sort above it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings on the test change) plus my own cold review (2 nits, both in the PR description, fixed before publication).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261020-173400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261020-165800 |
|
Workflow [PR], commit [b44146b] Summary: ✅ AI ReviewSummaryThis PR adds explicit Final Verdict✅ Approve |
|
cc @devcrafter, could you review this and add the |
…eplicas Same mechanism as 02317_distinct_in_order_optimization. Since ClickHouse#114550 the final DISTINCT hash-partitions its input (DistinctStep::tryScatterStreams) when it has more than one input stream and max_threads > 1. Under parallel replicas the initiator's final DISTINCT has several input streams (local plan plus remote replicas), so the two rows of `test_string` can land in different partitions and reach the client in either order. CI's own rerun with the failing run's settings reproduced it 19 of 446 times on PR ClickHouse#127095; the test had 0 failures in 33352 runs before the merge. The returned set is unchanged and a DISTINCT without ORDER BY has no defined row order, so pin it with ORDER BY c1. The reference is unchanged. With ORDER BY the final DISTINCT runs after the sort and keeps the input order, which forbids the scatter. The 49622 path stays covered (in-order DISTINCT with an empty-string non-sorted column, preliminary and final): the preliminary DISTINCT is still planned directly above the in-order read with the `c1` prefix, and the final DISTINCT now also runs in order over `c1`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
02317_distinct_in_order_optimization under parallel replicas02317_distinct_in_order_optimization and 02733_fix_distinct_in_order_bug_49622 under parallel replicas
Internal second-model review: adjudication log (02733 commit) (click to expand)Pre-publication review of the added
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261021-070100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261021-063300 |
Related: #114550
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Since #114550 was merged, two tests fail in the
ParallelReplicasstateless jobs with the right rows in another order:02317_distinct_in_order_optimization:select distinct a from sorting_key_empty_tupleprints0, 1instead of1, 0. 16 failures in 433ParallelReplicasruns after the merge, 0 in 4152 in the 10 days before (job).02733_fix_distinct_in_order_bug_49622:SELECT DISTINCT c2, c1 FROM test_stringprints('', '2')before('', '1'). CI's rerun reproduced it 19 of 446 times; 0 failures in 4149ParallelReplicasruns in the 10 days before the merge (job).The final
DISTINCTnow hash-partitions its input when it has more than one input stream. Under parallel replicas the initiator has several, so the rows of one chunk land in different partitions that are output in scheduling order. The set is unchanged; asallow_parallel_distinctdocuments, aDISTINCTwithoutORDER BYhas no defined row order.The change adds
ORDER BYto both queries, as #114550 did for02733_distinctand01213_optimize_skip_unused_shards_DISTINCT. Both tests keep their bug coverage: 42185, the preliminaryDISTINCTabove the in-order read with an empty sort description, and 49622, the in-orderDISTINCTwith an empty-string non-sorted column.On a parallel-replicas server,
EXPLAIN PIPELINEshowsScatterByPartitionTransformfor both old queries, and none withallow_parallel_distinct = 0or for the new queries. Withparallel_replicas_local_plan = 0the old queries returned the other order in 332 (02317) and 3113 (02733) of 12000 runs, never in theallow_parallel_distinct = 0controls; the new ones never did. Both tests passed 50 of 50 randomized runs with and without the parallel-replicas profile.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127002]
Version info
26.11.1.460-master(included in26.11and later)