Skip to content

Fix flaky test 03668_shard_join_in_reverse_order - #101654

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
vitlibar:fix-flaky-test-03668_shard_join_in_reverse_order
Apr 5, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
vitlibar:fix-flaky-test-03668_shard_join_in_reverse_order

Conversation

@vitlibar

@vitlibar vitlibar commented Apr 2, 2026 •

Copy link
Copy Markdown
Member

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):

Fix flaky test 03668_shard_join_in_reverse_order

Closes #100870

Version info

  • Merged into: 26.4.1.567

@clickhouse-gh

clickhouse-gh Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2a43ece]

Summary: ❌

job_name test_name status info comment
Stress test (arm_msan) failure
Server died FAIL cidb
MemorySanitizer: use-of-uninitialized-value (STID: 4179-5154) FAIL cidb, issue

AI Review

Summary

This PR fixes flaky test 03668_shard_join_in_reverse_order by propagating reverse read direction in ReadFromMergeTree::readByLayers (using ReadType::InReverseOrder when needed) and by extending the stateless test to validate both baseline and explicit read-in-order-through-join settings. I did not find correctness, safety, concurrency, or performance issues in the patch.

Missing context
  • ⚠️ No CI logs/results were provided in this review context, so validation here is based on code and test diff inspection.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@vitlibar
vitlibar requested a review from KochetovNicolai April 2, 2026 19:54
@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 2, 2026

INSERT INTO TABLE t0 (c0) SELECT number FROM numbers(10);

SELECT c0 FROM t0 JOIN t0 tx USING (c0) ORDER BY c0 SETTINGS query_plan_join_shard_by_pk_ranges = 1, max_threads = 2, query_plan_read_in_order_through_join = 1;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here query_plan_read_in_order_through_join was pinned to 1 in #91749 after enabling randomization for this setting. With this fix we don't need that pinning anymore.


DROP TABLE IF EXISTS t0;

CREATE TABLE t0 (c0 Int) ENGINE = MergeTree() ORDER BY (c0 DESC) SETTINGS index_granularity = 1, allow_experimental_reverse_key = 1;

@vitlibar vitlibar Apr 2, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here CREATE TABLE ... ORDER BY (c0 DESC) produces table sorted in descending order, however SELECT ORDER BY c0 requires data in ascending order. So

current_direction = sort_column_description.direction * reverse_indicator;
sets current_direction to 1 * (-1) = -1 and thus in ReadFromMergeTree::readByLayers() we should read data in descending order to match the SELECT query.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes flakiness in stateless test 03668_shard_join_in_reverse_order by ensuring the read-in-order path respects reverse read direction and by making the test exercise both the generic and forced “read-in-order through JOIN sharding” execution paths deterministically.

Changes:

  • Update ReadFromMergeTree::readByLayers() to use ReadType::InReverseOrder when input_order_info->direction indicates reverse reading.
  • Adjust the stateless test to run the JOIN query twice (baseline + forced settings) with a clear separator in output.
  • Update the expected .reference output to match the new test structure.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/queries/0_stateless/03668_shard_join_in_reverse_order.sql Adds a baseline query and a second query with pinned settings to reliably trigger the read-in-order-through-join path.
tests/queries/0_stateless/03668_shard_join_in_reverse_order.reference Updates expected output to include results from both queries and the separator line.
src/Processors/QueryPlan/ReadFromMergeTree.cpp Fixes reverse-direction handling in the layered read-in-order path by selecting the correct ReadType.

@vitlibar vitlibar added the 🍃 green ci 🌿 Fixing flaky tests in CI label Apr 2, 2026
@antaljanosbenjamin

Copy link
Copy Markdown
Member

I think this is a duplicate of #101153

@clickhouse-gh

clickhouse-gh Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% (739,539/879,177) 84.10% (738,963/879,179) +0.00% (-576)
Functions 90.90% (798,270/878,448) 90.90% (798,356/878,525) +0.00% (+86)
Branches 76.70% (239,703/312,720) 76.60% (239,528/312,722) -0.10% (-175)

Changed lines: 92.86% (13/14) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov self-assigned this Apr 5, 2026
@alexey-milovidov
alexey-milovidov merged commit 6ba8c63 into ClickHouse:master Apr 5, 2026
162 of 163 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 5, 2026
Mip182 pushed a commit to Mip182/ClickHouse that referenced this pull request May 9, 2026
…68_shard_join_in_reverse_order

Fix flaky test 03668_shard_join_in_reverse_order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🍃 green ci 🌿 Fixing flaky tests in CI 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.

Flaky test: 03668_shard_join_in_reverse_order

5 participants