petern48 commented on code in PR #18481:
URL: https://github.com/apache/datafusion/pull/18481#discussion_r2488987167


##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -1455,7 +1484,11 @@ impl NestedLoopJoinStream {
             if let Some(batch) = self.output_buffer.next_completed_batch() {
                 // HACK: this is not part of `BaselineMetrics` yet, so update 
it
                 // manually
-                self.join_metrics.output_batches.add(1);
+                self.metrics.join_metrics.output_batches.add(1);
+
+                // Update output rows for selectivity metric
+                let output_rows = batch.num_rows();
+                self.metrics.selectivity.add_part(output_rows);

Review Comment:
   Update `output_rows` at flush time.



##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -1108,6 +1128,16 @@ impl NestedLoopJoinStream {
             Ok(false) => {
                 // Left exhausted, transition to FetchingRight
                 self.left_probe_idx = 0;
+
+                // Selectivity Metric: Update total possibilities for the 
batch (left_rows * right_rows)
+                if let (Ok(left_data), Some(right_batch)) =
+                    (self.get_left_data(), self.current_right_batch.as_ref())
+                {
+                    let left_rows = left_data.batch().num_rows();
+                    let right_rows = right_batch.num_rows();
+                    self.metrics.selectivity.add_total(left_rows * right_rows);
+                }

Review Comment:
   I originally tried to get the values and calculate `num_left * num_right` at 
the end (in a `drop()` method, similar to how it was done 
[here](https://github.com/apache/datafusion/blob/59316de977245efd606b9643520ff89f96657e53/datafusion/physical-plan/src/joins/utils.rs#L1334-L1351)
 for `BuildProbeJoinMetrics`. But found it difficult to get the correctness 
consistently right since these are all multiple streams.
   
   Instead, I'm doing it incrementally. The basic idea here is that for each 
right batch, we `add_total()` the size of the full left buffer times the 
num_rows in the current batch. Doing that num_batches times gives us the 
equivalent of `num_right * num_left`.



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