diff --git a/go/vt/vtgate/engine/route.go b/go/vt/vtgate/engine/route.go index 6c3ae572c8c..59682dd91fe 100644 --- a/go/vt/vtgate/engine/route.go +++ b/go/vt/vtgate/engine/route.go @@ -130,11 +130,12 @@ func (route *Route) GetTableName() string { // TryExecute performs a non-streaming exec. func (route *Route) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) { - qr, err := route.executeInternal(ctx, vcursor, bindVars, wantfields) + rss, bvs, err := route.findRoute(ctx, vcursor, bindVars) if err != nil { return nil, err } - return qr.Truncate(route.TruncateColumnCount), nil + + return route.executeShards(ctx, vcursor, bindVars, wantfields, rss, bvs) } type cxtKey int @@ -143,20 +144,6 @@ const ( IgnoreReserveTxn cxtKey = iota ) -func (route *Route) executeInternal( - ctx context.Context, - vcursor VCursor, - bindVars map[string]*querypb.BindVariable, - wantfields bool, -) (*sqltypes.Result, error) { - rss, bvs, err := route.findRoute(ctx, vcursor, bindVars) - if err != nil { - return nil, err - } - - return route.executeShards(ctx, vcursor, bindVars, wantfields, rss, bvs) -} - func (route *Route) executeShards( ctx context.Context, vcursor VCursor, @@ -212,11 +199,15 @@ func (route *Route) executeShards( } } - if len(route.OrderBy) == 0 { - return result, nil + if len(route.OrderBy) != 0 { + var err error + result, err = route.sort(result) + if err != nil { + return nil, err + } } - return route.sort(result) + return result.Truncate(route.TruncateColumnCount), nil } func filterOutNilErrors(errs []error) []error { @@ -373,10 +364,8 @@ func (route *Route) sort(in *sqltypes.Result) (*sqltypes.Result, error) { // the contents of any row. out := in.ShallowCopy() - if err := route.OrderBy.SortResult(out); err != nil { - return nil, err - } - return out.Truncate(route.TruncateColumnCount), nil + err := route.OrderBy.SortResult(out) + return out, err } func (route *Route) description() PrimitiveDescription {