[4.1-dev] fix: allow scalar subquery in INNER JOIN ON condition#25359
[4.1-dev] fix: allow scalar subquery in INNER JOIN ON condition#25359aunjgr wants to merge 3 commits into
Conversation
Replace the NYI error in TableBinder.BindSubquery with the normal baseBindSubquery path. Subquery conditions are detected after binding, flattened via flattenSubqueries, and wrapped in a FILTER above the join (same flow as bindWhere). No binder swapping needed — TableBinder correctly handles aggregates and windows for JOIN ON context. Co-Authored-By: Claude <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
I think this still needs changes.
-
JOIN ... ONsubqueries are accepted by the binder now, but the join path still does not lower them into an executable form.buildTable()stores the bound ON predicates directly innode.OnList, and unlike WHERE / HAVING / projection paths there is still noflattenSubqueries()step for join predicates. Constant folding also does not rescue this:rule.IsConstant()returns false forExpr_Sub, so the scalar subquery stays inside the ON expression. At compile time non-equi ON predicates are forwarded tocolexec.NewExpressionExecutor(extraJoinConditions()/constructLoopJoin()), andNewExpressionExecutorstill has noExpr_Subcase. So removing the NYI inTableBinder.BindSubquery()makes plan building pass, but the execution path is still incomplete. -
This change is broader than JOIN ON.
TableBinderis also used bybuildTableFunction()andbuildResultScan(). Those call sites still treat their arguments as plain expressions;result_scanin particular evaluates them throughGetReadonlyResultFromNoColumnExpression()->NewExpressionExecutor(), which still rejectsExpr_Sub. So this PR also starts accepting subqueries in non-JOINTableBindercallers that still do not support them.
The new unit test only exercises runOneStmt / plan construction, so it does not catch either runtime gap. I think the fix needs to be scoped to real JOIN-ON support end-to-end (including lowering/compile/runtime), or the old guard should stay in place until that support exists.
What type of PR is this?
Which issue(s) this PR fixes:
issue #24996
What this PR does / why we need it:
Scalar subqueries in JOIN ON conditions failed with NYI. Cherry-pick of #25339 to 4.1-dev.
TableBinder.BindSubquery now delegates to baseBindSubquery. Subquery conditions are flattened via flattenSubqueries and wrapped in FILTER above the join.
pkg/sql/plan/table_binder.gopkg/sql/plan/build_test.gotest/.../func_aggr_sum.resulttest/.../join/join.sql🤖 Generated with Claude Code