From c40e91192841a461ee4b6df5ba98cc5200e15dc4 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Tue, 5 Dec 2023 20:51:19 -0500 Subject: [PATCH] go/vt/vtgate: fix nilness issues (#14685) --- go/vt/vtgate/engine/vindex_lookup.go | 4 ---- go/vt/vtgate/evalengine/api_coerce.go | 2 +- go/vt/vtgate/planbuilder/operator_transformers.go | 6 ------ .../vtgate/planbuilder/operators/query_planning.go | 13 ++++--------- go/vt/vtgate/planbuilder/operators/vindex.go | 5 +---- 5 files changed, 6 insertions(+), 24 deletions(-) diff --git a/go/vt/vtgate/engine/vindex_lookup.go b/go/vt/vtgate/engine/vindex_lookup.go index aaf49feea95..8bf8755c40e 100644 --- a/go/vt/vtgate/engine/vindex_lookup.go +++ b/go/vt/vtgate/engine/vindex_lookup.go @@ -227,10 +227,6 @@ func (vr *VindexLookup) executeBatch(ctx context.Context, vcursor VCursor, ids [ } else { result, err = vcursor.ExecutePrimitive(ctx, vr.Lookup, bindVars, false) } - if err != nil { - return nil, err - } - if err != nil { return nil, vterrors.Wrapf(err, "failed while running the lookup query") } diff --git a/go/vt/vtgate/evalengine/api_coerce.go b/go/vt/vtgate/evalengine/api_coerce.go index 89b36458198..cbd1b145ca6 100644 --- a/go/vt/vtgate/evalengine/api_coerce.go +++ b/go/vt/vtgate/evalengine/api_coerce.go @@ -48,7 +48,7 @@ func CoerceTypes(v1, v2 Type) (out Type, err error) { switch { case sqltypes.IsTextOrBinary(v1.Type()) && sqltypes.IsTextOrBinary(v2.Type()): mergedCollation, _, _, ferr := mergeCollations(typedCoercionCollation(v1.Type(), v1.Collation()), typedCoercionCollation(v2.Type(), v2.Collation()), v1.Type(), v2.Type()) - if err != nil { + if ferr != nil { return Type{}, ferr } out.collation = mergedCollation.Collation diff --git a/go/vt/vtgate/planbuilder/operator_transformers.go b/go/vt/vtgate/planbuilder/operator_transformers.go index 3974a307e71..7d3eb05549a 100644 --- a/go/vt/vtgate/planbuilder/operator_transformers.go +++ b/go/vt/vtgate/planbuilder/operator_transformers.go @@ -251,9 +251,6 @@ func transformAggregator(ctx *plancontext.PlanningContext, op *operators.Aggrega }) } - if err != nil { - return nil, err - } oa.truncateColumnCount = op.ResultColumns return oa, nil } @@ -431,9 +428,6 @@ func routeToEngineRoute(ctx *plancontext.PlanningContext, op *operators.Route, h rp := newRoutingParams(ctx, op.Routing.OpCode()) op.Routing.UpdateRoutingParams(ctx, rp) - if err != nil { - return nil, err - } e := &engine.Route{ TableName: strings.Join(tableNames, ", "), diff --git a/go/vt/vtgate/planbuilder/operators/query_planning.go b/go/vt/vtgate/planbuilder/operators/query_planning.go index 0994ee4402a..38e4e4cd8c0 100644 --- a/go/vt/vtgate/planbuilder/operators/query_planning.go +++ b/go/vt/vtgate/planbuilder/operators/query_planning.go @@ -55,8 +55,8 @@ func planQuery(ctx *plancontext.PlanningContext, root Operator) (output Operator // If we can push it under a route - done. // If we can't, we will instead expand the Horizon into // smaller operators and try to push these down as far as possible -func runPhases(ctx *plancontext.PlanningContext, root Operator) (op Operator, err error) { - op = root +func runPhases(ctx *plancontext.PlanningContext, root Operator) (Operator, error) { + op := root p := phaser{} for phase := p.next(ctx); phase != DONE; phase = p.next(ctx) { @@ -66,19 +66,14 @@ func runPhases(ctx *plancontext.PlanningContext, root Operator) (op Operator, er } op = phase.act(ctx, op) - if err != nil { - return nil, err - } + var err error op, err = runRewriters(ctx, op) if err != nil { return nil, err } op = compact(ctx, op) - if err != nil { - return nil, err - } } return addGroupByOnRHSOfJoin(op), nil @@ -222,7 +217,7 @@ func pushProjectionToOuter(ctx *plancontext.PlanningContext, p *Projection, sq * return p, NoRewrite } - if !reachedPhase(ctx, subquerySettling) || err != nil { + if !reachedPhase(ctx, subquerySettling) { return p, NoRewrite } diff --git a/go/vt/vtgate/planbuilder/operators/vindex.go b/go/vt/vtgate/planbuilder/operators/vindex.go index f8667b45aba..0b49083785a 100644 --- a/go/vt/vtgate/planbuilder/operators/vindex.go +++ b/go/vt/vtgate/planbuilder/operators/vindex.go @@ -148,15 +148,12 @@ func (v *Vindex) AddPredicate(ctx *plancontext.PlanningContext, expr sqlparser.E } // check RHS - var err error if sqlparser.IsValue(comparison.Right) || sqlparser.IsSimpleTuple(comparison.Right) { v.Value = comparison.Right } else { panic(vterrors.VT09018(wrongWhereCond + " (rhs is not a value)")) } - if err != nil { - panic(vterrors.VT09018(wrongWhereCond+": %v", err)) - } + v.OpCode = engine.VindexMap v.Table.Predicates = append(v.Table.Predicates, e) }