Skip to content

Commit

Permalink
fix: check for operator type before route to know a complex plan and …
Browse files Browse the repository at this point in the history
…fail accordingly

Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Oct 25, 2024
1 parent 7eaba8d commit e26e54a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions go/vt/vtgate/planbuilder/operators/plan_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"
"vitess.io/vitess/go/vt/vtgate/semantics"
)

type (
Expand Down Expand Up @@ -73,13 +74,28 @@ func PlanQuery(ctx *plancontext.PlanningContext, stmt sqlparser.Statement) (resu
checkValid(op)
op = planQuery(ctx, op)

_, isRoute := op.(*Route)
if !isRoute && ctx.SemTable.NotSingleRouteErr != nil {
// If we got here, we don't have a single shard plan
return nil, ctx.SemTable.NotSingleRouteErr
err = shouldErrorOnComplexPlan(ctx, op)
return op, err
}

func shouldErrorOnComplexPlan(ctx *plancontext.PlanningContext, op Operator) error {
complexPlan := false
visitF := func(op Operator, _ semantics.TableSet, _ bool) (Operator, *ApplyResult) {
switch op.(type) {
case *Limit, *Route:
default:
complexPlan = true
}
return op, NoRewrite
}

return op, err
TopDown(op, TableID, visitF, stopAtRoute)

if complexPlan && ctx.SemTable.NotSingleRouteErr != nil {
// If we got here, we don't have a single shard plan
return ctx.SemTable.NotSingleRouteErr
}
return nil
}

func PanicHandler(err *error) {
Expand Down

0 comments on commit e26e54a

Please sign in to comment.