You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "jonathanc-n (via GitHub)" <gi...@apache.org> on 2026/03/04 22:08:28 UTC
[PR] fix: Return `probe_side.len()` for RightMark/Anti count(*) queries [datafusion]
jonathanc-n opened a new pull request, #20710:
URL: https://github.com/apache/datafusion/pull/20710
## 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.
-->
- Closes #20669 .
## Rationale for this change
Return probe_side.len() for count(*) queries
<!--
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.
-->
<!--
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?
slt 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] fix: Return `probe_side.len()` for RightMark/Anti count(*) queries [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #20710:
URL: https://github.com/apache/datafusion/pull/20710#discussion_r2886756472
##########
datafusion/physical-plan/src/joins/utils.rs:
##########
@@ -998,9 +1003,17 @@ pub(crate) fn build_batch_from_indices(
probe_indices: &UInt32Array,
column_indices: &[ColumnIndex],
build_side: JoinSide,
+ join_type: JoinType,
) -> Result<RecordBatch> {
if schema.fields().is_empty() {
- return new_empty_schema_batch(schema, build_indices.len());
+ // For RightAnti and RightSemi joins, after `adjust_indices_by_join_type`
+ // the build_indices were untouched so only probe_indices hold the actual
+ // row count.
+ let row_count = match join_type {
+ JoinType::RightAnti | JoinType::RightSemi => probe_indices.len(),
Review Comment:
should `RightMark` be in the list?
--
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] fix: Return `probe_side.len()` for RightMark/Anti count(*) queries [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #20710:
URL: https://github.com/apache/datafusion/pull/20710#discussion_r2886782292
##########
datafusion/sqllogictest/test_files/joins.slt:
##########
@@ -5318,3 +5318,46 @@ DROP TABLE issue_20437_small;
statement count 0
DROP TABLE issue_20437_large;
+
+# Test count(*) with right semi/anti joins returns correct row counts
+# issue: https://github.com/apache/datafusion/issues/20669
+
+statement ok
+CREATE TABLE t1 (k INT, v INT);
+
+statement ok
+CREATE TABLE t2 (k INT, v INT);
+
+statement ok
+INSERT INTO t1 SELECT i AS k, i AS v FROM generate_series(1, 100) t(i);
+
+statement ok
+INSERT INTO t2 VALUES (1, 1);
+
+query I
+WITH t AS (
+ SELECT *
+ FROM t1
+ LEFT ANTI JOIN t2 ON t1.k = t2.k
+)
+SELECT count(*)
+FROM t;
+----
+99
+
+query I
+WITH t AS (
+ SELECT *
+ FROM t1
+ LEFT SEMI JOIN t2 ON t1.k = t2.k
+)
+SELECT count(*)
+FROM t;
Review Comment:
double checked tests with duckDB, everything is fine
--
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] fix: Return `probe_side.len()` for RightMark/Anti count(*) queries [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead merged PR #20710:
URL: https://github.com/apache/datafusion/pull/20710
--
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] fix: Return `probe_side.len()` for RightMark/Anti count(*) queries [datafusion]
Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on code in PR #20710:
URL: https://github.com/apache/datafusion/pull/20710#discussion_r2886772286
##########
datafusion/physical-plan/src/joins/utils.rs:
##########
@@ -998,9 +1003,17 @@ pub(crate) fn build_batch_from_indices(
probe_indices: &UInt32Array,
column_indices: &[ColumnIndex],
build_side: JoinSide,
+ join_type: JoinType,
) -> Result<RecordBatch> {
if schema.fields().is_empty() {
- return new_empty_schema_batch(schema, build_indices.len());
+ // For RightAnti and RightSemi joins, after `adjust_indices_by_join_type`
+ // the build_indices were untouched so only probe_indices hold the actual
+ // row count.
+ let row_count = match join_type {
+ JoinType::RightAnti | JoinType::RightSemi => probe_indices.len(),
Review Comment:
No it becomes the same number of indices for both left + right indices. Refer to [here](https://github.com/apache/datafusion/blob/340ef606cf19f63a6b8e01160a43a394bbfd46f4/datafusion/physical-plan/src/joins/utils.rs#L1137)
--
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] fix: Return `probe_side.len()` for RightMark/Anti count(*) queries [datafusion]
Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on PR #20710:
URL: https://github.com/apache/datafusion/pull/20710#issuecomment-4000609138
cc @nuno-faria
--
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