Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dbnode] Optimize index.Aggregate() for FieldQuery #1628

Merged
merged 3 commits into from
May 13, 2019

Conversation

prateek
Copy link
Collaborator

@prateek prateek commented May 11, 2019

Resolves #1620

@prateek prateek force-pushed the prateek/dbnode/issue-1620 branch from 67887be to 61e5e62 Compare May 11, 2019 22:03
@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1628     +/-   ##
========================================
+ Coverage    71.9%     72%   +<.1%     
========================================
  Files         954     954             
  Lines       79177   79188     +11     
========================================
+ Hits        56993   57038     +45     
+ Misses      18467   18431     -36     
- Partials     3717    3719      +2
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.7% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80% <88.8%> (+0.1%) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74% <71.4%> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.7% <ø> (ø) ⬆️
#query 67.1% <100%> (ø) ⬆️
#x 87.1% <ø> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fefee8...61e5e62. Read the comment docs.

9 similar comments
@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1628     +/-   ##
========================================
+ Coverage    71.9%     72%   +<.1%     
========================================
  Files         954     954             
  Lines       79177   79188     +11     
========================================
+ Hits        56993   57038     +45     
+ Misses      18467   18431     -36     
- Partials     3717    3719      +2
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.7% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80% <88.8%> (+0.1%) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74% <71.4%> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.7% <ø> (ø) ⬆️
#query 67.1% <100%> (ø) ⬆️
#x 87.1% <ø> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fefee8...61e5e62. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1628     +/-   ##
========================================
+ Coverage    71.9%     72%   +<.1%     
========================================
  Files         954     954             
  Lines       79177   79188     +11     
========================================
+ Hits        56993   57038     +45     
+ Misses      18467   18431     -36     
- Partials     3717    3719      +2
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.7% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80% <88.8%> (+0.1%) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74% <71.4%> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.7% <ø> (ø) ⬆️
#query 67.1% <100%> (ø) ⬆️
#x 87.1% <ø> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fefee8...61e5e62. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1628     +/-   ##
========================================
+ Coverage    71.9%     72%   +<.1%     
========================================
  Files         954     954             
  Lines       79177   79188     +11     
========================================
+ Hits        56993   57038     +45     
+ Misses      18467   18431     -36     
- Partials     3717    3719      +2
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.7% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80% <88.8%> (+0.1%) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74% <71.4%> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.7% <ø> (ø) ⬆️
#query 67.1% <100%> (ø) ⬆️
#x 87.1% <ø> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fefee8...61e5e62. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1628     +/-   ##
========================================
+ Coverage    71.9%     72%   +<.1%     
========================================
  Files         954     954             
  Lines       79177   79188     +11     
========================================
+ Hits        56993   57038     +45     
+ Misses      18467   18431     -36     
- Partials     3717    3719      +2
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.7% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80% <88.8%> (+0.1%) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74% <71.4%> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.7% <ø> (ø) ⬆️
#query 67.1% <100%> (ø) ⬆️
#x 87.1% <ø> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fefee8...61e5e62. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1628     +/-   ##
========================================
+ Coverage    71.9%     72%   +<.1%     
========================================
  Files         954     954             
  Lines       79177   79188     +11     
========================================
+ Hits        56993   57038     +45     
+ Misses      18467   18431     -36     
- Partials     3717    3719      +2
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.7% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80% <88.8%> (+0.1%) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74% <71.4%> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.7% <ø> (ø) ⬆️
#query 67.1% <100%> (ø) ⬆️
#x 87.1% <ø> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fefee8...61e5e62. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1628     +/-   ##
========================================
+ Coverage    71.9%     72%   +<.1%     
========================================
  Files         954     954             
  Lines       79177   79188     +11     
========================================
+ Hits        56993   57038     +45     
+ Misses      18467   18431     -36     
- Partials     3717    3719      +2
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.7% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80% <88.8%> (+0.1%) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74% <71.4%> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.7% <ø> (ø) ⬆️
#query 67.1% <100%> (ø) ⬆️
#x 87.1% <ø> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fefee8...61e5e62. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1628     +/-   ##
========================================
+ Coverage    71.9%     72%   +<.1%     
========================================
  Files         954     954             
  Lines       79177   79188     +11     
========================================
+ Hits        56993   57038     +45     
+ Misses      18467   18431     -36     
- Partials     3717    3719      +2
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.7% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80% <88.8%> (+0.1%) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74% <71.4%> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.7% <ø> (ø) ⬆️
#query 67.1% <100%> (ø) ⬆️
#x 87.1% <ø> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fefee8...61e5e62. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1628     +/-   ##
========================================
+ Coverage    71.9%     72%   +<.1%     
========================================
  Files         954     954             
  Lines       79177   79188     +11     
========================================
+ Hits        56993   57038     +45     
+ Misses      18467   18431     -36     
- Partials     3717    3719      +2
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.7% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80% <88.8%> (+0.1%) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74% <71.4%> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.7% <ø> (ø) ⬆️
#query 67.1% <100%> (ø) ⬆️
#x 87.1% <ø> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fefee8...61e5e62. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1628     +/-   ##
========================================
+ Coverage    71.9%     72%   +<.1%     
========================================
  Files         954     954             
  Lines       79177   79188     +11     
========================================
+ Hits        56993   57038     +45     
+ Misses      18467   18431     -36     
- Partials     3717    3719      +2
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.7% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80% <88.8%> (+0.1%) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74% <71.4%> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.7% <ø> (ø) ⬆️
#query 67.1% <100%> (ø) ⬆️
#x 87.1% <ø> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fefee8...61e5e62. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #1628 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1628   +/-   ##
======================================
  Coverage    71.9%   71.9%           
======================================
  Files         954     954           
  Lines       79182   79182           
======================================
  Hits        56995   56995           
  Misses      18464   18464           
  Partials     3723    3723
Flag Coverage Δ
#aggregator 82.3% <0%> (ø) ⬆️
#cluster 85.7% <0%> (ø) ⬆️
#collector 63.7% <0%> (ø) ⬆️
#dbnode 79.8% <0%> (ø) ⬆️
#m3em 73.2% <0%> (ø) ⬆️
#m3ninx 73.9% <0%> (ø) ⬆️
#m3nsch 51.1% <0%> (ø) ⬆️
#metrics 17.6% <0%> (ø) ⬆️
#msg 74.9% <0%> (ø) ⬆️
#query 67.1% <0%> (ø) ⬆️
#x 87.1% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 150c1f6...e656c56. Read the comment docs.

@@ -894,6 +895,10 @@ func (b *block) Aggregate(
}

aggOpts := results.AggregateResultsOptions()
// ensure we iterate the provided filter fields in order.
sort.Slice(aggOpts.FieldFilter, func(i, j int) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this cause a data race since block.Aggregate(...) happens in parallel across blocks?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed by moving the sort up into index.go:Aggregate() before we call into the blocks.

field, isField := idx.FieldQuery(query.Query)
if isField {
fn = i.execBlockAggregateQueryFn
aopts.FieldFilter = append(index.AggregateFieldFilter{field}, aopts.FieldFilter...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm only question here, is for the default query coming from query engine - don't we set both the FieldFilter and the TagMatcher turns into a FieldQuery?

If so, would we add the same field twice to the field filter? Would that mean iterating that field twice instead of once? After reading the field iterator code it wasn't clear, also I'd need to trace the query engine code again, but I though it both sent a tag matcher that is a FieldQuery and might also set the FieldFilter too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, seems like it does (from tag_values.go):

	return &storage.CompleteTagsQuery{
		// NB: necessarily spans the entire timerange for the index.
		Start:            time.Time{},
		End:              h.nowFn(),
		CompleteNameOnly: false,
		FilterNameTags:   [][]byte{nameBytes},
		TagMatchers: models.Matchers{
			models.Matcher{
				Type:  models.MatchRegexp,
				Name:  nameBytes,
				Value: matchValues,
			},
		},
	}, nil

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - it would have been a duplicate iteration. Wouldn't have affected correctness but it's redundant.

Made the change to only add the field filter if it doesn't exist in the list already, and further to de-dupe the filters to avoid this if users do something silly too.

@robskillington
Copy link
Collaborator

Awesome, thanks this is great! Let me know what you think about my comments, not 100% sure they are all correct hah but did the best I could to think through it.

@prateek
Copy link
Collaborator Author

prateek commented May 12, 2019

@robskillington ta, cheers! Addressed feedback.

@prateek prateek force-pushed the prateek/dbnode/issue-1620 branch from e331ae0 to 8927592 Compare May 12, 2019 20:49
Copy link
Collaborator

@robskillington robskillington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@robskillington robskillington merged commit e87ea75 into master May 13, 2019
@robskillington robskillington deleted the prateek/dbnode/issue-1620 branch May 13, 2019 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Queries for aggregate values from a single large field is slow
2 participants