107293 {
107294 if (!merger.external) {
107295 return;
107296 }
107297
107298
107299 unique_lock<mutex> guard(destroy_lock, std::try_to_lock);
107300 if (!guard.owns_lock()) {
107301 return;
107302 }
107303
107304
107305 idx_t end_partition_idx;
107306 for (end_partition_idx = destroy_partition_idx; end_partition_idx < num_partitions; end_partition_idx++) {
107307 const auto &
partition = *partitions[end_partition_idx];
107309 break;
107310 }
107311 }
107312
107313
107314 if (end_partition_idx < num_threads) {
107315 return;
107316 }
107317 end_partition_idx -= num_threads;
107318 if (end_partition_idx <= destroy_partition_idx) {
107319 return;
107320 }
107321
107322
107323 const auto total_tuples_to_destroy = (end_partition_idx - destroy_partition_idx) * merger.partition_size;
107324 const auto tuples_to_destroy_per_partition = total_tuples_to_destroy / num_partitions;
107325
107326
107327 const auto &run = *merger.sorted_runs[0];
107328 const auto tuples_per_block =
107329 run.payload_data ? run.payload_data->TuplesPerBlock() : run.key_data->TuplesPerBlock();
107330
107331
107332 const auto blocks_to_destroy_per_partition = tuples_to_destroy_per_partition / tuples_per_block;
107333 if (blocks_to_destroy_per_partition == 0) {
107334 return;
107335 }
107336
107337 for (
idx_t run_idx = 0; run_idx < num_runs; run_idx++) {
107338 idx_t begin_idx = 0;
107339 if (destroy_partition_idx != 0) {
107340 auto &begin_partition = *partitions[destroy_partition_idx];
107341 auto partition_guard = begin_partition.Lock();
107342 begin_idx = begin_partition.GetRunBoundaries(partition_guard)[run_idx].end;
107343 }
107344
107345 idx_t end_idx = merger.sorted_runs[run_idx]->Count();
107346 if (end_partition_idx != num_partitions) {
107347 auto &end_partition = *partitions[end_partition_idx];
107348 auto partition_guard = end_partition.Lock();
107349 end_idx = end_partition.GetRunBoundaries(partition_guard)[run_idx].end;
107350 }
107351
107352 merger.sorted_runs[run_idx]->DestroyData(begin_idx, end_idx);
107353 }
107354
107355 destroy_partition_idx = end_partition_idx;
107356 }
int partition(const std::vector< _Tp > &_vec, std::vector< int > &labels, _EqPredicate predicate=_EqPredicate())