HappenLee commented on code in PR #9459: URL: https://github.com/apache/incubator-doris/pull/9459#discussion_r876733240
########## be/src/olap/memtable.cpp: ########## @@ -263,11 +266,43 @@ 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]); + } } + // re-index the row_pos in VSkipList + it.key()->_row_pos = idx; + idx++; } + if constexpr (!is_final) { + 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(); + } + } +} + +void MemTable::shrink_memtable_by_agg() { + if (_is_shrunk_by_agg) { + return; } - return _output_mutable_block.to_block(); + _collect_vskiplist_to_output<false>(); + _is_shrunk_by_agg = true; +} + +bool MemTable::is_flush() { + return memory_usage() >= config::write_buffer_size; +} + +bool MemTable::need_to_agg() { + return memory_usage() >= config::memtable_max_buffer_size; Review Comment: if is dup key, just call `is_flush()` -- 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