vtgate: expand qualified stars without JOIN USING coalescing - #20759
Open
GrahamCampbell wants to merge 1 commit into
Open
vtgate: expand qualified stars without JOIN USING coalescing#20759GrahamCampbell wants to merge 1 commit into
GrahamCampbell wants to merge 1 commit into
Conversation
Signed-off-by: Graham Campbell <hello@gjcampbell.co.uk>
GrahamCampbell
requested review from
arthurschreiber,
frouioui,
harshit-gangal and
systay
as code owners
July 29, 2026 21:47
Contributor
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
5 tasks
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
The early rewriter applies JOIN USING coalescing to qualified stars. MySQL coalesces the join columns for an unqualified
*only:tbl.*returns every column of the named table, join columns included, soselect r.* from t l join t r using (col1)returns three columns on MySQL but two on Vitess, silently droppingr.col1from the results. The right-hand side of the join loses its join columns; the left-hand side keeps them, so the wrong shape only shows on one side.The fix clears the coalescing state when the star carries a qualifier, before the expander runs. Unqualified stars keep the existing coalesced expansion and ordering unchanged, pinned by the existing cases. Four new expansion cases cover both join sides, a mixed qualified pair, and a second table shape, and a planner golden pins the emitted SQL end to end; that file runs in the plan e2e suite, so CI compares the corrected expansion against MySQL directly.
This came out of reviewing #20633, whose declared-column-list validation turns the wrong expansion into a spurious VT03033 for
select a from (select r.* from t l join t r using (col1)) x(a, b, c). The validation change now stacks on this fix. Since the wrong column set is returned to clients on current releases, this is probably worth backporting.Related Issue(s)
Found while addressing review feedback on #20633.
Checklist
Deployment Notes
Qualified stars in queries with JOIN USING now expand to every column of the named table, matching MySQL: previously the join columns were omitted from the right-hand table's
tbl.*expansion, and results silently differed from MySQL. No migrations or configuration changes.AI Disclosure
This PR was written primarily by Fable.
graph LR subgraph json [JSON support] direction TB PR20625["#20625 (merged)<br>mysql/json: fix MarshalTo discarding accumulated output for nested blob and bit values"] PR20632["#20632<br>vtgate: preserve IN value lists in complex aggregate projections"] PRA["#20691<br>evalengine: disable the static IN hash table for JSON operands"] PR20682["#20682 (draft)<br>evalengine: support constant-folded JSON values as literals"] PR20683["#20683 (draft)<br>evalengine, sqlparser: MySQL comparison domains; nested BETWEEN parentheses"] PR20626["#20626 (draft)<br>vtgate: support cross-shard JSON_ARRAYAGG and JSON_OBJECTAGG"] PR20625 --> PR20682 PRA --> PR20682 PR20682 --> PR20683 PR20632 --> PR20626 PR20683 --> PR20626 end subgraph union [Union routing] direction TB PR20628["#20628<br>vtgate: track per-source copies of pushed join predicates so merges skip them"] PR20629["#20629<br>vtgate: fix None routing handling when merging unions"] PR20630["#20630 (draft)<br>vtgate: merge unions on join-predicate-free routings when all sources agree"] PR20755["#20755<br>vtgate: fix union merging through reference-table alternates"] PR20756["#20756 (draft)<br>vtgate: merge empty reference branches through rewritten copies"] PR20628 --> PR20630 PR20629 --> PR20630 PR20630 --> PR20756 PR20755 --> PR20756 end subgraph cte [Recursive CTEs] direction TB PR20759["#20759<br>vtgate: expand qualified stars without JOIN USING coalescing"] PR20633["#20633 (draft)<br>vtgate: validate the declared column list length of CTEs and derived tables"] PR20631["#20631 (draft)<br>vtgate: bind recursive CTE column filters as arguments in unmerged term queries"] PR20759 --> PR20633 PR20633 --> PR20631 end json ~~~ union ~~~ cte