feat: Add selectivity metric to NestedLoopJoinExec for EXPLAIN ANALYZE#18481
Merged
2010YOUY01 merged 8 commits intoapache:mainfrom Nov 5, 2025
Merged
feat: Add selectivity metric to NestedLoopJoinExec for EXPLAIN ANALYZE#184812010YOUY01 merged 8 commits intoapache:mainfrom
2010YOUY01 merged 8 commits intoapache:mainfrom
Conversation
petern48
commented
Nov 4, 2025
Comment on lines
1132
to
1139
| // 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); | ||
| } |
Contributor
Author
There was a problem hiding this 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 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.
Comment on lines
+1487
to
+1491
| 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); |
Contributor
Author
There was a problem hiding this comment.
Update output_rows at flush time.
Co-authored-by: Yongting You <2010youy01@gmail.com>
codetyri0n
pushed a commit
to codetyri0n/datafusion
that referenced
this pull request
Nov 11, 2025
apache#18481) ## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#18407 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> This new metric will give the user better visibility to see what portion of the possibilities is actually being matched. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Add selectivity metric to NestedLoopJoinExec for EXPLAIN ANALYZE ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Added tests ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> Yes, new metric in explain analyze <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Co-authored-by: Yongting You <2010youy01@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
selectivitymetrics (forExplain Analyze) in Nested Loop Join #18407Rationale for this change
This new metric will give the user better visibility to see what portion of the possibilities is actually being matched.
What changes are included in this PR?
Add selectivity metric to NestedLoopJoinExec for EXPLAIN ANALYZE
Are these changes tested?
Added tests
Are there any user-facing changes?
Yes, new metric in explain analyze