| 939 | } |
| 940 | |
| 941 | Status GroupingAggregator::SpillPartition(bool more_aggregate_rows) { |
| 942 | int64_t max_freed_mem = 0; |
| 943 | int partition_idx = -1; |
| 944 | |
| 945 | // Iterate over the partitions and pick the largest partition that is not spilled. |
| 946 | for (int i = 0; i < hash_partitions_.size(); ++i) { |
| 947 | if (hash_partitions_[i] == nullptr) continue; |
| 948 | if (hash_partitions_[i]->is_closed) continue; |
| 949 | if (hash_partitions_[i]->is_spilled()) continue; |
| 950 | // Pass 'true' because we need to keep the write block pinned. See Partition::Spill(). |
| 951 | int64_t mem = hash_partitions_[i]->aggregated_row_stream->BytesPinned(true); |
| 952 | mem += hash_partitions_[i]->hash_tbl->ByteSize(); |
| 953 | mem += hash_partitions_[i]->agg_fn_perm_pool->total_reserved_bytes(); |
| 954 | DCHECK_GT(mem, 0); // At least the hash table buckets should occupy memory. |
| 955 | if (mem > max_freed_mem) { |
| 956 | max_freed_mem = mem; |
| 957 | partition_idx = i; |
| 958 | } |
| 959 | } |
| 960 | DCHECK_NE(partition_idx, -1) << "Should have been able to spill a partition to " |
| 961 | << "reclaim memory: " |
| 962 | << buffer_pool_client()->DebugString(); |
| 963 | // Remove references to the destroyed hash table from 'hash_tbls_'. |
| 964 | // Additionally, we might be dealing with a rebuilt spilled partition, where all |
| 965 | // partitions point to a single in-memory partition. This also ensures that 'hash_tbls_' |
| 966 | // remains consistent in that case. |
| 967 | for (int i = 0; i < PARTITION_FANOUT; ++i) { |
| 968 | if (hash_partitions_[i] == hash_partitions_[partition_idx]) hash_tbls_[i] = nullptr; |
| 969 | } |
| 970 | Status status = hash_partitions_[partition_idx]->Spill(more_aggregate_rows); |
| 971 | // Try to save back the large write page reservation if it's used by a pinned partition. |
| 972 | if (status.ok() && large_write_page_reservation_.GetReservation() == 0) { |
| 973 | TrySaveLargeWritePageReservation(); |
| 974 | } |
| 975 | return status; |
| 976 | } |
| 977 | |
| 978 | Status GroupingAggregator::MoveHashPartitions(int64_t num_input_rows) { |
| 979 | DCHECK(!hash_partitions_.empty()); |
nothing calls this directly
no test coverage detected