Skip to content

Fix flaky test 03583_rewrite_in_to_join (row ordering) - #108561

Merged
m-selmi merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-03583-rewrite-in-to-join-order-by
Jun 29, 2026
Merged

m-selmi merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-03583-rewrite-in-to-join-order-by

Conversation

@groeneai

@groeneai groeneai commented Jun 26, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Flaky test fix. The data SELECTs in 03583_rewrite_in_to_join read FROM numbers() with no ORDER BY. With rewrite_in_to_join, the IN/NOT IN subquery is rewritten to a LEFT JOIN whose output is produced by parallel JoiningTransform lanes (EXPLAIN PIPELINE shows Resize 32 -> 16 over 16 lanes), so the row order depends on which lane finishes first. The result multiset is always correct; only the order varies, which trips the .reference comparison. Fails on Fast test too (no settings randomization), so it is ordering, not a setting interaction.

Added ORDER BY number to the affected SELECTs. The EXPLAIN rewrite assertions and the serverError checks are unchanged, and no result value changes (only ordering becomes deterministic).

Repro (parallel JOIN lanes scramble order): clickhouse local --max_threads 16 --max_block_size 1 --join_algorithm parallel_hash over the test produced 11 distinct orderings in 20 runs without ORDER BY, and a single stable output in 30/30 runs with it.

Failed across 6 unrelated PRs in 30 days, 0 on master.

Version info

  • Merged into: 26.7.1.243 (included in 26.7 and later)

The data SELECTs read FROM numbers() without an ORDER BY. With
rewrite_in_to_join the IN/NOT IN subquery becomes a LEFT JOIN whose
output is produced by parallel JoiningTransform lanes (EXPLAIN PIPELINE
shows Resize 32->16 over 16 lanes), so row order depends on which lane
finishes first. The result multiset is always correct, only the order
varies, which trips the reference comparison.

Add ORDER BY number to the affected SELECTs. The EXPLAIN rewrite
assertions and the serverError checks are unchanged, and no result
value changes (only ordering becomes deterministic).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local --max_threads 16 --max_block_size 1 --join_algorithm parallel_hash over the test scrambles row order on every run (e.g. SELECT number IN (SELECT * FROM numbers(2)) FROM numbers(8) gave 11 distinct orderings in 20 runs).
b Root cause explained? Yes. With rewrite_in_to_join, each IN/NOT IN becomes a LEFT JOIN. EXPLAIN PIPELINE shows the result flowing through 16 parallel JoiningTransform lanes into Resize 32 -> 16, so output row order depends on which lane finishes first. The data SELECTs have no ORDER BY, so the row order is undefined and the .reference comparison fails intermittently.
c Fix matches root cause? Yes. ORDER BY number is added to exactly the multi-row data SELECTs, making output order deterministic. This is the standard fix for parallel-execution row-ordering nondeterminism, not a band-aid (no bounds widened, no no-random-* tag, no data reduction).
d Test intent preserved / new tests added? Yes. The EXPLAIN keep_logical_steps rewrite assertions (JoinLogical) and the serverError checks are untouched, so the test still verifies the IN->JOIN rewrite and its error paths. No result value changes; only ordering becomes deterministic.
e Both directions demonstrated? Yes. Without ORDER BY: 11 distinct orderings / 20 runs (current flaky behavior). With ORDER BY: 30/30 runs match the reference under the same parallel settings. The regenerated .reference differs from the old one ONLY in the echoed SQL lines, with every result value identical.
f Fix is general across code paths? N/A (flaky test fix, not a code bug). Every multi-row data SELECT reading FROM numbers() in this test received ORDER BY number; single-row (system.one) and serverError queries correctly left as-is.
g Fix generalizes across inputs? N/A (flaky test fix, not a code bug).
h Backward compatible? N/A (flaky test fix, not a code bug).
i Invariants and contracts preserved? N/A (flaky test fix, not a code bug).

Session id: cron:clickhouse-worker-slot-0:20260626-003700

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @dhtclk — could you review this? The data SELECTs in 03583_rewrite_in_to_join had no ORDER BY, and with rewrite_in_to_join the IN/NOT IN subquery becomes a LEFT JOIN whose output is produced by parallel JoiningTransform lanes, so row order was nondeterministic (failed on Fast test + 5 other unrelated PRs, 0 on master). This adds ORDER BY number to the affected SELECTs; the EXPLAIN rewrite assertions and serverError checks are unchanged and no result value changes.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [985c436]

Summary: ✅


AI Review

Summary

This PR is a scoped test-only fix for 03583_rewrite_in_to_join: it adds ORDER BY number to result-producing numbers queries whose IN / NOT IN subqueries can be rewritten into parallel joins, making the reference output deterministic. I found no unresolved correctness issues and no new inline findings.

Missing context / blind spots
  • ⚠️ I could not run the stateless test locally because this checkout has no build* directory or clickhouse binary. The direct CI report currently shows no failed tests for commit 985c4369, but the available report was still partial when checked.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 26, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 985c436

Every failure below has an owner; none is in this PR's diff (03583_rewrite_in_to_join.sql/.reference), so none is PR-caused.

Check / test Reason Owner / fixing PR
Stateless (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) / 02770_async_buffer_ignore flaky, 13 PRs / 2 master in 30d #107298 (ours, fixes flaky 02770)
Stress test (arm_debug) / Hung check failed, possible deadlock chronic hung-check deadlock family #101680 / #105905 (ours)
Stress test (arm_tsan) / Hung check failed, possible deadlock chronic hung-check deadlock family #101680 / #105905 (ours)
Mergeable Check / PR aggregators reflecting the reds above n/a

Session id: cron:our-pr-ci-monitor:20260626-173000

@m-selmi m-selmi self-assigned this Jun 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 360 line(s), 23 function(s) across 123 file(s) · Details

Top files
  • src/Backups/BackupEntriesCollector.cpp: 28 line(s), 2 function(s)
  • src/Common/ZooKeeper/ZooKeeperImpl.cpp: 15 line(s)
  • src/Storages/StorageReplicatedMergeTree.cpp: 15 line(s)
  • src/Dictionaries/IPAddressDictionary.h: 9 line(s), 7 function(s)
  • src/AggregateFunctions/AggregateFunctionQuantileExact.cpp: 8 line(s)

Full report

@m-selmi
m-selmi added this pull request to the merge queue Jun 29, 2026
Merged via the queue into ClickHouse:master with commit 4603264 Jun 29, 2026
327 of 330 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 29, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…in-to-join-order-by

Fix flaky test 03583_rewrite_in_to_join (row ordering)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants