Fix readByLayers using wrong ReadType for reverse-key tables#101153
Fix readByLayers using wrong ReadType for reverse-key tables#101153alexey-milovidov wants to merge 7 commits intomasterfrom
readByLayers using wrong ReadType for reverse-key tables#101153Conversation
`readByLayers` hardcoded `ReadType::InOrder` when reading data for the sharded join optimization. For tables with descending primary keys (`allow_experimental_reverse_key = 1`), the correct type should be `ReadType::InReverseOrder` when `input_order_info->direction == -1`. This caused flaky failures in `03668_shard_join_in_reverse_order` when randomized settings enabled both `read_in_order_use_virtual_row` and disabled `enable_join_runtime_filters`, producing wrong output order. The fix mirrors the logic already used in `spreadMarkRangesAmongStreamsWithOrder`. Closes #100870 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Add a test. |
|
Workflow [PR], commit [70f8e23] Summary: ❌
AI ReviewSummaryThis PR fixes PR Metadata
Findings
ClickHouse Rules
Final Verdict
|
| sort_description.emplace_back(sorting_columns[i], input_order_info->direction); | ||
| } | ||
|
|
||
| const auto read_type = input_order_info->direction == 1 ? ReadType::InOrder : ReadType::InReverseOrder; |
There was a problem hiding this comment.
Please add the required Changelog entry in the PR description for the selected Bug Fix category (the template requires it unless category is one of the explicitly exempt ones).
Suggested text:
Fix incorrect read order in readByLayers for reverse-key MergeTree tables, which could produce unstable result ordering in shard-join queries when reading in reverse order.
Adds a deterministic test that exercises the `readByLayers` code path (via `query_plan_join_shard_by_pk_ranges`) on a table with a descending primary key (`allow_experimental_reverse_key = 1`). This verifies that the correct `ReadType` is used based on `input_order_info->direction`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…verse-key-read-type
The number 04068 was taken by another test on master. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…verse-key-read-type
…verse-key-read-type
LLVM Coverage Report
Changed lines: 92.86% (13/14) · Uncovered code |
readByLayershardcodedReadType::InOrderwhen reading data for the sharded join optimization. For tables with descending primary keys (allow_experimental_reverse_key = 1), the correct type should beReadType::InReverseOrderwheninput_order_info->direction == -1.This caused flaky failures in
03668_shard_join_in_reverse_orderwhen randomized settings enabled bothread_in_order_use_virtual_rowand disabledenable_join_runtime_filters, producing wrong output order.The fix mirrors the logic already used in
spreadMarkRangesAmongStreamsWithOrder.Closes #100870
Changelog category (leave one):