HappenLee commented on code in PR #9459: URL: https://github.com/apache/incubator-doris/pull/9459#discussion_r878111822
########## be/src/olap/memtable.cpp: ########## @@ -263,11 +264,46 @@ vectorized::Block MemTable::_collect_vskiplist_results() { auto function = _agg_functions[i]; function->insert_result_into(it.key()->_agg_places[i], *(_output_mutable_block.get_column_by_position(i))); - function->destroy(it.key()->_agg_places[i]); + if constexpr (is_final) { + function->destroy(it.key()->_agg_places[i]); + } } + if constexpr (!is_final) { + // re-index the row_pos in VSkipList + it.key()->_row_pos = idx; + idx++; + } + } + if constexpr (!is_final) { + // if is not final, we collect the agg results to input_block and then continue to insert + size_t shrunked_after_agg = _output_mutable_block.allocated_bytes(); + _mem_tracker->consume(shrunked_after_agg - _mem_usage); + _mem_usage = shrunked_after_agg; + _input_mutable_block.swap(_output_mutable_block); + //TODO(weixang):opt here. + std::unique_ptr<vectorized::Block> empty_input_block = + std::move(in_block.create_same_struct_block(0)); + _output_mutable_block = + vectorized::MutableBlock::build_mutable_block(empty_input_block.get()); + _output_mutable_block.clear_column_data(); } } - return _output_mutable_block.to_block(); +} + +void MemTable::shrink_memtable_by_agg() { + if (_keys_type == KeysType::DUP_KEYS) { Review Comment: DCHECK(_key_type != KeysType::DUP_KEYS) the dup keys should not call this function -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org