dongjoon-hyun opened a new pull request, #60633: URL: https://github.com/apache/spark/pull/60633
### What changes were proposed in this pull request? `SizeInBytesOnlyStatsPlanVisitor` now estimates a left single join from its left side, the same way as an existence join. Such a join outputs each row of the left side once, with the columns of the right side added, as a second match fails the query. So its size is the left side's, scaled by the row widths, and its row count and column stats are the left side's. `Join.maxRows` now returns the left side's `maxRows` for a left single join, as for a left semi or anti join, instead of `(left * right).max(left)`. With CBO, `JoinEstimation` does not support a left single join, and falls back to the same visitor, as it does for an existence join. It is not estimated as a left semi join from the left side's row count and column stats, because without `avgLen`, as for a materialized AQE stage, that size can be far below the left side's. ### Why are the changes needed? `spark.sql.optimizer.scalarSubqueryUseSingleJoin` (`true` by default) plans a correlated scalar subquery that is not proven to return one row as a left single join. Before, its size fell to `default`, which multiplies the sizes of the two sides, and its `maxRows` was the product of the two sides' `maxRows`. A join above it sees that side as far bigger than it is, and can miss a broadcast. ### Does this PR introduce _any_ user-facing change? Yes. A plan above a left single join can change, as a join above it can now be broadcast. The results do not change. ### How was this patch tested? - New tests in `BasicStatsEstimationSuite`, with CBO on and off, and in `LogicalPlanSuite`. Both fail without the change. - The stats estimation suites, the TPC-DS and TPC-H plan stability suites (including the `WithStats` variants), `SingleJoinSuite`, `JoinHintSuite`, `InjectRuntimeFilterSuite`, `SubquerySuite` and `ExistenceJoinSuite` pass. No approved plan changed. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 -- 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]
