diff --git a/crates/proof-of-sql/src/base/database/join_util.rs b/crates/proof-of-sql/src/base/database/join_util.rs index 363b704b2..d8e274f10 100644 --- a/crates/proof-of-sql/src/base/database/join_util.rs +++ b/crates/proof-of-sql/src/base/database/join_util.rs @@ -102,16 +102,17 @@ fn get_sort_merge_join_indexes<'a, S: Scalar>( }) .collect(); + // Advance the iterators + left_iter.nth(left_group.len() - 1); + right_iter.nth(right_group.len() - 1); + // Generate all pairs (Cartesian product) let pairs: Vec<_> = left_group .iter() - .flat_map(|&l| right_group.iter().map(move |&r| (l, r))) + .cartesian_product(right_group.iter()) + .map(|(&lidx, &ridx)| (lidx, ridx)) .collect(); - // Advance the iterators - left_iter.nth(left_group.len() - 1); - right_iter.nth(right_group.len() - 1); - Some(pairs) } }