184856 {
184857 D_ASSERT(sink.hash_table->GetRadixBits() > JoinHashTable::INITIAL_RADIX_BITS);
184858 auto block_size = sink.hash_table->buffer_manager.GetBlockSize();
184859
184860 idx_t total_size = 0;
184861 idx_t total_count = 0;
184862 for (auto &local_ht : local_hts) {
184863 auto &sink_collection = local_ht->GetSinkCollection();
184864 total_size += sink_collection.SizeInBytes();
184865 total_count += sink_collection.Count();
184866 }
184867 auto total_blocks = (total_size + block_size - 1) / block_size;
184868 auto count_per_block = total_count / total_blocks;
184869 auto blocks_per_vector = MaxValue<idx_t>(STANDARD_VECTOR_SIZE / count_per_block, 2);
184870
184871
184872 auto partition_multiplier =
184874 auto thread_memory = 2 * blocks_per_vector * partition_multiplier * block_size;
184875 auto repartition_threads = MaxValue<idx_t>(sink.temporary_memory_state->GetReservation() / thread_memory, 1);
184876
184877 if (repartition_threads < local_hts.size()) {
184878
184879 for (
idx_t thread_idx = repartition_threads; thread_idx < local_hts.size(); thread_idx++) {
184880 local_hts[thread_idx % repartition_threads]->Merge(*local_hts[thread_idx]);
184881 }
184882 local_hts.resize(repartition_threads);
184883 }
184884
184885 auto &context =
pipeline->GetClientContext();
184886
184887 vector<shared_ptr<Task>> partition_tasks;
184888 partition_tasks.reserve(local_hts.size());
184889 for (auto &local_ht : local_hts) {
184890 partition_tasks.push_back(
184891 make_uniq<HashJoinRepartitionTask>(shared_from_this(), context, *sink.hash_table, *local_ht, op));
184892 }
184893 SetTasks(std::move(partition_tasks));
184894 }
shared_ptr< Pipeline > pipeline
The pipeline that this event belongs to.
Definition duckdb.cpp:35137
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static constexpr idx_t NumberOfPartitions(idx_t radix_bits)
The number of partitions for a given number of radix bits.
Definition duckdb.cpp:93425