Skip to content

Commit

Permalink
Return early if no data in segment. (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
notbdu committed Feb 20, 2019
1 parent 8ee3ce4 commit 739dd82
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions storage/immutable_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ func (s *immutableSeg) QueryRaw(
return nil
}

if s.NumDocuments() == 0 {
return nil
}

// Check if this segment has all orderBy fields as they are required, and bail early
// otherwise.
for _, ob := range q.OrderBy {
Expand Down Expand Up @@ -285,6 +289,10 @@ func (s *immutableSeg) QueryGrouped(
return nil
}

if s.NumDocuments() == 0 {
return nil
}

// Check if this segment has all groupBy fields as they are required, and bail early
// otherwise.
for _, gb := range q.GroupBy {
Expand Down Expand Up @@ -370,6 +378,10 @@ func (s *immutableSeg) QueryTimeBucket(
q query.ParsedTimeBucketQuery,
res *query.TimeBucketResults,
) error {
if s.NumDocuments() == 0 {
return nil
}

// Identify the set of fields needed for query execution.
allowedFieldTypes, fieldIndexMap, fieldsToRetrieve, err := s.collectFieldsForQuery(
q.NumFieldsForQuery(),
Expand Down
8 changes: 6 additions & 2 deletions storage/mutable_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ func (s *mutableSeg) QueryGrouped(
return nil, errMutableSegmentAlreadySealed
}

numDocuments := s.mutableSegmentBase.NumDocuments()
if numDocuments == 0 {
s.RUnlock()
return q.NewGroupedResults(), nil
}

allowedFieldTypes, fieldIndexMap, queryFields, err := s.collectFieldsForQueryWithLock(
q.NumFieldsForQuery(),
q.FieldConstraints,
Expand All @@ -278,8 +284,6 @@ func (s *mutableSeg) QueryGrouped(
s.RUnlock()
return nil, err
}

numDocuments := s.mutableSegmentBase.NumDocuments()
s.RUnlock()

defer func() {
Expand Down

0 comments on commit 739dd82

Please sign in to comment.