You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "kumarUjjawal (via GitHub)" <gi...@apache.org> on 2025/12/23 13:30:26 UTC
[PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
kumarUjjawal opened a new pull request, #19468:
URL: https://github.com/apache/datafusion/pull/19468
## 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 #123` indicates that this PR will close issue #123.
-->
- Part of #15873
## Rationale for this change
After the introduction of the `partition_statistics` API there are some operators which don't support this new API, the goal is to update the operators with new API.
<!--
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.
-->
## What changes are included in this PR?
- Updated `NestedLoopJoinExec` with the new `partition_statistics`
<!--
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.
-->
## Are these changes tested?
- Added relevant tests
<!--
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)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "kumarUjjawal (via GitHub)" <gi...@apache.org>.
kumarUjjawal commented on code in PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#discussion_r2645964752
##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -550,17 +550,22 @@ impl ExecutionPlan for NestedLoopJoinExec {
}
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
- if partition.is_some() {
- return Ok(Statistics::new_unknown(&self.schema()));
- }
let join_columns = Vec::new();
- estimate_join_statistics(
- self.left.partition_statistics(None)?,
- self.right.partition_statistics(None)?,
+ let left_stats = self.left.partition_statistics(None)?;
+ let right_stats = match partition {
+ Some(partition) => self.right.partition_statistics(Some(partition))?,
+ None => self.right.partition_statistics(None)?,
+ };
+
+ let stats = estimate_join_statistics(
Review Comment:
Added comments
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#issuecomment-3695888086
I'll review the PR shortly, thank you for your contribution! @kumarUjjawal
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "kumarUjjawal (via GitHub)" <gi...@apache.org>.
kumarUjjawal commented on code in PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#discussion_r2647167964
##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -550,17 +550,22 @@ impl ExecutionPlan for NestedLoopJoinExec {
}
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
- if partition.is_some() {
- return Ok(Statistics::new_unknown(&self.schema()));
- }
let join_columns = Vec::new();
- estimate_join_statistics(
- self.left.partition_statistics(None)?,
- self.right.partition_statistics(None)?,
+ let left_stats = self.left.partition_statistics(None)?;
+ let right_stats = match partition {
+ Some(partition) => self.right.partition_statistics(Some(partition))?,
+ None => self.right.partition_statistics(None)?,
+ };
+
+ let stats = estimate_join_statistics(
Review Comment:
Got it. I kept this comment while also added the comment to the `estimate_join_statistics()` function.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "kumarUjjawal (via GitHub)" <gi...@apache.org>.
kumarUjjawal commented on code in PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#discussion_r2651269259
##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -550,17 +550,34 @@ impl ExecutionPlan for NestedLoopJoinExec {
}
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
- if partition.is_some() {
- return Ok(Statistics::new_unknown(&self.schema()));
- }
+ // NestedLoopJoinExec is designed for joins without equijoin keys in the
+ // ON clause (e.g., `t1 JOIN t2 ON (t1.v1 + t2.v1) % 2 = 0`). Any join
+ // predicates are stored in `self.filter`, but `estimate_join_statistics`
+ // currently doesn't support selectivity estimation for such arbitrary
+ // filter expressions. We pass an empty join column list, which means
+ // the cardinality estimation cannot use column statistics and returns
+ // unknown row counts.
let join_columns = Vec::new();
- estimate_join_statistics(
- self.left.partition_statistics(None)?,
- self.right.partition_statistics(None)?,
+
+ // Left side is always a single partition (Distribution::SinglePartition),
+ // so we always request overall stats with `None`. Right side can have
+ // multiple partitions, so we forward the partition parameter to get
+ // partition-specific statistics when requested.
+ let left_stats = self.left.partition_statistics(None)?;
+ let right_stats = match partition {
+ Some(partition) => self.right.partition_statistics(Some(partition))?,
+ None => self.right.partition_statistics(None)?,
Review Comment:
Yes this test covers that
https://github.com/apache/datafusion/pull/19468/changes/BASE..68bcbd6f2ad8e8b59e1508022067631ed3414c4b#diff-984f04e8c9c9fcd35a4c1b89e446506c813be1fe41b2716533bf4f41c1157339R640
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#discussion_r2646474018
##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -550,17 +550,22 @@ impl ExecutionPlan for NestedLoopJoinExec {
}
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
- if partition.is_some() {
- return Ok(Statistics::new_unknown(&self.schema()));
- }
let join_columns = Vec::new();
- estimate_join_statistics(
- self.left.partition_statistics(None)?,
- self.right.partition_statistics(None)?,
+ let left_stats = self.left.partition_statistics(None)?;
+ let right_stats = match partition {
+ Some(partition) => self.right.partition_statistics(Some(partition))?,
+ None => self.right.partition_statistics(None)?,
+ };
+
+ let stats = estimate_join_statistics(
Review Comment:
I mean adding comments to `estimate_join_statistics()` to specify its behavior; I find it hard to figure out how it propagates statistics.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on code in PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#discussion_r2651080481
##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -550,17 +550,34 @@ impl ExecutionPlan for NestedLoopJoinExec {
}
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
- if partition.is_some() {
- return Ok(Statistics::new_unknown(&self.schema()));
- }
+ // NestedLoopJoinExec is designed for joins without equijoin keys in the
+ // ON clause (e.g., `t1 JOIN t2 ON (t1.v1 + t2.v1) % 2 = 0`). Any join
+ // predicates are stored in `self.filter`, but `estimate_join_statistics`
+ // currently doesn't support selectivity estimation for such arbitrary
+ // filter expressions. We pass an empty join column list, which means
+ // the cardinality estimation cannot use column statistics and returns
+ // unknown row counts.
let join_columns = Vec::new();
- estimate_join_statistics(
- self.left.partition_statistics(None)?,
- self.right.partition_statistics(None)?,
+
+ // Left side is always a single partition (Distribution::SinglePartition),
+ // so we always request overall stats with `None`. Right side can have
+ // multiple partitions, so we forward the partition parameter to get
+ // partition-specific statistics when requested.
+ let left_stats = self.left.partition_statistics(None)?;
+ let right_stats = match partition {
+ Some(partition) => self.right.partition_statistics(Some(partition))?,
+ None => self.right.partition_statistics(None)?,
Review Comment:
Do we have a test for the case?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on code in PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#discussion_r2652601266
##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -550,17 +550,34 @@ impl ExecutionPlan for NestedLoopJoinExec {
}
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
- if partition.is_some() {
- return Ok(Statistics::new_unknown(&self.schema()));
- }
+ // NestedLoopJoinExec is designed for joins without equijoin keys in the
+ // ON clause (e.g., `t1 JOIN t2 ON (t1.v1 + t2.v1) % 2 = 0`). Any join
+ // predicates are stored in `self.filter`, but `estimate_join_statistics`
+ // currently doesn't support selectivity estimation for such arbitrary
+ // filter expressions. We pass an empty join column list, which means
+ // the cardinality estimation cannot use column statistics and returns
+ // unknown row counts.
let join_columns = Vec::new();
- estimate_join_statistics(
- self.left.partition_statistics(None)?,
- self.right.partition_statistics(None)?,
+
+ // Left side is always a single partition (Distribution::SinglePartition),
+ // so we always request overall stats with `None`. Right side can have
+ // multiple partitions, so we forward the partition parameter to get
+ // partition-specific statistics when requested.
+ let left_stats = self.left.partition_statistics(None)?;
+ let right_stats = match partition {
+ Some(partition) => self.right.partition_statistics(Some(partition))?,
+ None => self.right.partition_statistics(None)?,
Review Comment:
For right side, match partition could be some or none, but I only see a test for nested_loop_join
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#discussion_r2644617827
##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -550,17 +550,22 @@ impl ExecutionPlan for NestedLoopJoinExec {
}
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
- if partition.is_some() {
- return Ok(Statistics::new_unknown(&self.schema()));
- }
let join_columns = Vec::new();
- estimate_join_statistics(
- self.left.partition_statistics(None)?,
- self.right.partition_statistics(None)?,
+ let left_stats = self.left.partition_statistics(None)?;
+ let right_stats = match partition {
+ Some(partition) => self.right.partition_statistics(Some(partition))?,
+ None => self.right.partition_statistics(None)?,
+ };
+
+ let stats = estimate_join_statistics(
Review Comment:
I think we should add more comments to this function to explain how it propagates statistics.
In particular, here we set the join columns to empty, but NLJ might have additional join conditions (for example, `t1 join t2 on (t1.v1+t2.v1)%2=0`), and this utility is not able to handle it yet. Is this function assuming the input join don't have any join conditions?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#discussion_r2650431413
##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -550,17 +550,22 @@ impl ExecutionPlan for NestedLoopJoinExec {
}
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
- if partition.is_some() {
- return Ok(Statistics::new_unknown(&self.schema()));
- }
let join_columns = Vec::new();
- estimate_join_statistics(
- self.left.partition_statistics(None)?,
- self.right.partition_statistics(None)?,
+ let left_stats = self.left.partition_statistics(None)?;
+ let right_stats = match partition {
+ Some(partition) => self.right.partition_statistics(Some(partition))?,
+ None => self.right.partition_statistics(None)?,
+ };
+
+ let stats = estimate_join_statistics(
Review Comment:
Since you requested my review, I’m not yet familiar with this statistics propagation module, so I’ll need some time in the future to read through the relevant code before I can effectively review and approve it.
This looks like a nice contribution—thank you.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#issuecomment-3703783535
Thanks @kumarUjjawal and @xudong963
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #19468:
URL: https://github.com/apache/datafusion/pull/19468
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Implement `partition_statistics` API for `NestedLoopJoinExec` [datafusion]
Posted by "kumarUjjawal (via GitHub)" <gi...@apache.org>.
kumarUjjawal commented on code in PR #19468:
URL: https://github.com/apache/datafusion/pull/19468#discussion_r2652996975
##########
datafusion/physical-plan/src/joins/nested_loop_join.rs:
##########
@@ -550,17 +550,34 @@ impl ExecutionPlan for NestedLoopJoinExec {
}
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
- if partition.is_some() {
- return Ok(Statistics::new_unknown(&self.schema()));
- }
+ // NestedLoopJoinExec is designed for joins without equijoin keys in the
+ // ON clause (e.g., `t1 JOIN t2 ON (t1.v1 + t2.v1) % 2 = 0`). Any join
+ // predicates are stored in `self.filter`, but `estimate_join_statistics`
+ // currently doesn't support selectivity estimation for such arbitrary
+ // filter expressions. We pass an empty join column list, which means
+ // the cardinality estimation cannot use column statistics and returns
+ // unknown row counts.
let join_columns = Vec::new();
- estimate_join_statistics(
- self.left.partition_statistics(None)?,
- self.right.partition_statistics(None)?,
+
+ // Left side is always a single partition (Distribution::SinglePartition),
+ // so we always request overall stats with `None`. Right side can have
+ // multiple partitions, so we forward the partition parameter to get
+ // partition-specific statistics when requested.
+ let left_stats = self.left.partition_statistics(None)?;
+ let right_stats = match partition {
+ Some(partition) => self.right.partition_statistics(Some(partition))?,
+ None => self.right.partition_statistics(None)?,
Review Comment:
Yeah, I updated the test.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org