{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/212869567","pull_request_review_id":149585646,"id":212869567,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMjg2OTU2Nw==","diff_hunk":"@@ -468,13 +470,70 @@ func getOrdinalOfRangeCond(sc *stmtctx.StatementContext, ran *ranger.Range) int\n \treturn len(ran.LowVal)\n }\n \n-func (coll *HistColl) getIndexRowCount(sc *stmtctx.StatementContext, idx *Index, indexRanges []*ranger.Range, modifyCount int64) (float64, error) {\n+// GenerateHistCollFromColumnInfo generates a new HistColl whose ColID2IdxID and IdxID2ColIDs is built from the given parameter.\n+func (coll *HistColl) GenerateHistCollFromColumnInfo(infos []*model.ColumnInfo, columns []*expression.Column) HistColl {\n+\n+\tnewColHistMap := make(map[int64]*Column)\n+\tcolInfoID2UniqueID := make(map[int64]int64)\n+\tcolNames2UniqueID := make(map[string]int64)\n+\tfor _, col := range columns {\n+\t\tcolInfoID2UniqueID[col.ID] = col.UniqueID\n+\t}\n+\tfor _, colInfo := range infos {\n+\t\tuniqueID, ok := colInfoID2UniqueID[colInfo.ID]\n+\t\tif ok {\n+\t\t\tcolNames2UniqueID[colInfo.Name.L] = uniqueID\n+\t\t}\n+\t}\n+\tfor id, colHist := range coll.Columns {\n+\t\tuniqueID, ok := colInfoID2UniqueID[id]\n+\t\t// If this column is not in datasource's schema, it won't be used in this query.\n+\t\tif ok {\n+\t\t\tnewColHistMap[uniqueID] = colHist\n+\t\t}\n+\t}\n+\tnewIdxHistMap := make(map[int64]*Index)\n+\tidx2Columns := make(map[int64][]int64)\n+\tcolID2IdxID := make(map[int64]int64)\n+\tfor _, idxHist := range coll.Indices {\n+\t\tids := make([]int64, 0, len(idxHist.Info.Columns))\n+\t\tfor _, idxCol := range idxHist.Info.Columns {\n+\t\t\tuniqueID, ok := colNames2UniqueID[idxCol.Name.L]\n+\t\t\tif !ok {\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t\tids = append(ids, uniqueID)\n+\t\t}\n+\t\t// If the length of the id list is 0, this index won't be used in this query.\n+\t\tif len(ids) == 0 {\n+\t\t\tcontinue\n+\t\t}\n+\t\tcolID2IdxID[ids[0]] = idxHist.ID","path":"statistics/table.go","position":179,"original_position":179,"commit_id":"ba4b400d7c8d499826351c42f6c02f08014fbf83","original_commit_id":"ba4b400d7c8d499826351c42f6c02f08014fbf83","user":{"login":"winoros","id":7846227,"node_id":"MDQ6VXNlcjc4NDYyMjc=","avatar_url":"https://avatars1.githubusercontent.com/u/7846227?v=4","gravatar_id":"","url":"https://api.github.com/users/winoros","html_url":"https://github.com/winoros","followers_url":"https://api.github.com/users/winoros/followers","following_url":"https://api.github.com/users/winoros/following{/other_user}","gists_url":"https://api.github.com/users/winoros/gists{/gist_id}","starred_url":"https://api.github.com/users/winoros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/winoros/subscriptions","organizations_url":"https://api.github.com/users/winoros/orgs","repos_url":"https://api.github.com/users/winoros/repos","events_url":"https://api.github.com/users/winoros/events{/privacy}","received_events_url":"https://api.github.com/users/winoros/received_events","type":"User","site_admin":false},"body":"Yes, this operation is the same with the original `colName2Idx` map.","created_at":"2018-08-27T05:34:37Z","updated_at":"2018-08-27T05:34:37Z","html_url":"https://github.com/pingcap/tidb/pull/7385#discussion_r212869567","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/7385","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/212869567"},"html":{"href":"https://github.com/pingcap/tidb/pull/7385#discussion_r212869567"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7385"}},"in_reply_to_id":212855808},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/7385","id":208175874,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA4MTc1ODc0","html_url":"https://github.com/pingcap/tidb/pull/7385","diff_url":"https://github.com/pingcap/tidb/pull/7385.diff","patch_url":"https://github.com/pingcap/tidb/pull/7385.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/7385","number":7385,"state":"open","locked":false,"title":" plan, statistics: maintain `HistColl` in `DataSource`'s `StatsInfo`","user":{"login":"winoros","id":7846227,"node_id":"MDQ6VXNlcjc4NDYyMjc=","avatar_url":"https://avatars1.githubusercontent.com/u/7846227?v=4","gravatar_id":"","url":"https://api.github.com/users/winoros","html_url":"https://github.com/winoros","followers_url":"https://api.github.com/users/winoros/followers","following_url":"https://api.github.com/users/winoros/following{/other_user}","gists_url":"https://api.github.com/users/winoros/gists{/gist_id}","starred_url":"https://api.github.com/users/winoros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/winoros/subscriptions","organizations_url":"https://api.github.com/users/winoros/orgs","repos_url":"https://api.github.com/users/winoros/repos","events_url":"https://api.github.com/users/winoros/events{/privacy}","received_events_url":"https://api.github.com/users/winoros/received_events","type":"User","site_admin":false},"body":"<!--\r\nThank you for contributing to TiDB! Please read TiDB's [CONTRIBUTING](https://github.com/pingcap/tidb/blob/master/CONTRIBUTING.md) document **BEFORE** filing this PR.\r\n-->\r\n\r\n### What problem does this PR solve? <!--add issue link with summary if exists-->\r\n\r\nMaintain `HistColl` in `DataSource`'s `StatsInfo` to get more accurate statistics.\r\n\r\n### What is changed and how it works?\r\n\r\nMap the column by its `UniqueID` rather than `ID`. So it can be maintained in the other plan's `StatsInfo` later.\r\nAnd map the index and column by column's `UniqueID` rather than column's name.\r\n\r\n### Check List <!--REMOVE the items that are not applicable-->\r\n\r\nTests <!-- At least one of them must be included. -->\r\n\r\n - Exsiting tests.\r\n\r\nCode changes\r\n\r\n - Has exported function/method change\r\n - Has exported variable/fields change","created_at":"2018-08-14T05:57:16Z","updated_at":"2018-08-27T05:34:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6dd99cd424b611747a13f642997de2efcb15976b","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":667671533,"node_id":"MDU6TGFiZWw2Njc2NzE1MzM=","url":"https://api.github.com/repos/pingcap/tidb/labels/component/planner","name":"component/planner","color":"1d76db","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/7385/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/7385/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/7385/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/ba4b400d7c8d499826351c42f6c02f08014fbf83","head":{"label":"winoros:hist-in-datasource","ref":"hist-in-datasource","sha":"ba4b400d7c8d499826351c42f6c02f08014fbf83","user":{"login":"winoros","id":7846227,"node_id":"MDQ6VXNlcjc4NDYyMjc=","avatar_url":"https://avatars1.githubusercontent.com/u/7846227?v=4","gravatar_id":"","url":"https://api.github.com/users/winoros","html_url":"https://github.com/winoros","followers_url":"https://api.github.com/users/winoros/followers","following_url":"https://api.github.com/users/winoros/following{/other_user}","gists_url":"https://api.github.com/users/winoros/gists{/gist_id}","starred_url":"https://api.github.com/users/winoros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/winoros/subscriptions","organizations_url":"https://api.github.com/users/winoros/orgs","repos_url":"https://api.github.com/users/winoros/repos","events_url":"https://api.github.com/users/winoros/events{/privacy}","received_events_url":"https://api.github.com/users/winoros/received_events","type":"User","site_admin":false},"repo":{"id":107362799,"node_id":"MDEwOlJlcG9zaXRvcnkxMDczNjI3OTk=","name":"tidb","full_name":"winoros/tidb","owner":{"login":"winoros","id":7846227,"node_id":"MDQ6VXNlcjc4NDYyMjc=","avatar_url":"https://avatars1.githubusercontent.com/u/7846227?v=4","gravatar_id":"","url":"https://api.github.com/users/winoros","html_url":"https://github.com/winoros","followers_url":"https://api.github.com/users/winoros/followers","following_url":"https://api.github.com/users/winoros/following{/other_user}","gists_url":"https://api.github.com/users/winoros/gists{/gist_id}","starred_url":"https://api.github.com/users/winoros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/winoros/subscriptions","organizations_url":"https://api.github.com/users/winoros/orgs","repos_url":"https://api.github.com/users/winoros/repos","events_url":"https://api.github.com/users/winoros/events{/privacy}","received_events_url":"https://api.github.com/users/winoros/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/winoros/tidb","description":"TiDB is a distributed NewSQL database compatible with MySQL protocol ","fork":true,"url":"https://api.github.com/repos/winoros/tidb","forks_url":"https://api.github.com/repos/winoros/tidb/forks","keys_url":"https://api.github.com/repos/winoros/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/winoros/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/winoros/tidb/teams","hooks_url":"https://api.github.com/repos/winoros/tidb/hooks","issue_events_url":"https://api.github.com/repos/winoros/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/winoros/tidb/events","assignees_url":"https://api.github.com/repos/winoros/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/winoros/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/winoros/tidb/tags","blobs_url":"https://api.github.com/repos/winoros/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/winoros/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/winoros/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/winoros/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/winoros/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/winoros/tidb/languages","stargazers_url":"https://api.github.com/repos/winoros/tidb/stargazers","contributors_url":"https://api.github.com/repos/winoros/tidb/contributors","subscribers_url":"https://api.github.com/repos/winoros/tidb/subscribers","subscription_url":"https://api.github.com/repos/winoros/tidb/subscription","commits_url":"https://api.github.com/repos/winoros/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/winoros/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/winoros/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/winoros/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/winoros/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/winoros/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/winoros/tidb/merges","archive_url":"https://api.github.com/repos/winoros/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/winoros/tidb/downloads","issues_url":"https://api.github.com/repos/winoros/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/winoros/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/winoros/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/winoros/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/winoros/tidb/labels{/name}","releases_url":"https://api.github.com/repos/winoros/tidb/releases{/id}","deployments_url":"https://api.github.com/repos/winoros/tidb/deployments","created_at":"2017-10-18T05:29:31Z","updated_at":"2018-06-11T11:24:24Z","pushed_at":"2018-08-24T08:52:51Z","git_url":"git://github.com/winoros/tidb.git","ssh_url":"git@github.com:winoros/tidb.git","clone_url":"https://github.com/winoros/tidb.git","svn_url":"https://github.com/winoros/tidb","homepage":"https://pingcap.com","size":53271,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"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":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"43e9c06a593d86804d7c3e2f2666ad77b471768b","user":{"login":"pingcap","id":11855343,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExODU1MzQz","avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":41986369,"node_id":"MDEwOlJlcG9zaXRvcnk0MTk4NjM2OQ==","name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExODU1MzQz","avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tidb","description":"TiDB is a distributed HTAP database compatible with the MySQL protocol ","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tidb/deployments","created_at":"2015-09-06T04:01:52Z","updated_at":"2018-08-27T05:04:30Z","pushed_at":"2018-08-27T04:34:14Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"https://pingcap.com","size":80501,"stargazers_count":14562,"watchers_count":14562,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2031,"mirror_url":null,"archived":false,"open_issues_count":509,"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":2031,"open_issues":509,"watchers":14562,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7385"},"html":{"href":"https://github.com/pingcap/tidb/pull/7385"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/7385"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/7385/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7385/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7385/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/ba4b400d7c8d499826351c42f6c02f08014fbf83"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"winoros"}}