vtgate: merge empty reference branches through rewritten copies - #20756
Draft
GrahamCampbell wants to merge 5 commits into
Draft
vtgate: merge empty reference branches through rewritten copies#20756GrahamCampbell wants to merge 5 commits into
GrahamCampbell wants to merge 5 commits into
Conversation
…kip them Signed-off-by: Graham Campbell <hello@gjcampbell.co.uk>
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
|
GrahamCampbell
force-pushed
the
union-none-reference-rewrite
branch
from
July 29, 2026 19:44
3a8062c to
fe1b8f8
Compare
Signed-off-by: Graham Campbell <hello@gjcampbell.co.uk>
… agree Signed-off-by: Graham Campbell <hello@gjcampbell.co.uk>
Signed-off-by: Graham Campbell <hello@gjcampbell.co.uk>
Signed-off-by: Graham Campbell <hello@gjcampbell.co.uk>
GrahamCampbell
force-pushed
the
union-none-reference-rewrite
branch
from
July 29, 2026 22:42
fe1b8f8 to
65f76b7
Compare
This was referenced Jul 29, 2026
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
Statically empty reference branches used to merge blindly on main:
select id from source_of_ref where id in (null) union select id from userplanned SQL that namedsource_of_refon user shards, where the table is physicallyref_with_source, and failed at runtime with an unknown-table error. #20629 made those pairings decline instead, which is correct but plans a Concatenate where a single route used to suffice.This change restores the merge, correctly. When the none side's keyspace does not match the other side's, every real table under the empty branch is resolved to its reference copy in the target keyspace — the table itself, a
ReferencedBycopy, or a reference source — through the same lookup that builds alternate routes, so routing rules stay in effect and a copy that a rule sends elsewhere does not count. The branch's planned operators are then pointed at those copies in place with the original names kept as aliases, and the union merges into the other side's routing. The rewrite mechanism comes from #20755, which fixes the panic in the live-branch equivalent of this merge.Three planner cases pin the restored merges: the same-name copy, the differing physical name (now rewritten where main used to emit the broken name), and the reversed order. Branches whose tables have no copy in the target keyspace keep planning as separate routes, pinned by the existing cross-keyspace cases, and the information_schema guard from #20629 still precedes the rewrite.
Related Issue(s)
Closes #20754 together with #20755. Builds on #20628, #20629, #20630, and #20755.
Checklist
Deployment Notes
Unions with a statically empty reference-table branch and a branch in a keyspace holding a copy of its tables now plan as a single merged route using the copy's physical name. 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