HappenLee commented on code in PR #12921: URL: https://github.com/apache/doris/pull/12921#discussion_r980957363
########## be/src/vec/exec/vsort_node.cpp: ########## @@ -48,13 +48,16 @@ Status VSortNode::init(const TPlanNode& tnode, RuntimeState* state) { !row_desc.has_varlen_slots()) { _sorter.reset(new HeapSorter(_vsort_exec_exprs, _limit, _offset, _pool, _is_asc_order, _nulls_first, row_desc)); + reuse_mem = false; Review Comment: maybe set default value == `true`, only need init false only here? ########## be/src/vec/core/sort_block.cpp: ########## @@ -114,6 +114,60 @@ void sort_block(Block& block, const SortDescription& description, UInt64 limit) } } +void sort_block(Block& src_block, Block& dest_block, const SortDescription& description, Review Comment: here many code is same as upper, why only one method, you can call same `src_block` and `dest_block` to replace upper method ########## be/src/vec/core/sort_block.cpp: ########## @@ -114,6 +114,60 @@ void sort_block(Block& block, const SortDescription& description, UInt64 limit) } } +void sort_block(Block& src_block, Block& dest_block, const SortDescription& description, + UInt64 limit) { + if (!src_block) { + return; + } + + /// If only one column to sort by + if (description.size() == 1) { + bool reverse = description[0].direction == -1; + + const IColumn* column = + !description[0].column_name.empty() + ? src_block.get_by_name(description[0].column_name).column.get() + : src_block.safe_get_by_position(description[0].column_number).column.get(); + + IColumn::Permutation perm; + column->get_permutation(reverse, limit, description[0].nulls_direction, perm); + + size_t columns = src_block.columns(); + for (size_t i = 0; i < columns; ++i) { + dest_block.replace_by_position( + i, src_block.get_by_position(i).column->permute(perm, limit)); + } + } else { + size_t size = src_block.rows(); + IColumn::Permutation perm(size); + for (size_t i = 0; i < size; ++i) { + perm[i] = i; + } + + if (limit >= size) { + limit = 0; + } + + ColumnsWithSortDescriptions columns_with_sort_desc = + get_columns_with_sort_description(src_block, description); + { + EqualFlags flags(size, 1); + EqualRange range {0, size}; + + for (size_t i = 0; i < columns_with_sort_desc.size(); i++) { + ColumnSorter sorter(columns_with_sort_desc[i], limit); Review Comment: TODO:seems we can reuse the ColumnSorter, do not need construct every time? -- 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