Repository navigation
Do not inject random ORDER BY into queries planned to an intermediate stage - #113266
Conversation
… stage With `inject_random_order_for_select_without_order_by = 1`, `InjectRandomOrderIfNoOrderByPass` wrapped every top-level query into `SELECT * FROM (...) ORDER BY rand()`, including queries that are planned only up to an intermediate stage. For a `Merge` table with a `Distributed` child, the other children are planned to `WithMergeableState`; the wrapper made such a child plan complete its aggregation, so blocks without `AggregatedChunkInfo` reached `MergingAggregatedTransform`, failing with a logical error (exception) "Chunk info was not set for chunk in MergingAggregatedTransform". Now the pass is only added when the query is processed to stage `Complete`. Found by BuzzHouse: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110188&sha=cdc23648d36878b136bf2c8d87ee9b0a29651412&name_0=PR&name_1=BuzzHouse%20%28arm_asan_ubsan%29 On: #110188 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [dd20b50] Summary: ✅
AI ReviewSummaryThis PR moves the Final Verdict✅ No blocking issues found in the current version of this PR. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
|
🕵 The sole red check, AST fuzzer (amd_debug), is unrelated to this PR: the logical error |
…rder-intermediate-stage
…rder-intermediate-stage
…without_order_by The AI review suggested that analyzer parallel replicas fragment builders could replan an already wrapped query tree to an intermediate stage. Verified that the fragment is built from the inner, unwrapped query tree (the wrapper interposes a QueryNode boundary and each subquery planner passes its own tree), so replicas return partially aggregated blocks and the initiator merges them correctly. This test pins that behavior.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
… parameter Address review: instead of threading a bool parameter through addQueryTreePasses and branching on it, disable the setting inject_random_order_for_select_without_order_by in buildContext when the query is processed up to an intermediate stage. InjectRandomOrderIfNoOrderByPass already gates itself on that setting, and buildContext is the existing place where the interpreter context is adjusted based on SelectQueryOptions, so addQueryTreePasses keeps its uniform pass list and its original signature. #113266 (comment) Co-Authored-By: Claude Opus 4.8 <[email protected]>
…rder-intermediate-stage
|
🕵 Both red checks on
Merged |
|
🕵 The sole red check on Everything else is green (160 successful checks), and the AI Review on this head is ✅. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Looks perfect.
…rder-intermediate-stage
Related: #110188
With
inject_random_order_for_select_without_order_by = 1,InjectRandomOrderIfNoOrderByPasswrapped every top-level query intoSELECT * FROM (...) ORDER BY rand(), including queries that are planned only up to an intermediate stage. For aMergetable with aDistributedchild, the other children are planned toWithMergeableState; the wrapper made such a child plan complete its aggregation, so blocks withoutAggregatedChunkInforeachedMergingAggregatedTransform, and the query failed with a logical error (exception)Chunk info was not set for chunk in MergingAggregatedTransform.Now the injection pass is only added when the query is processed to stage
Complete, so intermediate-stage plans (Merge/Distributedchildren) are left untouched, while the injection still applies to the user-facing query.Minimal reproducer (found by BuzzHouse on this report, unrelated to that PR's changes — it reproduces on master):
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a logical error (exception)
Chunk info was not set for chunk in MergingAggregatedTransformwhen the settinginject_random_order_for_select_without_order_byis enabled and an aggregation query reads from aMergetable containing aDistributedchild: the randomORDER BY rand()wrapper is no longer injected into queries planned only up to an intermediate stage.Version info
26.8.1.1453(included in26.8and later)