Copilot commented on code in PR #66588:
URL: https://github.com/apache/doris/pull/66588#discussion_r3737462641


##########
be/src/load/memtable/memtable.cpp:
##########
@@ -380,46 +385,114 @@ Status MemTable::_put_into_output(Block& in_block) {
     if (_need_row_binlog_lsn) {
         _output_row_binlog_lsns.reserve(_output_row_binlog_lsns.size() + 
in_block.rows());
     }
-    for (int i = 0; i < _row_in_blocks->size(); i++) {
-        row_pos_vec.emplace_back((*_row_in_blocks)[i]->_row_pos);
-        _append_output_row_binlog_lsn((*_row_in_blocks)[i].get());
+    for (const auto& row : *_row_in_blocks) {
+        row_pos_vec.emplace_back(row._row_pos);
+        _append_output_row_binlog_lsn(row);
     }
     return _output_mutable_block.add_rows(&in_block, row_pos_vec.data(),
                                           row_pos_vec.data() + 
in_block.rows());
 }
 
+// ColumnSorter keeps an inline copy of the key next to the row id, so a
+// comparison no longer chases a row pointer nor pays a virtual
+// IColumn::compare_at, which is what dominated the previous kernel.
+size_t MemTable::_sort_permutation_by_key_columns(MutableBlock& block,
+                                                  const std::vector<int>& 
key_col_idx,
+                                                  IColumn::Permutation& perm,
+                                                  bool descending_row_pos) {
+    const size_t num_rows = perm.size();
+    if (num_rows == 0) {
+        return 0;
+    }
+    EqualFlags flags(num_rows, 1);
+    EqualRange range {0, static_cast<int>(num_rows)};
+    HybridSorter hybrid_sorter;

Review Comment:
   _sort_permutation_by_key_columns() casts perm.size() to int for EqualRange 
and ColumnSorter internally truncates row ids to uint32_t 
(PermutationWithInlineValue::row_id). If the memtable block ever grows beyond 
these bounds, the sort can overflow/truncate and produce incorrect ordering or 
out-of-bounds access. Add explicit bounds checks before constructing EqualRange 
/ invoking ColumnSorter so failures are loud and deterministic.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to