Repository navigation
Support FINAL reads in distributed query plans (make_distributed_plan) - #108148
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…lan` Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…red step Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…s partitions Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…fied distributed read Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…arallelism Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [79d1ee1] Summary: ✅
AI ReviewSummaryThis PR adds distributed Missing context / blind spots
Findings
Final Verdict
|
…-only) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…der query-plan serialization version Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… to the step deserializer Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ibutedFinalPipe` helper Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…onIntersectingFinalWithEngineFilter` Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… skip distributed FINAL for Graphite Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…not reproduce Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
📊 Cloud Performance Report 🔴 AI verdict: This PR reworks distributed read bucketing and adds parallel FINAL, changing how MergeTree reads are split into per-bucket mark slices. On TPC-H the three join/read-heavy queries regress: Q7 (71ms to 629ms) and Q4 (329ms to 960ms) are large and consistent — the base runs were noisy but the new version is steadily much slower — and Q8 shifts +23.5%. On ClickBench the same bucketing change lines up with modest, consistent improvements (Q4 -17%, Q15 -13%, Q28 -5.5%). Net: the new bucketing helps simple scan/aggregate reads but clearly hurts the TPC-H join inputs, which is worth investigating before merge. clickbench🟢 3 improved Flagged queries (3 of 43)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🔴 3 regressed Flagged queries (3 of 22)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
…d guard bucketed reads Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rker path Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…MPLE` predicate Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rced bucketing Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
…swap Co-Authored-By: Claude Fable 5 <[email protected]>
| /// marks travel in the `read_bucket` task parameter. The deserializer rejects a version-1 bucketed step (its | ||
| /// trailing part-name payload would desync the plan), so all `make_distributed_plan` nodes need one version. | ||
| static constexpr auto DBMS_QUERY_PLAN_SERIALIZATION_VERSION = 2; | ||
| /// Version 1 added the initiator's settings changes to the task. |
There was a problem hiding this comment.
This version bump widens the compatibility break from the new bucketed FINAL layout to every make_distributed_plan query. DistributedPlanExecutor::serializeQueryPlan always emits DBMS_QUERY_PLAN_SERIALIZATION_VERSION (src/QueryPipeline/DistributedPlanExecutor.cpp:604), and an older worker rejects any higher plan version before it even reaches ReadFromMergeTree (src/Processors/QueryPlan/Serialization.cpp:169-172). That means a rolling upgrade now breaks even plain distributed-plan reads/joins/aggregations that never use bucketed FINAL: a new initiator will send version 2, and a v1 worker will fail the fragment immediately instead of running the old-compatible plan.
Please keep serializing legacy-compatible fragments as version 1 (or negotiate the query-plan version per worker/task) and reserve version 2 for fragments that actually contain a bucketed ReadFromMergeTree. Otherwise this PR effectively requires a lockstep cluster upgrade for the whole experimental distributed-plan feature, not just the new FINAL path.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 457/513 (89.08%) · Uncovered code |
| { | ||
| const size_t global_mark = global_offset + covered; | ||
| while (current_bucket + 1 < bucket_count && global_mark >= bucket_end_global(current_bucket)) | ||
| ++current_bucket; |
There was a problem hiding this comment.
Perfect! Favours allocating contiguous whole parts to workers.
| const size_t non_intersecting_buckets = std::max<size_t>(1, span_budget * non_intersecting_marks / span_marks); | ||
| for (auto & slice : sliceMarksAcrossBuckets(ranges.non_intersecting_parts_ranges, non_intersecting_buckets)) | ||
| if (!slice.empty()) | ||
| buckets.push_back({std::move(slice), /*needs_merge=*/ false, {}, 0}); |
There was a problem hiding this comment.
Non-intersecting ranges go first into the buckets and then the intersecting will be accumulated in the rear. So some replicas may only do non-merges and the some replica(s) in the replica list will get all the merge work. Should be fine, we can revisit if needed.
Resolve conflicts from master's distributed-FINAL refactor (#108148), which relocated the standalone expression-compilation call sites this PR migrates: - `PartsSplitter.cpp`: master extracted the per-layer range-filter building out of `readByLayers` into a new `applyRangeFilterFromAST` helper. Kept master's structure (dropped the now-moved inline block) and applied this PR's migration to the helper (`TreeRewriter`+`ExpressionAnalyzer` -> `analyzeExpressionToActionsDAG`). - `ReadFromMergeTree.cpp`: master moved `addMergingFinal`, `createExpressionForPositiveSign` and `createExpressionForIsDeleted` into the new `MergeTreeFinalMerge.cpp`. Took master's side (removed the local definitions; `addMergingFinal` is now declared in `MergeTreeFinalMerge.h`). The remaining in-file site (`spreadMarkRangesAmongStreamsWithOrder`) keeps this PR's migration. - `MergeTreeFinalMerge.cpp` (new on master): applied this PR's migration to the relocated `createExpressionForPositiveSign` / `createExpressionForIsDeleted` (`analyzeExpressionToActions`) and swapped the includes. This transformation is byte-identical to the one this PR already applied to these functions in their pre-refactor location in `ReadFromMergeTree.cpp`. `analyzeExpressionToActions`/`analyzeExpressionToActionsDAG` default `add_aliases = false`, matching the old `getActionsDAG(false)` behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…-pk-range-final Support FINAL reads in distributed query plans (make_distributed_plan)
Motivation
make_distributed_plancould distribute ordinary MergeTree reads across the cluster, but notSELECT ... FINAL.FINALdeduplicates rows that share a primary key during a merge, so its input can't be split arbitrarily — as a resultFINALqueries stayed single-node.Approach
Split a
FINALread into primary-key-range buckets so that every row sharing a key lands in exactly one bucket. Each bucket is read andFINAL-merged independently — in parallel across nodes — and the results are concatenated. Ranges that don't overlap across parts skip the merge entirely (only the engine's sign / is-deleted filter is applied), and whenFINALdoes not merge across partitions each partition is split on its own.Main changes
MergeTreeFinalMergemodule that shares theFINALlogic between the single-node and distributed paths:addMergingFinal,buildDistributedFinalPipe, andreadNonIntersectingFinalWithEngineFilter.ReadFromMergeTreegains serializable per-bucket primary-key-range layer state (DistributedReadBucket); the coordinator ships each bucket's authoritative marks (plusFINALborders and index) as a per-task parameter, with multiple merge lanes per task for parallelism.GraphiteFINAL) fall back to a serial read instead of failing.Covered by new stateless tests
04356–04360(PK-range layers, per-partitionFINAL, more engines, read modifiers, non-intersecting ranges) and multi-node integration coverage.Changelog category (leave one):
Changelog entry:
Support distributed query-plan reads for
SELECT ... FINALon MergeTree-family tables whenmake_distributed_planis enabled.Version info
26.7.1.645(included in26.7and later)