Skip to content

[release-23.0] vtgate: fix None routing handling when merging unions (#20629) - #20940

Draft
vitess-bot[bot] wants to merge 1 commit into
release-23.0from
backport-20629-to-release-23.0
Draft

[release-23.0] vtgate: fix None routing handling when merging unions (#20629)#20940
vitess-bot[bot] wants to merge 1 commit into
release-23.0from
backport-20629-to-release-23.0

Conversation

@vitess-bot

@vitess-bot vitess-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Description

This is a backport of #20629

Copilot AI balanced review requested due to automatic review settings August 28, 2026 18:01
@vitess-bot vitess-bot Bot added Type: Bug Backport This is a backport Skip CI Skip CI actions from running Merge Conflict Component: VTGate labels Aug 28, 2026
@vitess-bot

vitess-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Hello @GrahamCampbell, 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 20940
git reset --hard origin/release-23.0
git cherry-pick -m 1 39bcd63d47db82a19fb998cfedfa766c7d841769

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Backports corrected NoneRouting handling when merging vtgate unions, preventing dropped rows and invalid cross-keyspace plans.

Changes:

  • Prioritizes NoneRouting pairings and tracks inferred keyspaces.
  • Adds table/keyspace validation for safe union merges.
  • Adds planner and end-to-end regression coverage.

Reviewed changes

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

Show a summary per file
File Description
union_cases.json Adds union planning fixtures.
dml_cases.json Adds targeted DML planning fixtures.
union_merging.go Implements safe None-route merging.
route.go Preserves inferred None routing state.
route_planning.go Adds keyspace accounting helpers.
route_planning_test.go Tests routing and keyspace accounting.
misc_routing.go Adds inferred-keyspace metadata.
union_test.go Adds execution regressions.
Suppressed comments (2)

go/vt/vtgate/planbuilder/operators/route_planning_test.go:310

  • This second vindexes.Source literal also tries to initialize the promoted Name field directly, which is not permitted for keyed literals on the release-23 type and causes a compile error. Initialize its embedded TableName.
					Source: &vindexes.Source{
						Name: sqlparser.NewIdentifierCS("src"),
					},

go/test/endtoend/vtgate/queries/union/union_test.go:94

  • These assertions cover behavior introduced by this release-23 backport, but the query suite also runs against older vtgate binaries and gates version-specific cases elsewhere in this file. Put these two assertions behind BinaryIsAtLeastAtVersion(23, "vtgate") so compatibility runs do not fail on binaries that predate the fix.
			mcmp.AssertMatches("select 1 from dual union select id1 from t1 where id1 in (null)", "[[INT64(1)]]")
			mcmp.AssertMatches("select id1 from t1 where id1 in (null) union select 1 from dual", "[[INT64(1)]]")

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

return join, Rewrote("logical join to applyJoin ")
}

<<<<<<< HEAD
Comment on lines +95 to +98
Source: &vindexes.Source{
Qualifier: sqlparser.NewIdentifierCS(sourceKs),
Name: sqlparser.NewIdentifierCS("src"),
},
Comment on lines +178 to +180
stmt, err := sqlparser.NewTestParser().Parse(
fmt.Sprintf("select /*vt+ %s */ 1", sqlparser.DirectiveAllowCrossKeyspaceReads),
)
mcmp.AssertMatchesNoOrder("select id1, id2 from t1 union select 827, 452 union select id3,id4 from t2",
"[[INT64(4) INT64(4)] [INT64(1) INT64(1)] [INT64(2) INT64(2)] [INT64(3) INT64(3)] [INT64(827) INT64(452)] [INT64(2) INT64(3)] [INT64(3) INT64(4)] [INT64(5) INT64(5)]]")
mcmp.AssertMatches("select 1 from dual where 1 IN (select 1 as col union select 2)", "[[INT64(1)]]")
<<<<<<< HEAD
if op, exprs, merged := tryMergeNoneUnion(ctx, lhsRoute, rhsRoute, lhsExprs, rhsExprs, distinct, routingA, routingB, a, b); merged {
return op, exprs
}
checkCrossKeyspaceOp(ctx, lhs, rhs, "UNION")
@mattlord mattlord mentioned this pull request Aug 29, 2026
33 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport This is a backport Component: VTGate Merge Conflict Skip CI Skip CI actions from running Type: Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant