Merge adjacent vectors to larger vectors as long as the result do not exceed the size limit. This is important for performance because each small vector here would be duplicated by the number of rows on probe side, result in huge number of small vectors in the output.
| 89 | // here would be duplicated by the number of rows on probe side, result in huge |
| 90 | // number of small vectors in the output. |
| 91 | std::vector<RowVectorPtr> NestedLoopJoinBuild::mergeDataVectors() const { |
| 92 | const auto maxBatchRows = |
| 93 | operatorCtx_->task()->queryCtx()->queryConfig().maxOutputBatchRows(); |
| 94 | std::vector<RowVectorPtr> merged; |
| 95 | for (int i = 0; i < dataVectors_.size();) { |
| 96 | // convert int32_t to int64_t to avoid sum overflow |
| 97 | int64_t batchSize = dataVectors_[i]->size(); |
| 98 | auto j = i + 1; |
| 99 | while (j < dataVectors_.size() && |
| 100 | batchSize + dataVectors_[j]->size() <= maxBatchRows) { |
| 101 | batchSize += dataVectors_[j++]->size(); |
| 102 | } |
| 103 | if (j == i + 1) { |
| 104 | merged.push_back(dataVectors_[i++]); |
| 105 | } else { |
| 106 | auto batch = BaseVector::create<RowVector>( |
| 107 | dataVectors_[i]->type(), batchSize, pool()); |
| 108 | batchSize = 0; |
| 109 | while (i < j) { |
| 110 | auto* source = dataVectors_[i++].get(); |
| 111 | batch->copy(source, batchSize, 0, source->size()); |
| 112 | batchSize += source->size(); |
| 113 | } |
| 114 | merged.push_back(std::move(batch)); |
| 115 | } |
| 116 | } |
| 117 | return merged; |
| 118 | } |
| 119 | |
| 120 | void NestedLoopJoinBuild::noMoreInput() { |
| 121 | Operator::noMoreInput(); |