Perform the global merge sort and apply the global LIMIT. Each shard already applied `ORDER BY + LIMIT` locally, so we have at most `num_shards × limit` rows. The global sort + limit produces the correct result.
(&mut self, global_limit: usize)
| 57 | /// at most `num_shards × limit` rows. The global sort + limit produces |
| 58 | /// the correct result. |
| 59 | pub fn merge(&mut self, global_limit: usize) -> Vec<ShardRow> { |
| 60 | match self.direction { |
| 61 | SortDirection::Ascending => { |
| 62 | self.rows.sort_by(|a, b| a.sort_key.cmp(&b.sort_key)); |
| 63 | } |
| 64 | SortDirection::Descending => { |
| 65 | self.rows.sort_by(|a, b| b.sort_key.cmp(&a.sort_key)); |
| 66 | } |
| 67 | } |
| 68 | self.rows.truncate(global_limit); |
| 69 | self.rows.clone() |
| 70 | } |
| 71 | |
| 72 | /// Total rows collected before merge. |
| 73 | pub fn total_rows(&self) -> usize { |