From 26326ac74c47bd7f78f586c3844d83a93060983d Mon Sep 17 00:00:00 2001 From: Seebs Date: Wed, 20 Nov 2019 16:10:51 -0600 Subject: [PATCH] recompute shards for cross-index queries When computing results on another index, recompute list of shards for that index. --- executor.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/executor.go b/executor.go index 31caaf7e7..0e70de6f0 100644 --- a/executor.go +++ b/executor.go @@ -427,7 +427,7 @@ func (e *executor) execute(ctx context.Context, index string, q *pql.Query, shar // already precomputed by handlePreCallChildren, though, // we don't need this logic in executeCall. if newIndex := call.CallIndex(); newIndex != "" { - v, err = e.executeCall(ctx, newIndex, call, shards, opt) + v, err = e.executeCall(ctx, newIndex, call, nil, opt) } else { v, err = e.executeCall(ctx, index, call, shards, opt) } @@ -458,6 +458,20 @@ func (e *executor) executeCall(ctx context.Context, index string, c *pql.Call, s e.Holder.Logger.Printf("DEPRECATED: Range() is deprecated, please use Row() instead.") } + // If shards are specified, then use that value for shards. If shards aren't + // specified, then include all of them. + if shards == nil && needsShards([]*pql.Call{c}) { + // Round up the number of shards. + idx := e.Holder.Index(index) + if idx == nil { + return nil, ErrIndexNotFound + } + shards = idx.AvailableShards().Slice() + if len(shards) == 0 { + shards = []uint64{0} + } + } + // Special handling for mutation and top-n calls. if op, ok := e.additionalCountOps[c.Name]; ok { e.Holder.Stats.CountWithCustomTags(c.Name, 1, 1.0, []string{indexTag})