Skip to content

[release-23.0] planbuilder: fix subquery arg name collision across pullout opcodes (#19781)#19864

Open
vitess-bot[bot] wants to merge 2 commits into
release-23.0from
backport-19781-to-release-23.0
Open

[release-23.0] planbuilder: fix subquery arg name collision across pullout opcodes (#19781)#19864
vitess-bot[bot] wants to merge 2 commits into
release-23.0from
backport-19781-to-release-23.0

Conversation

@vitess-bot
Copy link
Copy Markdown
Contributor

@vitess-bot vitess-bot Bot commented Apr 14, 2026

Description

This is a backport of #19781

Copilot AI review requested due to automatic review settings April 14, 2026 19:08
@vitess-bot
Copy link
Copy Markdown
Contributor Author

vitess-bot Bot commented Apr 14, 2026

Hello @arthurschreiber, there are conflicts in this backport.

Please address them in order to merge this Pull Request. You can execute the snippet below to reset your branch and resolve the conflict manually.

Make sure you replace origin by the name of the vitessio/vitess remote

git fetch --all
gh pr checkout 19864
git reset --hard origin/release-23.0
git cherry-pick -m 1 67a0d78ec3175c57823cc9a79c7052cfe37bc9c9

@vitess-bot vitess-bot Bot review requested due to automatic review settings April 14, 2026 19:08
@github-actions github-actions Bot added this to the v23.0.4 milestone Apr 14, 2026
Copilot AI review requested due to automatic review settings April 16, 2026 08:46
@arthurschreiber arthurschreiber removed Skip CI Skip CI actions from running Merge Conflict labels Apr 16, 2026
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
@arthurschreiber arthurschreiber force-pushed the backport-19781-to-release-23.0 branch from 1f2d9a4 to 8d92abf Compare April 16, 2026 08:47
@arthurschreiber arthurschreiber marked this pull request as ready for review April 16, 2026 08:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Backports a fix to prevent bind variable name collisions when the same subquery text appears in different pullout contexts (e.g., scalar value vs IN), ensuring each subquery occurrence gets its own reserved bind variable name and correct type.

Changes:

  • Reserve a fresh bind variable name per subquery occurrence via ReserveSubQuery() (instead of caching via GetReservedArgumentFor).
  • Track merged subqueries by arg name (map[string]*sqlparser.Subquery) to decouple merging logic from the reserved-argument cache.
  • Update/add planbuilder golden test cases to assert distinct bind var names for duplicate/volatile subqueries and mixed scalar/IN scenarios.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
go/vt/vtgate/planbuilder/testdata/select_cases.json Updates projection subquery pullout expectations; adds volatile uuid() subquery case asserting non-coalescing.
go/vt/vtgate/planbuilder/testdata/filter_cases.json Adds WHERE-case asserting distinct arg names for same subquery used in scalar comparison and IN.
go/vt/vtgate/planbuilder/testdata/dml_cases.json Adds UPDATE-case asserting distinct arg names for same subquery used in scalar SET and IN SET.
go/vt/vtgate/planbuilder/testdata/onecase.json Normalizes file formatting (trailing newline).
go/vt/vtgate/planbuilder/plancontext/planning_context.go Changes MergedSubqueries to a map keyed by arg name; removes subquery case from GetReservedArgumentFor.
go/vt/vtgate/planbuilder/operators/subquery_planning.go Reworks merged-subquery rewrite/settling logic to use the arg-name-keyed map.
go/vt/vtgate/planbuilder/operators/subquery_builder.go Ensures each subquery occurrence gets a unique reserved name; replaces old extraction/dedup flow with a single AST walk.
go/vt/vtgate/planbuilder/operators/subquery.go Updates merged check to use MergedSubqueries map keyed by arg name.

@mattlord mattlord mentioned this pull request May 4, 2026
34 tasks
@mattlord mattlord modified the milestones: v23.0.4, v23.0.5 May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants