Skip to content

refactor: derive cross join equivalence properties as an inner join - #26631

Open
jayzhan211 wants to merge 3 commits into
apache:mainfrom
jayzhan211:cross-join-inner-equivalence
Open

jayzhan211 wants to merge 3 commits into
apache:mainfrom
jayzhan211:cross-join-inner-equivalence

Conversation

@jayzhan211

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

CrossJoinExec computes its output facts (constants, equalities, orderings) by calling
join_equivalence_properties with JoinType::Full. A cross join never pads rows with NULLs, so a full outer join
is the wrong model. Today this does not change any plan, because the current outer-join rules keep the constants
that a cross join needs. But it ties cross join to rules that are about NULL padding, and those rules are being
changed: with #26459 or #26042 merged, a query such as

SELECT l.c, s.x
FROM (SELECT c FROM t) l CROSS JOIN (SELECT x FROM small WHERE x = 1) s
ORDER BY l.c, s.x;

sorts on x again even though x = 1 still holds after the join. The cross-join cases added in #26570 fail with
either PR merged in.

What changes are included in this PR?

CrossJoinExec now derives its equivalence properties as an inner join with no join keys, with a comment that
says why. Nothing else changes: with no keys and no maintained input order, an inner join and a full outer join
give the same facts under the current rules.

What is the testing strategy for this PR?

The cross-join cases in equivalence_properties.slt from #26570 cover this change. All sqllogictest files and the
join and physical optimizer tests pass unchanged. I also merged #26459 and #26042 into this branch one at a time:
without this change the cross-join cases fail with an extra sort, and with it they pass.

Are there any user-facing changes?

No.

@jayzhan211
jayzhan211 marked this pull request as ready for review October 23, 2026 03:58
@github-actions github-actions Bot added core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-plan Changes to the physical-plan crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant