Finalize transfer of 'num_to_commit' tuples to 'dst_batch' and transfer memory to 'dst_batch' if at the end of 'scratch_batch'. The tuples must not yet be committed to 'dst_batch'. Only needs to be called when materialising non-empty tuples.
| 122 | /// committed to 'dst_batch'. Only needs to be called when materialising non-empty |
| 123 | /// tuples. |
| 124 | void FinalizeTupleTransfer(RowBatch* dst_batch, int num_to_commit) { |
| 125 | DCHECK_GE(num_to_commit, 0); |
| 126 | DCHECK_LE(dst_batch->num_rows() + num_to_commit, dst_batch->capacity()); |
| 127 | DCHECK_LE(num_tuples_transferred + num_to_commit, num_tuples); |
| 128 | DCHECK(tuple_mem != nullptr); |
| 129 | num_tuples_transferred += num_to_commit; |
| 130 | if (!AtEnd()) return; |
| 131 | // We're at the end of the scratch batch. Transfer memory that may be referenced by |
| 132 | // transferred tuples or that we can't reuse to 'dst_batch'. |
| 133 | |
| 134 | // Future tuples won't reference data in 'aux_mem_pool' - always transfer so that |
| 135 | // we don't accumulate unneeded memory in the scratch batch. |
| 136 | dst_batch->tuple_data_pool()->AcquireData(&aux_mem_pool, false); |
| 137 | |
| 138 | // Try to avoid the transfer of 'tuple_mem' for selective scans by compacting the |
| 139 | // output batch. This avoids excessive allocation and transfer of memory, which |
| 140 | // can lead to performance problems like IMPALA-4923. |
| 141 | // Compaction is unsafe if the scratch batch was split across multiple output batches |
| 142 | // because the batch we returned earlier may hold a reference into 'tuple_mem'. |
| 143 | if (num_tuples_transferred > num_to_commit |
| 144 | || num_tuples_transferred * MIN_SELECTIVITY_TO_COMPACT > num_tuples |
| 145 | || !TryCompact(dst_batch, num_to_commit)) { |
| 146 | // Didn't compact - rows in 'dst_batch' reference 'tuple_mem'. |
| 147 | dst_batch->tuple_data_pool()->AcquireData(&tuple_mem_pool, false); |
| 148 | tuple_mem = nullptr; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /// Try to compact 'num_uncommitted_tuples' uncommitted tuples that were added to |
| 153 | /// the end of 'dst_batch' by copying them to memory allocated from |
no test coverage detected