Skip to content

Commit

Permalink
fix: route engine to handle column truncation for execute after lookup
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed Oct 16, 2024
1 parent da49d08 commit b315e30
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions go/vt/vtgate/engine/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b315e30

Please sign in to comment.