be/src/exec/partitioner/partitioner.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <algorithm> |
21 | | |
22 | | #include "core/block/block.h" |
23 | | #include "exprs/vexpr.h" |
24 | | #include "exprs/vexpr_context.h" |
25 | | |
26 | | namespace doris { |
27 | | |
28 | | class PartitionerBase { |
29 | | public: |
30 | | using HashValType = uint32_t; |
31 | | |
32 | 294k | PartitionerBase(HashValType partition_count) : _partition_count(partition_count) {} |
33 | 297k | virtual ~PartitionerBase() = default; |
34 | | |
35 | | virtual Status init(const std::vector<TExpr>& texprs) = 0; |
36 | | |
37 | | virtual Status prepare(RuntimeState* state, const RowDescriptor& row_desc) = 0; |
38 | | |
39 | | virtual Status open(RuntimeState* state) = 0; |
40 | | |
41 | | virtual Status close(RuntimeState* state) = 0; |
42 | | |
43 | | virtual Status do_partitioning(RuntimeState* state, Block* block) const = 0; |
44 | | |
45 | | virtual const std::vector<HashValType>& get_channel_ids() const = 0; |
46 | | |
47 | | virtual Status clone(RuntimeState* state, std::unique_ptr<PartitionerBase>& partitioner) = 0; |
48 | | |
49 | | // use _partition_count as invalid sentinel value. since modulo operation result is [0, partition_count-1] |
50 | 6 | HashValType partition_count() const { return _partition_count; } |
51 | | // use a individual function to highlight its special meaning |
52 | 4 | HashValType invalid_sentinel() const { return partition_count(); } |
53 | | |
54 | | protected: |
55 | | const HashValType _partition_count; |
56 | | }; |
57 | | |
58 | | enum class ShuffleHashMethod { |
59 | | CRC32, |
60 | | CRC32C, |
61 | | }; |
62 | | |
63 | | class PartitionFunction { |
64 | | public: |
65 | | using HashValType = PartitionerBase::HashValType; |
66 | | |
67 | 11 | virtual ~PartitionFunction() = default; |
68 | | |
69 | | virtual Status init(const std::vector<TExpr>& texprs) = 0; |
70 | | |
71 | | virtual Status prepare(RuntimeState* state, const RowDescriptor& row_desc) = 0; |
72 | | |
73 | | virtual Status open(RuntimeState* state) = 0; |
74 | | |
75 | | virtual Status close(RuntimeState* state) = 0; |
76 | | |
77 | | virtual Status get_partitions(RuntimeState* state, Block* block, size_t partition_count, |
78 | | std::vector<HashValType>& partitions) const = 0; |
79 | | |
80 | | virtual HashValType partition_count() const = 0; |
81 | | |
82 | | virtual Status clone(RuntimeState* state, |
83 | | std::unique_ptr<PartitionFunction>& function) const = 0; |
84 | | }; |
85 | | |
86 | | // Adapts the standard Doris expression hash partitioner to the composable |
87 | | // PartitionFunction interface used by sink routing. |
88 | | class HashPartitionFunction final : public PartitionFunction { |
89 | | public: |
90 | | HashPartitionFunction(HashValType partition_count, ShuffleHashMethod hash_method); |
91 | | |
92 | | Status init(const std::vector<TExpr>& texprs) override; |
93 | | Status prepare(RuntimeState* state, const RowDescriptor& row_desc) override; |
94 | | Status open(RuntimeState* state) override; |
95 | | Status close(RuntimeState* state) override; |
96 | | Status get_partitions(RuntimeState* state, Block* block, size_t partition_count, |
97 | | std::vector<HashValType>& partitions) const override; |
98 | 0 | HashValType partition_count() const override { return _partition_count; } |
99 | | Status clone(RuntimeState* state, std::unique_ptr<PartitionFunction>& function) const override; |
100 | | |
101 | | private: |
102 | | HashValType _partition_count; |
103 | | ShuffleHashMethod _hash_method; |
104 | | std::unique_ptr<PartitionerBase> _partitioner; |
105 | | }; |
106 | | |
107 | | template <typename ChannelIds> |
108 | | class Crc32HashPartitioner : public PartitionerBase { |
109 | | public: |
110 | 294k | Crc32HashPartitioner(int partition_count) : PartitionerBase(partition_count) {}_ZN5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEEC2Ei Line | Count | Source | 110 | 286k | Crc32HashPartitioner(int partition_count) : PartitionerBase(partition_count) {} |
_ZN5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEEC2Ei Line | Count | Source | 110 | 7.62k | Crc32HashPartitioner(int partition_count) : PartitionerBase(partition_count) {} |
_ZN5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEEC2Ei Line | Count | Source | 110 | 23 | Crc32HashPartitioner(int partition_count) : PartitionerBase(partition_count) {} |
_ZN5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEEC2Ei Line | Count | Source | 110 | 10 | Crc32HashPartitioner(int partition_count) : PartitionerBase(partition_count) {} |
|
111 | 297k | ~Crc32HashPartitioner() override = default; _ZN5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEED2Ev Line | Count | Source | 111 | 289k | ~Crc32HashPartitioner() override = default; |
_ZN5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEED2Ev Line | Count | Source | 111 | 7.68k | ~Crc32HashPartitioner() override = default; |
_ZN5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEED2Ev Line | Count | Source | 111 | 23 | ~Crc32HashPartitioner() override = default; |
_ZN5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEED2Ev Line | Count | Source | 111 | 10 | ~Crc32HashPartitioner() override = default; |
|
112 | | |
113 | 201k | Status init(const std::vector<TExpr>& texprs) override { |
114 | 201k | return VExpr::create_expr_trees(texprs, _partition_expr_ctxs); |
115 | 201k | } _ZN5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE4initERKSt6vectorINS_5TExprESaIS4_EE Line | Count | Source | 113 | 194k | Status init(const std::vector<TExpr>& texprs) override { | 114 | 194k | return VExpr::create_expr_trees(texprs, _partition_expr_ctxs); | 115 | 194k | } |
_ZN5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE4initERKSt6vectorINS_5TExprESaIS4_EE Line | Count | Source | 113 | 7.09k | Status init(const std::vector<TExpr>& texprs) override { | 114 | 7.09k | return VExpr::create_expr_trees(texprs, _partition_expr_ctxs); | 115 | 7.09k | } |
_ZN5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE4initERKSt6vectorINS_5TExprESaIS4_EE Line | Count | Source | 113 | 18 | Status init(const std::vector<TExpr>& texprs) override { | 114 | 18 | return VExpr::create_expr_trees(texprs, _partition_expr_ctxs); | 115 | 18 | } |
_ZN5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE4initERKSt6vectorINS_5TExprESaIS4_EE Line | Count | Source | 113 | 6 | Status init(const std::vector<TExpr>& texprs) override { | 114 | 6 | return VExpr::create_expr_trees(texprs, _partition_expr_ctxs); | 115 | 6 | } |
|
116 | | |
117 | 201k | Status prepare(RuntimeState* state, const RowDescriptor& row_desc) override { |
118 | 201k | return VExpr::prepare(_partition_expr_ctxs, state, row_desc); |
119 | 201k | } _ZN5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE7prepareEPNS_12RuntimeStateERKNS_13RowDescriptorE Line | Count | Source | 117 | 193k | Status prepare(RuntimeState* state, const RowDescriptor& row_desc) override { | 118 | 193k | return VExpr::prepare(_partition_expr_ctxs, state, row_desc); | 119 | 193k | } |
_ZN5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE7prepareEPNS_12RuntimeStateERKNS_13RowDescriptorE Line | Count | Source | 117 | 7.07k | Status prepare(RuntimeState* state, const RowDescriptor& row_desc) override { | 118 | 7.07k | return VExpr::prepare(_partition_expr_ctxs, state, row_desc); | 119 | 7.07k | } |
_ZN5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE7prepareEPNS_12RuntimeStateERKNS_13RowDescriptorE Line | Count | Source | 117 | 15 | Status prepare(RuntimeState* state, const RowDescriptor& row_desc) override { | 118 | 15 | return VExpr::prepare(_partition_expr_ctxs, state, row_desc); | 119 | 15 | } |
_ZN5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE7prepareEPNS_12RuntimeStateERKNS_13RowDescriptorE Line | Count | Source | 117 | 6 | Status prepare(RuntimeState* state, const RowDescriptor& row_desc) override { | 118 | 6 | return VExpr::prepare(_partition_expr_ctxs, state, row_desc); | 119 | 6 | } |
|
120 | | |
121 | 202k | Status open(RuntimeState* state) override { return VExpr::open(_partition_expr_ctxs, state); }_ZN5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE4openEPNS_12RuntimeStateE Line | Count | Source | 121 | 195k | Status open(RuntimeState* state) override { return VExpr::open(_partition_expr_ctxs, state); } |
_ZN5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE4openEPNS_12RuntimeStateE Line | Count | Source | 121 | 7.12k | Status open(RuntimeState* state) override { return VExpr::open(_partition_expr_ctxs, state); } |
_ZN5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE4openEPNS_12RuntimeStateE Line | Count | Source | 121 | 6 | Status open(RuntimeState* state) override { return VExpr::open(_partition_expr_ctxs, state); } |
_ZN5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE4openEPNS_12RuntimeStateE Line | Count | Source | 121 | 6 | Status open(RuntimeState* state) override { return VExpr::open(_partition_expr_ctxs, state); } |
|
122 | | |
123 | 184k | Status close(RuntimeState* state) override { return Status::OK(); }_ZN5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE5closeEPNS_12RuntimeStateE Line | Count | Source | 123 | 177k | Status close(RuntimeState* state) override { return Status::OK(); } |
_ZN5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE5closeEPNS_12RuntimeStateE Line | Count | Source | 123 | 7.03k | Status close(RuntimeState* state) override { return Status::OK(); } |
Unexecuted instantiation: _ZN5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE5closeEPNS_12RuntimeStateE Unexecuted instantiation: _ZN5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE5closeEPNS_12RuntimeStateE |
124 | | |
125 | | Status do_partitioning(RuntimeState* state, Block* block) const override; |
126 | | |
127 | 212k | const std::vector<HashValType>& get_channel_ids() const override { return _hash_vals; }_ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE15get_channel_idsEv Line | Count | Source | 127 | 202k | const std::vector<HashValType>& get_channel_ids() const override { return _hash_vals; } |
_ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE15get_channel_idsEv Line | Count | Source | 127 | 10.1k | const std::vector<HashValType>& get_channel_ids() const override { return _hash_vals; } |
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE15get_channel_idsEv Line | Count | Source | 127 | 8 | const std::vector<HashValType>& get_channel_ids() const override { return _hash_vals; } |
_ZNK5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE15get_channel_idsEv Line | Count | Source | 127 | 8 | const std::vector<HashValType>& get_channel_ids() const override { return _hash_vals; } |
|
128 | | |
129 | | Status clone(RuntimeState* state, std::unique_ptr<PartitionerBase>& partitioner) override; |
130 | | |
131 | | protected: |
132 | 46.1k | Status _get_partition_column_result(Block* block, std::vector<int>& result) const { |
133 | 46.1k | int counter = 0; |
134 | 61.3k | for (auto ctx : _partition_expr_ctxs) { |
135 | 61.3k | RETURN_IF_ERROR(ctx->execute(block, &result[counter++])); |
136 | 61.3k | } |
137 | 46.1k | return Status::OK(); |
138 | 46.1k | } _ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE28_get_partition_column_resultEPNS_5BlockERSt6vectorIiSaIiEE Line | Count | Source | 132 | 5.02k | Status _get_partition_column_result(Block* block, std::vector<int>& result) const { | 133 | 5.02k | int counter = 0; | 134 | 5.02k | for (auto ctx : _partition_expr_ctxs) { | 135 | 5.02k | RETURN_IF_ERROR(ctx->execute(block, &result[counter++])); | 136 | 5.02k | } | 137 | 5.02k | return Status::OK(); | 138 | 5.02k | } |
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE28_get_partition_column_resultEPNS_5BlockERSt6vectorIiSaIiEE Line | Count | Source | 132 | 8 | Status _get_partition_column_result(Block* block, std::vector<int>& result) const { | 133 | 8 | int counter = 0; | 134 | 8 | for (auto ctx : _partition_expr_ctxs) { | 135 | 8 | RETURN_IF_ERROR(ctx->execute(block, &result[counter++])); | 136 | 8 | } | 137 | 8 | return Status::OK(); | 138 | 8 | } |
_ZNK5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE28_get_partition_column_resultEPNS_5BlockERSt6vectorIiSaIiEE Line | Count | Source | 132 | 8 | Status _get_partition_column_result(Block* block, std::vector<int>& result) const { | 133 | 8 | int counter = 0; | 134 | 8 | for (auto ctx : _partition_expr_ctxs) { | 135 | 8 | RETURN_IF_ERROR(ctx->execute(block, &result[counter++])); | 136 | 8 | } | 137 | 8 | return Status::OK(); | 138 | 8 | } |
_ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE28_get_partition_column_resultEPNS_5BlockERSt6vectorIiSaIiEE Line | Count | Source | 132 | 41.0k | Status _get_partition_column_result(Block* block, std::vector<int>& result) const { | 133 | 41.0k | int counter = 0; | 134 | 56.3k | for (auto ctx : _partition_expr_ctxs) { | 135 | 56.3k | RETURN_IF_ERROR(ctx->execute(block, &result[counter++])); | 136 | 56.3k | } | 137 | 41.0k | return Status::OK(); | 138 | 41.0k | } |
|
139 | | |
140 | 94.3k | Status _clone_expr_ctxs(RuntimeState* state, VExprContextSPtrs& new_partition_expr_ctxs) const { |
141 | 94.3k | new_partition_expr_ctxs.resize(_partition_expr_ctxs.size()); |
142 | 195k | for (size_t i = 0; i < _partition_expr_ctxs.size(); i++) { |
143 | 101k | RETURN_IF_ERROR(_partition_expr_ctxs[i]->clone(state, new_partition_expr_ctxs[i])); |
144 | 101k | } |
145 | 94.3k | return Status::OK(); |
146 | 94.3k | } _ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE16_clone_expr_ctxsEPNS_12RuntimeStateERSt6vectorISt10shared_ptrINS_12VExprContextEESaIS8_EE Line | Count | Source | 140 | 535 | Status _clone_expr_ctxs(RuntimeState* state, VExprContextSPtrs& new_partition_expr_ctxs) const { | 141 | 535 | new_partition_expr_ctxs.resize(_partition_expr_ctxs.size()); | 142 | 1.07k | for (size_t i = 0; i < _partition_expr_ctxs.size(); i++) { | 143 | 544 | RETURN_IF_ERROR(_partition_expr_ctxs[i]->clone(state, new_partition_expr_ctxs[i])); | 144 | 544 | } | 145 | 535 | return Status::OK(); | 146 | 535 | } |
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE16_clone_expr_ctxsEPNS_12RuntimeStateERSt6vectorISt10shared_ptrINS_12VExprContextEESaIS8_EE Line | Count | Source | 140 | 5 | Status _clone_expr_ctxs(RuntimeState* state, VExprContextSPtrs& new_partition_expr_ctxs) const { | 141 | 5 | new_partition_expr_ctxs.resize(_partition_expr_ctxs.size()); | 142 | 10 | for (size_t i = 0; i < _partition_expr_ctxs.size(); i++) { | 143 | 5 | RETURN_IF_ERROR(_partition_expr_ctxs[i]->clone(state, new_partition_expr_ctxs[i])); | 144 | 5 | } | 145 | 5 | return Status::OK(); | 146 | 5 | } |
_ZNK5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE16_clone_expr_ctxsEPNS_12RuntimeStateERSt6vectorISt10shared_ptrINS_12VExprContextEESaIS8_EE Line | Count | Source | 140 | 4 | Status _clone_expr_ctxs(RuntimeState* state, VExprContextSPtrs& new_partition_expr_ctxs) const { | 141 | 4 | new_partition_expr_ctxs.resize(_partition_expr_ctxs.size()); | 142 | 8 | for (size_t i = 0; i < _partition_expr_ctxs.size(); i++) { | 143 | 4 | RETURN_IF_ERROR(_partition_expr_ctxs[i]->clone(state, new_partition_expr_ctxs[i])); | 144 | 4 | } | 145 | 4 | return Status::OK(); | 146 | 4 | } |
_ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE16_clone_expr_ctxsEPNS_12RuntimeStateERSt6vectorISt10shared_ptrINS_12VExprContextEESaIS8_EE Line | Count | Source | 140 | 93.8k | Status _clone_expr_ctxs(RuntimeState* state, VExprContextSPtrs& new_partition_expr_ctxs) const { | 141 | 93.8k | new_partition_expr_ctxs.resize(_partition_expr_ctxs.size()); | 142 | 194k | for (size_t i = 0; i < _partition_expr_ctxs.size(); i++) { | 143 | 100k | RETURN_IF_ERROR(_partition_expr_ctxs[i]->clone(state, new_partition_expr_ctxs[i])); | 144 | 100k | } | 145 | 93.8k | return Status::OK(); | 146 | 93.8k | } |
|
147 | | |
148 | | virtual void _do_hash(const ColumnPtr& column, HashValType* __restrict result, int idx) const; |
149 | 5.04k | virtual void _initialize_hash_vals(size_t rows) const { |
150 | 5.04k | _hash_vals.resize(rows); |
151 | 5.04k | std::ranges::fill(_hash_vals, 0); |
152 | 5.04k | } Unexecuted instantiation: _ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE21_initialize_hash_valsEm _ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE21_initialize_hash_valsEm Line | Count | Source | 149 | 5.02k | virtual void _initialize_hash_vals(size_t rows) const { | 150 | 5.02k | _hash_vals.resize(rows); | 151 | 5.02k | std::ranges::fill(_hash_vals, 0); | 152 | 5.02k | } |
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE21_initialize_hash_valsEm Line | Count | Source | 149 | 8 | virtual void _initialize_hash_vals(size_t rows) const { | 150 | 8 | _hash_vals.resize(rows); | 151 | 8 | std::ranges::fill(_hash_vals, 0); | 152 | 8 | } |
_ZNK5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE21_initialize_hash_valsEm Line | Count | Source | 149 | 8 | virtual void _initialize_hash_vals(size_t rows) const { | 150 | 8 | _hash_vals.resize(rows); | 151 | 8 | std::ranges::fill(_hash_vals, 0); | 152 | 8 | } |
|
153 | | |
154 | | VExprContextSPtrs _partition_expr_ctxs; |
155 | | mutable std::vector<HashValType> _hash_vals; |
156 | | }; |
157 | | |
158 | | struct ShuffleChannelIds { |
159 | | using HashValType = PartitionerBase::HashValType; |
160 | 5.38M | HashValType operator()(HashValType l, size_t r) { return l % r; } |
161 | | }; |
162 | | |
163 | | struct SpillPartitionChannelIds { |
164 | | using HashValType = PartitionerBase::HashValType; |
165 | | // Default spill partition mapping used by level-0 partitioning: |
166 | | // rotate hash bits and apply modulo to get a channel id directly. |
167 | 3.14M | HashValType operator()(HashValType l, size_t r) { return ((l >> 16) | (l << 16)) % r; } |
168 | | }; |
169 | | |
170 | | struct SpillRePartitionChannelIds { |
171 | | using HashValType = PartitionerBase::HashValType; |
172 | | |
173 | | // Repartition mode: return the raw hash value without modulo. |
174 | | // The caller (SpillRepartitioner) will apply level-aware hash mixing and |
175 | | // final channel mapping, so repartition behavior can vary by level. |
176 | 20 | HashValType operator()(HashValType l, size_t /*r*/) { return l; } |
177 | | }; |
178 | | |
179 | 26.6M | static inline PartitionerBase::HashValType crc32c_shuffle_mix(PartitionerBase::HashValType h) { |
180 | | // Step 1: fold high entropy into low bits |
181 | 26.6M | h ^= h >> 16; |
182 | | // Step 2: odd multiplicative scramble (cheap avalanche) |
183 | 26.6M | h *= 0xA5B35705U; |
184 | | // Step 3: final fold to break remaining linearity |
185 | 26.6M | h ^= h >> 13; |
186 | 26.6M | return h; |
187 | 26.6M | } Unexecuted instantiation: unity_0_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj unity_14_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Line | Count | Source | 179 | 650 | static inline PartitionerBase::HashValType crc32c_shuffle_mix(PartitionerBase::HashValType h) { | 180 | | // Step 1: fold high entropy into low bits | 181 | 650 | h ^= h >> 16; | 182 | | // Step 2: odd multiplicative scramble (cheap avalanche) | 183 | 650 | h *= 0xA5B35705U; | 184 | | // Step 3: final fold to break remaining linearity | 185 | 650 | h ^= h >> 13; | 186 | 650 | return h; | 187 | 650 | } |
Unexecuted instantiation: unity_1_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj unity_8_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Line | Count | Source | 179 | 26.6M | static inline PartitionerBase::HashValType crc32c_shuffle_mix(PartitionerBase::HashValType h) { | 180 | | // Step 1: fold high entropy into low bits | 181 | 26.6M | h ^= h >> 16; | 182 | | // Step 2: odd multiplicative scramble (cheap avalanche) | 183 | 26.6M | h *= 0xA5B35705U; | 184 | | // Step 3: final fold to break remaining linearity | 185 | 26.6M | h ^= h >> 13; | 186 | 26.6M | return h; | 187 | 26.6M | } |
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: unity_6_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: unity_11_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: unity_10_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: unity_5_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: unity_9_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: unity_2_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: unity_4_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: unity_3_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: hashjoin_build_sink.cpp:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: join_build_sink_operator.cpp:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: operator.cpp:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: partitioned_aggregation_sink_operator.cpp:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: scan_operator.cpp:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: vfile_result_writer.cpp:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: unity_29_cxx.cxx:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: vorc_reader.cpp:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: vparquet_reader.cpp:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: iceberg_partition_function.cpp:_ZN5dorisL18crc32c_shuffle_mixEj Unexecuted instantiation: merge_partitioner.cpp:_ZN5dorisL18crc32c_shuffle_mixEj |
188 | | |
189 | | // use high 16 bits as channel id to avoid conflict with crc32c hash table |
190 | | // shuffle hash function same with crc32c hash table(eg join hash table) will lead bad performance |
191 | | // hash table offten use low 16 bits as bucket index, so we shift 16 bits to high bits to avoid conflict |
192 | | struct ShiftChannelIds { |
193 | | using HashValType = PartitionerBase::HashValType; |
194 | 26.6M | HashValType operator()(HashValType l, size_t r) { return crc32c_shuffle_mix(l) % r; } |
195 | | }; |
196 | | |
197 | | class Crc32CHashPartitioner : public Crc32HashPartitioner<ShiftChannelIds> { |
198 | | public: |
199 | | Crc32CHashPartitioner(int partition_count) |
200 | 286k | : Crc32HashPartitioner<ShiftChannelIds>(partition_count) {} |
201 | | |
202 | | Status clone(RuntimeState* state, std::unique_ptr<PartitionerBase>& partitioner) override; |
203 | | |
204 | | private: |
205 | | void _do_hash(const ColumnPtr& column, HashValType* __restrict result, int idx) const override; |
206 | | |
207 | 41.0k | void _initialize_hash_vals(size_t rows) const override { |
208 | 41.0k | _hash_vals.resize(rows); |
209 | | // use golden ratio to initialize hash values to avoid collision with hash table's hash function |
210 | 41.0k | constexpr HashValType CRC32C_SHUFFLE_SEED = 0x9E3779B9U; |
211 | 41.0k | std::ranges::fill(_hash_vals, CRC32C_SHUFFLE_SEED); |
212 | 41.0k | } |
213 | | }; |
214 | | |
215 | | /// Instantiated once in partitioner.cpp; suppresses per-TU implicit instantiation. |
216 | | extern template class Crc32HashPartitioner<ShuffleChannelIds>; |
217 | | extern template class Crc32HashPartitioner<SpillPartitionChannelIds>; |
218 | | extern template class Crc32HashPartitioner<SpillRePartitionChannelIds>; |
219 | | |
220 | | } // namespace doris |