From 8d193a3e56d040c474fa78a5d06fa927633101a6 Mon Sep 17 00:00:00 2001 From: Jiquan Long Date: Tue, 27 Jun 2023 19:22:45 +0800 Subject: [PATCH] Skip unnecessary reduce phase during search (#25166) Signed-off-by: longjiquan --- internal/querynodev2/delegator/delegator.go | 4 ++-- internal/querynodev2/segments/result.go | 8 +++++++ tests/integration/jsonexpr/json_expr_test.go | 24 +++++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/internal/querynodev2/delegator/delegator.go b/internal/querynodev2/delegator/delegator.go index 80c519f1b6..58569212a1 100644 --- a/internal/querynodev2/delegator/delegator.go +++ b/internal/querynodev2/delegator/delegator.go @@ -253,7 +253,7 @@ func (sd *shardDelegator) Search(ctx context.Context, req *querypb.SearchRequest return nil, err } - log.Info("Delegator search done") + log.Debug("Delegator search done") return results, nil } @@ -484,7 +484,7 @@ func (sd *shardDelegator) waitTSafe(ctx context.Context, ts uint64) error { lag := gt.Sub(st) maxLag := paramtable.Get().QueryNodeCfg.MaxTimestampLag.GetAsDuration(time.Second) if lag > maxLag { - log.Warn("guarantee and servicable ts larger than MaxLag", + log.Warn("guarantee and serviceable ts larger than MaxLag", zap.Time("guaranteeTime", gt), zap.Time("serviceableTime", st), zap.Duration("lag", lag), diff --git a/internal/querynodev2/segments/result.go b/internal/querynodev2/segments/result.go index 8a4fa1450c..bc55071020 100644 --- a/internal/querynodev2/segments/result.go +++ b/internal/querynodev2/segments/result.go @@ -40,6 +40,14 @@ var _ typeutil.ResultWithID = &internalpb.RetrieveResults{} var _ typeutil.ResultWithID = &segcorepb.RetrieveResults{} func ReduceSearchResults(ctx context.Context, results []*internalpb.SearchResults, nq int64, topk int64, metricType string) (*internalpb.SearchResults, error) { + results = lo.Filter(results, func(result *internalpb.SearchResults, _ int) bool { + return result != nil && result.GetSlicedBlob() != nil + }) + + if len(results) == 1 { + return results[0], nil + } + log := log.Ctx(ctx) searchResultData, err := DecodeSearchResults(results) diff --git a/tests/integration/jsonexpr/json_expr_test.go b/tests/integration/jsonexpr/json_expr_test.go index db973da499..edacac9f10 100644 --- a/tests/integration/jsonexpr/json_expr_test.go +++ b/tests/integration/jsonexpr/json_expr_test.go @@ -207,7 +207,9 @@ func (s *JSONExprSuite) TestJSON_InsertWithoutDynamicData() { // search expr = `$meta["A"] > 90` checkFunc := func(result *milvuspb.SearchResults) { - s.Equal(0, len(result.Results.FieldsData)) + for _, f := range result.Results.GetFieldsData() { + s.Nil(f) + } } s.doSearch(collectionName, []string{common.MetaFieldName}, expr, dim, checkFunc) log.Info("GT expression run successfully") @@ -563,7 +565,9 @@ func (s *JSONExprSuite) checkSearch(collectionName, fieldName string, dim int) { expr = `exists AAA` checkFunc = func(result *milvuspb.SearchResults) { - s.Equal(0, len(result.Results.FieldsData)) + for _, f := range result.Results.GetFieldsData() { + s.Nil(f) + } } s.doSearch(collectionName, []string{fieldName}, expr, dim, checkFunc) log.Info("EXISTS expression run successfully") @@ -610,7 +614,9 @@ func (s *JSONExprSuite) checkSearch(collectionName, fieldName string, dim int) { expr = `A like "10"` checkFunc = func(result *milvuspb.SearchResults) { - s.Equal(0, len(result.Results.FieldsData)) + for _, f := range result.Results.GetFieldsData() { + s.Nil(f) + } } s.doSearch(collectionName, []string{fieldName}, expr, dim, checkFunc) log.Info("like expression run successfully") @@ -627,14 +633,18 @@ func (s *JSONExprSuite) checkSearch(collectionName, fieldName string, dim int) { expr = `str1 like 'abc"def-%'` checkFunc = func(result *milvuspb.SearchResults) { - s.Equal(0, len(result.Results.FieldsData)) + for _, f := range result.Results.GetFieldsData() { + s.Nil(f) + } } s.doSearch(collectionName, []string{fieldName}, expr, dim, checkFunc) log.Info("like expression run successfully") expr = `str2 like 'abc\"def-%'` checkFunc = func(result *milvuspb.SearchResults) { - s.Equal(0, len(result.Results.FieldsData)) + for _, f := range result.Results.GetFieldsData() { + s.Nil(f) + } } s.doSearch(collectionName, []string{fieldName}, expr, dim, checkFunc) log.Info("like expression run successfully") @@ -651,7 +661,9 @@ func (s *JSONExprSuite) checkSearch(collectionName, fieldName string, dim int) { expr = `A in []` checkFunc = func(result *milvuspb.SearchResults) { - s.Equal(0, len(result.Results.FieldsData)) + for _, f := range result.Results.GetFieldsData() { + s.Nil(f) + } } s.doSearch(collectionName, []string{fieldName}, expr, dim, checkFunc) log.Info("term empty expression run successfully")