Repository navigation
Do not read in order across exchanges kept by distributed_plan_optimize_exchanges = 0 - #127220
shankar-iyer wants to merge 3 commits into
Conversation
…ze_exchanges = 0 With `distributed_plan_read_in_order = 1`, `findReadingStep` descends a keyless scatter/gather pair with equal bucket counts and lets the read read in order, assuming `optimizeExchanges` collapses the pair. With `distributed_plan_optimize_exchanges = 0` the pair stays in the plan and delivers rows in arrival order, while the sorting skips sorting, so `ORDER BY ... LIMIT` returned wrong rows. Descend such pairs only when exchanges are optimized. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [0e5ecda] Summary: ✅
AI ReviewSummaryPrevents read-order optimizations from crossing exchanges that survive when Final Verdict✅ Approve |
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, 19 s compile time in total, 7 of them have a recent master baseline. |
`test_read_in_order_with_exchanges_not_optimized` compared results only, and those depend on the arrival order of the rows, so it also passed on builds without the fix. Check the plan instead: with `optimize_read_in_order = 1` pinned, the read must not be `InOrder` and the sorting must not have a `Prefix sort description`. Without the fix both are present above the surviving `ScatterExchange`. Verified with the CI binaries: fails with master `f1c2aa5dd79`, passes with the PR build of `0485391fcef`. Addresses the AI review comment on ClickHouse#127220 Bugfix validation: https://s3.amazonaws.com/clickhouse-test-reports/PRs/127220/0485391fcef347e83b5043dec30211df2f2571f8/pr/bugfix_validation_integration_tests_amd64/job.log Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ut_optimize_exchanges
With
distributed_plan_read_in_order = 1, the read-in-order optimization descends a keyless scatter/gather pair whose bucket counts match and lets the read read in order, assumingoptimizeExchangeswill collapse the pair. Withdistributed_plan_optimize_exchanges = 0that never happens: the pair stays between the read and the sorting and delivers rows in arrival order, while the sorting trusts the input order and skips sorting.ORDER BY id LIMIT 20 OFFSET 24990over a table with several parts returned rows from the wrong part of the table in every run locally.The fix descends such pairs only when exchanges are optimized. The new integration test
test_read_in_order_with_exchanges_not_optimizedcovers it.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix wrong results of
ORDER BY ... LIMITin a distributed query plan withdistributed_plan_read_in_order = 1anddistributed_plan_optimize_exchanges = 0: the read was read in order across an exchange that reorders rows.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127220]