yiguolei commented on code in PR #60367: URL: https://github.com/apache/doris/pull/60367#discussion_r2828308653
########## be/src/pipeline/exec/hierarchical_spill_partition.h: ########## @@ -0,0 +1,104 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// +// A small shared helper for hierarchical spill partitioning (multi-level split). + +#pragma once + +#include <cstdint> +#include <string> + +namespace doris::pipeline { + +// Fixed 8-way fanout (3 bits per level). +// This keeps the hierarchy bounded and makes the path encoding compact and stable. +static constexpr uint32_t kSpillFanout = 8; +static constexpr uint32_t kSpillBitsPerLevel = 3; +static constexpr uint32_t kSpillMaxDepth = 6; + +static_assert(kSpillMaxDepth <= 7, + "Max depth must be <= 7 to fit level in high 8 bits of partition key"); + +// SpillPartitionId legend (8-way fanout, 3 bits per level): +// +// level: tree depth, root partitions are level 0. +// path : bit-packed child indices from low bits to high bits. +// +// path bit layout: +// [ ... | L2(3b) | L1(3b) | L0(3b) ] +// ^^^^^^^^ +// base partition index (level 0) +// +// example path: +// level 0 -> child 5 (101) +// level 1 -> child 2 (010) +// level 2 -> child 7 (111) +// +// path = 0b111_010_101 +// L2 L1 L0 +// +// key() packs into a single uint32: +// key = (level << 24) | path +struct SpillPartitionId { + // Depth in the split tree. Root partitions are at level 0. + uint32_t level = 0; + // Bit-packed child indices along the path (3 bits per level). + // Lowest 3 bits represent the base partition index at level 0. + uint32_t path = 0; + + // Pack (level,path) into a compact key for unordered_map lookup. + // Assumes max depth is small; level is stored in high 8 bits. + uint32_t key() const { return (level << 24) | path; } + + SpillPartitionId child(uint32_t child_index) const { + return {.level = level + 1, + .path = path | (child_index << ((level + 1) * kSpillBitsPerLevel))}; Review Comment: 这种代码,再68 行 已经改了level的值了,此时69 行到底是+1 了,还是+2 了,就不太清楚了 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
