dataroaring commented on code in PR #56361:
URL: https://github.com/apache/doris/pull/56361#discussion_r2443870174


##########
be/src/vec/sink/vtablet_finder.cpp:
##########
@@ -84,14 +87,45 @@ Status OlapTabletFinder::find_tablets(RuntimeState* state, 
Block* block, int row
     if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_ROW) {
         _vpartition->find_tablets(block, qualified_rows, partitions, 
tablet_index);
     } else {
-        // for random distribution
+        // For random distribution: use buffer to cache tablet selection per 
partition
         _vpartition->find_tablets(block, qualified_rows, partitions, 
tablet_index,
                                   &_partition_to_tablet_map);
+
         if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_BATCH) {
-            for (auto it : _partition_to_tablet_map) {
-                // do round-robin for next batch
-                if (it.first->load_tablet_idx != -1) {
-                    it.first->load_tablet_idx++;
+            // Handle tablet switching for random distribution
+            // Count rows per partition in this batch
+            std::unordered_map<VOlapTablePartition*, int64_t> 
partition_row_counts;
+            for (size_t i = 0; i < qualified_rows.size(); ++i) {
+                auto* partition = partitions[qualified_rows[i]];
+                if (partition != nullptr) {
+                    partition_row_counts[partition]++;

Review Comment:
   We can add a filed in VOlapTablePartition named rows_in_batch to avoid 
introduce a map here.



-- 
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