{"action":"created","comment":{"url":"https://api.github.com/repos/m3db/m3/pulls/comments/223096227","pull_request_review_id":162148327,"id":223096227,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyMzA5NjIyNw==","diff_hunk":"@@ -117,55 +143,79 @@ func (r *multiResult) Add(\n \t\treturn\n \t}\n \n+\tif len(r.seenIters) == 0 {\n+\t\t// store the first attributes seen\n+\t\tr.seenFirstAttrs = attrs\n+\t}\n \tr.seenIters = append(r.seenIters, iterators)\n \tif !r.err.Empty() {\n \t\t// don't need to do anything if the final result is going to be an error\n \t\treturn\n \t}\n-\n-\titers := iterators.Iters()\n-\tif r.dedupeMap == nil {\n-\t\tr.dedupeMap = make(map[string][]multiResultSeries, len(iters))\n+\tif len(r.seenIters) < 2 {\n+\t\t// don't need to build the de-dupe map until we need to actually need to dedupe\n+\t\treturn\n \t}\n \n-\tfor _, iter := range iters {\n-\t\tid := iter.ID().String()\n-\t\tr.dedupeMap[id] = append(r.dedupeMap[id], multiResultSeries{\n-\t\t\tattrs: attrs,\n-\t\t\titer:  iter,\n-\t\t})\n+\tif len(r.seenIters) == 2 {\n+\t\t// need to build backfill the dedupe map from the first result first\n+\t\texisting := r.seenIters[0]\n+\t\tr.dedupeMap = make(map[string]multiResultSeries, existing.Len())\n+\t\tfor _, iter := range existing.Iters() {\n+\t\t\tid := iter.ID().String()\n+\t\t\tr.dedupeMap[id] = multiResultSeries{\n+\t\t\t\tattrs: r.seenFirstAttrs,\n+\t\t\t\titer:  iter,\n+\t\t\t}\n+\t\t}\n \t}\n \n-\tr.dedupe()\n+\tr.dedupe(attrs, iterators)\n }\n \n-func (r *multiResult) dedupe() {\n-\tfor id, serieses := range r.dedupeMap {\n-\t\tif len(serieses) < 2 {\n-\t\t\tcontinue\n-\t\t}\n+func (r *multiResult) dedupe(\n+\tattrs storage.Attributes,\n+\titerators encoding.SeriesIterators,\n+) {\n+\tfor _, iter := range iterators.Iters() {\n+\t\tid := iter.ID().String()\n \n-\t\t// find max resolution\n-\t\tmaxIdx := 0\n-\t\tmaxValue := serieses[0].attrs\n-\t\tfor i := 1; i < len(serieses); i++ {\n-\t\t\tseries := serieses[i].attrs\n-\t\t\tif series.Resolution > maxValue.Resolution {\n-\t\t\t\tmaxIdx = i\n-\t\t\t\tmaxValue = series\n+\t\texisting, exists := r.dedupeMap[id]\n+\t\tif !exists {\n+\t\t\t// Does not exist, new addition\n+\t\t\tr.dedupeMap[id] = multiResultSeries{\n+\t\t\t\tattrs: attrs,\n+\t\t\t\titer:  iter,\n \t\t\t}\n+\t\t\tcontinue\n \t\t}\n \n-\t\tmaxSeries := serieses[maxIdx]\n-\n-\t\t// reset slice to reuse\n-\t\tfor idx := range serieses {\n-\t\t\tserieses[idx] = multiResultSeries{}\n+\t\tvar existsBetter bool\n+\t\tswitch r.fanout {\n+\t\tcase namespacesCoverAllRetention:","path":"src/query/storage/m3/multi_fetch_result.go","position":183,"original_position":183,"commit_id":"98a6f740ca371f7d600cc2c4a3ea9698f460a356","original_commit_id":"98a6f740ca371f7d600cc2c4a3ea9698f460a356","user":{"login":"richardartoul","id":9171254,"node_id":"MDQ6VXNlcjkxNzEyNTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/9171254?v=4","gravatar_id":"","url":"https://api.github.com/users/richardartoul","html_url":"https://github.com/richardartoul","followers_url":"https://api.github.com/users/richardartoul/followers","following_url":"https://api.github.com/users/richardartoul/following{/other_user}","gists_url":"https://api.github.com/users/richardartoul/gists{/gist_id}","starred_url":"https://api.github.com/users/richardartoul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richardartoul/subscriptions","organizations_url":"https://api.github.com/users/richardartoul/orgs","repos_url":"https://api.github.com/users/richardartoul/repos","events_url":"https://api.github.com/users/richardartoul/events{/privacy}","received_events_url":"https://api.github.com/users/richardartoul/received_events","type":"User","site_admin":false},"body":"is this more like `namespacesCoverQueryDuration`?","created_at":"2018-10-05T18:12:31Z","updated_at":"2018-10-05T18:12:31Z","html_url":"https://github.com/m3db/m3/pull/908#discussion_r223096227","pull_request_url":"https://api.github.com/repos/m3db/m3/pulls/908","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/m3db/m3/pulls/comments/223096227"},"html":{"href":"https://github.com/m3db/m3/pull/908#discussion_r223096227"},"pull_request":{"href":"https://api.github.com/repos/m3db/m3/pulls/908"}}},"pull_request":{"url":"https://api.github.com/repos/m3db/m3/pulls/908","id":215841403,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE1ODQxNDAz","html_url":"https://github.com/m3db/m3/pull/908","diff_url":"https://github.com/m3db/m3/pull/908.diff","patch_url":"https://github.com/m3db/m3/pull/908.patch","issue_url":"https://api.github.com/repos/m3db/m3/issues/908","number":908,"state":"open","locked":false,"title":"Add cluster namespace fanout heuristics supporting queries greater than retention","user":{"login":"robskillington","id":339615,"node_id":"MDQ6VXNlcjMzOTYxNQ==","avatar_url":"https://avatars1.githubusercontent.com/u/339615?v=4","gravatar_id":"","url":"https://api.github.com/users/robskillington","html_url":"https://github.com/robskillington","followers_url":"https://api.github.com/users/robskillington/followers","following_url":"https://api.github.com/users/robskillington/following{/other_user}","gists_url":"https://api.github.com/users/robskillington/gists{/gist_id}","starred_url":"https://api.github.com/users/robskillington/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robskillington/subscriptions","organizations_url":"https://api.github.com/users/robskillington/orgs","repos_url":"https://api.github.com/users/robskillington/repos","events_url":"https://api.github.com/users/robskillington/events{/privacy}","received_events_url":"https://api.github.com/users/robskillington/received_events","type":"User","site_admin":false},"body":"I need to add tests, however I want to get buy-in that this is meets our current needs before moving to writing extensive tests.\r\n\r\nThis fixes https://github.com/m3db/m3/issues/866.","created_at":"2018-09-16T19:43:10Z","updated_at":"2018-10-05T18:12:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"991ad4f0f331f52bd3d1749b49a21c897ee741bf","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/m3db/m3/pulls/908/commits","review_comments_url":"https://api.github.com/repos/m3db/m3/pulls/908/comments","review_comment_url":"https://api.github.com/repos/m3db/m3/pulls/comments{/number}","comments_url":"https://api.github.com/repos/m3db/m3/issues/908/comments","statuses_url":"https://api.github.com/repos/m3db/m3/statuses/98a6f740ca371f7d600cc2c4a3ea9698f460a356","head":{"label":"m3db:r/local-query-cluster-fanout-heuristics","ref":"r/local-query-cluster-fanout-heuristics","sha":"98a6f740ca371f7d600cc2c4a3ea9698f460a356","user":{"login":"m3db","id":19937171,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5OTM3MTcx","avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"repo":{"id":61153677,"node_id":"MDEwOlJlcG9zaXRvcnk2MTE1MzY3Nw==","name":"m3","full_name":"m3db/m3","private":false,"owner":{"login":"m3db","id":19937171,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5OTM3MTcx","avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/m3db/m3","description":"M3 monorepo - Distributed TSDB and Query Engine, Prometheus Sidecar, Metrics Platform","fork":false,"url":"https://api.github.com/repos/m3db/m3","forks_url":"https://api.github.com/repos/m3db/m3/forks","keys_url":"https://api.github.com/repos/m3db/m3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m3db/m3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m3db/m3/teams","hooks_url":"https://api.github.com/repos/m3db/m3/hooks","issue_events_url":"https://api.github.com/repos/m3db/m3/issues/events{/number}","events_url":"https://api.github.com/repos/m3db/m3/events","assignees_url":"https://api.github.com/repos/m3db/m3/assignees{/user}","branches_url":"https://api.github.com/repos/m3db/m3/branches{/branch}","tags_url":"https://api.github.com/repos/m3db/m3/tags","blobs_url":"https://api.github.com/repos/m3db/m3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m3db/m3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m3db/m3/git/refs{/sha}","trees_url":"https://api.github.com/repos/m3db/m3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m3db/m3/statuses/{sha}","languages_url":"https://api.github.com/repos/m3db/m3/languages","stargazers_url":"https://api.github.com/repos/m3db/m3/stargazers","contributors_url":"https://api.github.com/repos/m3db/m3/contributors","subscribers_url":"https://api.github.com/repos/m3db/m3/subscribers","subscription_url":"https://api.github.com/repos/m3db/m3/subscription","commits_url":"https://api.github.com/repos/m3db/m3/commits{/sha}","git_commits_url":"https://api.github.com/repos/m3db/m3/git/commits{/sha}","comments_url":"https://api.github.com/repos/m3db/m3/comments{/number}","issue_comment_url":"https://api.github.com/repos/m3db/m3/issues/comments{/number}","contents_url":"https://api.github.com/repos/m3db/m3/contents/{+path}","compare_url":"https://api.github.com/repos/m3db/m3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m3db/m3/merges","archive_url":"https://api.github.com/repos/m3db/m3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m3db/m3/downloads","issues_url":"https://api.github.com/repos/m3db/m3/issues{/number}","pulls_url":"https://api.github.com/repos/m3db/m3/pulls{/number}","milestones_url":"https://api.github.com/repos/m3db/m3/milestones{/number}","notifications_url":"https://api.github.com/repos/m3db/m3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m3db/m3/labels{/name}","releases_url":"https://api.github.com/repos/m3db/m3/releases{/id}","deployments_url":"https://api.github.com/repos/m3db/m3/deployments","created_at":"2016-06-14T20:29:45Z","updated_at":"2018-10-05T16:58:46Z","pushed_at":"2018-10-05T17:30:41Z","git_url":"git://github.com/m3db/m3.git","ssh_url":"git@github.com:m3db/m3.git","clone_url":"https://github.com/m3db/m3.git","svn_url":"https://github.com/m3db/m3","homepage":"https://m3db.io/","size":13359,"stargazers_count":1161,"watchers_count":1161,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":84,"mirror_url":null,"archived":false,"open_issues_count":158,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":84,"open_issues":158,"watchers":1161,"default_branch":"master"}},"base":{"label":"m3db:master","ref":"master","sha":"4f37073b2b0cd8cdb15ddb476fc55d9e37fabc0e","user":{"login":"m3db","id":19937171,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5OTM3MTcx","avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"repo":{"id":61153677,"node_id":"MDEwOlJlcG9zaXRvcnk2MTE1MzY3Nw==","name":"m3","full_name":"m3db/m3","private":false,"owner":{"login":"m3db","id":19937171,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5OTM3MTcx","avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/m3db/m3","description":"M3 monorepo - Distributed TSDB and Query Engine, Prometheus Sidecar, Metrics Platform","fork":false,"url":"https://api.github.com/repos/m3db/m3","forks_url":"https://api.github.com/repos/m3db/m3/forks","keys_url":"https://api.github.com/repos/m3db/m3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m3db/m3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m3db/m3/teams","hooks_url":"https://api.github.com/repos/m3db/m3/hooks","issue_events_url":"https://api.github.com/repos/m3db/m3/issues/events{/number}","events_url":"https://api.github.com/repos/m3db/m3/events","assignees_url":"https://api.github.com/repos/m3db/m3/assignees{/user}","branches_url":"https://api.github.com/repos/m3db/m3/branches{/branch}","tags_url":"https://api.github.com/repos/m3db/m3/tags","blobs_url":"https://api.github.com/repos/m3db/m3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m3db/m3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m3db/m3/git/refs{/sha}","trees_url":"https://api.github.com/repos/m3db/m3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m3db/m3/statuses/{sha}","languages_url":"https://api.github.com/repos/m3db/m3/languages","stargazers_url":"https://api.github.com/repos/m3db/m3/stargazers","contributors_url":"https://api.github.com/repos/m3db/m3/contributors","subscribers_url":"https://api.github.com/repos/m3db/m3/subscribers","subscription_url":"https://api.github.com/repos/m3db/m3/subscription","commits_url":"https://api.github.com/repos/m3db/m3/commits{/sha}","git_commits_url":"https://api.github.com/repos/m3db/m3/git/commits{/sha}","comments_url":"https://api.github.com/repos/m3db/m3/comments{/number}","issue_comment_url":"https://api.github.com/repos/m3db/m3/issues/comments{/number}","contents_url":"https://api.github.com/repos/m3db/m3/contents/{+path}","compare_url":"https://api.github.com/repos/m3db/m3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m3db/m3/merges","archive_url":"https://api.github.com/repos/m3db/m3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m3db/m3/downloads","issues_url":"https://api.github.com/repos/m3db/m3/issues{/number}","pulls_url":"https://api.github.com/repos/m3db/m3/pulls{/number}","milestones_url":"https://api.github.com/repos/m3db/m3/milestones{/number}","notifications_url":"https://api.github.com/repos/m3db/m3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m3db/m3/labels{/name}","releases_url":"https://api.github.com/repos/m3db/m3/releases{/id}","deployments_url":"https://api.github.com/repos/m3db/m3/deployments","created_at":"2016-06-14T20:29:45Z","updated_at":"2018-10-05T16:58:46Z","pushed_at":"2018-10-05T17:30:41Z","git_url":"git://github.com/m3db/m3.git","ssh_url":"git@github.com:m3db/m3.git","clone_url":"https://github.com/m3db/m3.git","svn_url":"https://github.com/m3db/m3","homepage":"https://m3db.io/","size":13359,"stargazers_count":1161,"watchers_count":1161,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":84,"mirror_url":null,"archived":false,"open_issues_count":158,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":84,"open_issues":158,"watchers":1161,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/m3db/m3/pulls/908"},"html":{"href":"https://github.com/m3db/m3/pull/908"},"issue":{"href":"https://api.github.com/repos/m3db/m3/issues/908"},"comments":{"href":"https://api.github.com/repos/m3db/m3/issues/908/comments"},"review_comments":{"href":"https://api.github.com/repos/m3db/m3/pulls/908/comments"},"review_comment":{"href":"https://api.github.com/repos/m3db/m3/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/m3db/m3/pulls/908/commits"},"statuses":{"href":"https://api.github.com/repos/m3db/m3/statuses/98a6f740ca371f7d600cc2c4a3ea9698f460a356"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"richardartoul"}}