Skip to content

[branch-54] Gate new ScalarSubqueryExec node behind session property (#22530)#22690

Open
LiaCastaneda wants to merge 2 commits into
apache:branch-54from
LiaCastaneda:lia/backport-pr-22530
Open

[branch-54] Gate new ScalarSubqueryExec node behind session property (#22530)#22690
LiaCastaneda wants to merge 2 commits into
apache:branch-54from
LiaCastaneda:lia/backport-pr-22530

Conversation

@LiaCastaneda
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • Closes #.

Rationale for this change

This PR backports #22530

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

Related to discussion on apache#21240 and
apache#21080 (comment).

PR apache#21240 introduced `ScalarSubqueryExec` / `ScalarSubqueryExpr` to
execute uncorrelated scalar subqueries during physical execution. The
two communicate via shared in process state (a `slot` in
`ExecutionProps`), which breaks distributed execution that may split
execution across a network boundary between the producer
(`ScalarSubqueryExec`) and the consumer expression
(`ScalarSubqueryExpr`). See more details on this explanation in
[datafusion-contrib/datafusion-distributed#460](datafusion-contrib/datafusion-distributed#460)

Adds a new optimizer config option
`datafusion.optimizer.enable_physical_uncorrelated_scalar_subquery`
(default true, preserving the current behavior). When true (default),
behavior is unchanged from current main; when false, all scalar
subqueries are rewritten to left joins by `ScalarSubqueryToJoin` and
`ScalarSubqueryExec` is never constructed (which was the previous
behavior).

Yes all tests pass and added
`uncorrelated_scalar_subquery_rewritten_when_flag_off` to test the
negative case.

Yes, a new config option
`datafusion.optimizer.physical_uncorrelated_scalar_subquery` (this just
changes the way the query is executed but not the results)
@github-actions github-actions Bot added documentation Improvements or additions to documentation optimizer Optimizer rules core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) common Related to common crate labels Jun 1, 2026
@LiaCastaneda LiaCastaneda changed the title Gate new ScalarSubqueryExec node behind session property (#22530) [branch-54] Gate new ScalarSubqueryExec node behind session property (#22530) Jun 1, 2026
Comment on lines -2123 to -2127
# Scalar subquery returning zero rows → NULL
query I
SELECT (SELECT v FROM sq_empty);
----
NULL
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on branch-54 this query returns nothing (empty), on main it returns NULL because of https://github.com/apache/datafusion/pull/22316/changes. I think this is a preexisting bug (that the PR i mention fixed), the correct behavior is to return null

Do we want to backport that PR as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we should backport #22316 as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is a test case I added on the PR I'm backporting, so this bug will not pop up in the existing sqllogic tests)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just confirmed this bug is preexisting, this was the behavior in branch-53

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backport of 22316 -> #22693

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate core Core DataFusion crate documentation Improvements or additions to documentation optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants