Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vtgate planner] Routing & Merging refactor #12197

Merged
merged 37 commits into from
Feb 15, 2023
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f9561fa
start of extracting routing logic out from Route into an interface
systay Jan 27, 2023
f03b14c
wip - milestone - first plan-test green
systay Jan 31, 2023
b05601a
wip - single table routes work fine
systay Jan 31, 2023
383fa5c
wip - sequence tables passing
systay Jan 31, 2023
85fc461
wip - all tests in from_cases.json passing
systay Feb 1, 2023
dceb990
wip - more work on merge logic
systay Feb 3, 2023
1c88334
wip - need to switch the routes as well
systay Feb 9, 2023
dfdb741
subquery merging
harshit-gangal Feb 9, 2023
671a684
dual routing
harshit-gangal Feb 9, 2023
5917321
wip - make sure to keep inner/outer in the right place
systay Feb 9, 2023
a915603
make sure to not forget already seen predicates when merging sharded …
systay Feb 9, 2023
42593dd
add merged subqueries to the merged field
systay Feb 10, 2023
7526a00
dual subquery and none routing change
harshit-gangal Feb 10, 2023
a635fe8
handle merging subqueries on IN comparisons
systay Feb 10, 2023
138994f
recalculate routing after merging subquery
systay Feb 13, 2023
0572046
rename field to make it easier to grokk
systay Feb 13, 2023
24ec13c
better merging logic when merging non-sharded tables
systay Feb 13, 2023
b1179e5
when merging subqueries, we must also copy predicates
systay Feb 13, 2023
b148822
copy keyspace when producing NoneRouting
systay Feb 13, 2023
6934749
implement Routing methods in TargetedRouting and update OpCode outsid…
frouioui Feb 13, 2023
1ee4558
Fix targeted routing update params and rest of the dml cases
frouioui Feb 13, 2023
a4bac20
Enhanced UpdateRoutingLogic function to detect constant null and None…
frouioui Feb 13, 2023
60e651e
clean up info schema route mergeing
systay Feb 13, 2023
a964b0b
handle reference tables with alternates
systay Feb 13, 2023
8c59b70
update remaining plan_tests
systay Feb 13, 2023
7001f97
unify unsharded and reference routing in the same logic
systay Feb 13, 2023
c982062
clean up merging.go
systay Feb 13, 2023
52b98a4
build the alternate routes with the correct keyspace
systay Feb 14, 2023
c877106
minor fixes after self-review
systay Feb 14, 2023
04fd6f5
when missing current keyspace, any valid keyspace can be used
systay Feb 14, 2023
1cb7df0
final small changes. I promise
systay Feb 14, 2023
c764429
review feedback
systay Feb 14, 2023
ff8a713
tidy up method after review feedback
systay Feb 14, 2023
1352119
more cleanup - fix goland warnings in new files
systay Feb 14, 2023
7245a70
add keyspace information to sequence routing
systay Feb 15, 2023
19e024b
more cleanups from PR review
systay Feb 15, 2023
87e3812
more cleanup
systay Feb 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make sure to not forget already seen predicates when merging sharded …
…routes

Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Feb 14, 2023
commit a9156035ef4079e0bbfb23f3fde81677c041205b
35 changes: 18 additions & 17 deletions go/vt/vtgate/planbuilder/operators/merging.go
Original file line number Diff line number Diff line change
@@ -76,24 +76,24 @@ func (rt routingType) String() string {
// Merge checks whether two operators can be merged into a single one.
// If they can be merged, the new Routing for the merged operator is returned.
// If they cannot be merged, nil is returned.
func Merge(ctx *plancontext.PlanningContext, opA, opB ops.Operator, joinPredicates []sqlparser.Expr, m merger) (ops.Operator, error) {
routeA, routeB := operatorsToRoutes(opA, opB)
if routeA == nil || routeB == nil {
func Merge(ctx *plancontext.PlanningContext, lhs, rhs ops.Operator, joinPredicates []sqlparser.Expr, m merger) (ops.Operator, error) {
lhsRoute, rhsRoute := operatorsToRoutes(lhs, rhs)
if lhsRoute == nil || rhsRoute == nil {
return nil, nil
}

//
// if !sameKeyspace {
// if altARoute := routeA.AlternateInKeyspace(routeB.Keyspace); altARoute != nil {
// if altARoute := routeA.AlternateInKeyspace(rhsRoute.Keyspace); altARoute != nil {
// routeA = altARoute
// sameKeyspace = true
// } else if altBRoute := routeB.AlternateInKeyspace(routeA.Keyspace); altBRoute != nil {
// routeB = altBRoute
// } else if altBRoute := rhsRoute.AlternateInKeyspace(routeA.Keyspace); altBRoute != nil {
// rhsRoute = altBRoute
// sameKeyspace = true
// }
// }
routingA := routeA.Routing
routingB := routeB.Routing
routingA := lhsRoute.Routing
routingB := rhsRoute.Routing
sameKeyspace := routingA.Keyspace() == routingB.Keyspace()
a, b := getRoutingType(routingA), getRoutingType(routingB)
if getTypeName(routingA) < getTypeName(routingB) {
@@ -106,15 +106,15 @@ func Merge(ctx *plancontext.PlanningContext, opA, opB ops.Operator, joinPredicat

// if either side is a dual query, we can always merge them together
case a == dual:
return m.merge(routeA, routeB, routingB)
return m.merge(lhsRoute, rhsRoute, routingB)
case b == dual:
return m.merge(routeA, routeB, routingA)
return m.merge(lhsRoute, rhsRoute, routingA)

// an unsharded/reference route can be merged with anything going to that keyspace
case (a == unsharded || a == ref) && sameKeyspace:
return m.merge(routeA, routeB, routingB)
return m.merge(lhsRoute, rhsRoute, routingB)
case (b == unsharded || b == ref) && sameKeyspace:
return m.merge(routeA, routeB, routingA)
return m.merge(lhsRoute, rhsRoute, routingA)

case (a == unsharded || a == ref || b == unsharded || b == ref) && !sameKeyspace:
return nil, nil
@@ -123,11 +123,11 @@ func Merge(ctx *plancontext.PlanningContext, opA, opB ops.Operator, joinPredicat
return nil, nil

case a == sharded && b == sharded:
return mergeTables(ctx, routeA, routeB, m, joinPredicates)
return mergeTables(ctx, lhsRoute, rhsRoute, m, joinPredicates)

// table and reference routing can be merged if they are going to the same keyspace
case a == sharded && b == ref && sameKeyspace:
return m.merge(routeA, routeB, routingA)
return m.merge(lhsRoute, rhsRoute, routingA)

// info schema routings are hard to merge with anything else
case a == infoSchema || b == infoSchema:
@@ -215,9 +215,10 @@ func newJoinMerge(ctx *plancontext.PlanningContext, predicates []sqlparser.Expr,

func (jm *joinMerger) mergeTables(r1, r2 *ShardedRouting, op1, op2 *Route) (ops.Operator, error) {
tr := &ShardedRouting{
VindexPreds: append(r1.VindexPreds, r2.VindexPreds...),
keyspace: r1.keyspace,
RouteOpCode: r1.RouteOpCode,
VindexPreds: append(r1.VindexPreds, r2.VindexPreds...),
keyspace: r1.keyspace,
RouteOpCode: r1.RouteOpCode,
SeenPredicates: r1.SeenPredicates,
}
if r1.SelectedVindex() == r2.SelectedVindex() {
tr.Selected = r1.Selected
Original file line number Diff line number Diff line change
@@ -520,10 +520,10 @@ func (tr *ShardedRouting) resetRoutingSelections(ctx *plancontext.PlanningContex
tr.VindexPreds[i] = &VindexPlusPredicates{ColVindex: vp.ColVindex, TableID: vp.TableID}
}

var routing Routing
var routing Routing = tr
for _, predicate := range tr.SeenPredicates {
var err error
routing, err = tr.UpdateRoutingLogic(ctx, predicate)
routing, err = routing.UpdateRoutingLogic(ctx, predicate)
if err != nil {
return err
}