[release-23.0] planbuilder: fix subquery arg name collision across pullout opcodes (#19781)#19864
Open
vitess-bot[bot] wants to merge 2 commits into
Open
[release-23.0] planbuilder: fix subquery arg name collision across pullout opcodes (#19781)#19864vitess-bot[bot] wants to merge 2 commits into
vitess-bot[bot] wants to merge 2 commits into
Conversation
Contributor
Author
|
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 |
arthurschreiber
approved these changes
Apr 16, 2026
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
1f2d9a4 to
8d92abf
Compare
Contributor
There was a problem hiding this comment.
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 viaGetReservedArgumentFor). - 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/
INscenarios.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This is a backport of #19781