{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/231405209","pull_request_review_id":172367626,"id":231405209,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMTQwNTIwOQ==","diff_hunk":"@@ -857,6 +857,202 @@ func (idx *Index) getRowCount(sc *stmtctx.StatementContext, indexRanges []*range\n \treturn totalCount, nil\n }\n \n+func (c *Column) newNumericColumnBySelectivity(sc *stmtctx.StatementContext, statsNode *StatsNode) (*Column, error) {\n+\tnewColHist := &Column{Info: c.Info}\n+\tnewColHist.Histogram = *NewHistogram(c.ID, int64(float64(c.NDV)*statsNode.Selectivity), 0, 0, c.Tp, chunk.InitialCapacity, 0)\n+\tranLowIdx := 0\n+\tvar totCnt int64 = 0\n+\t// Process each bucket.\n+\tfor i := 0; i < c.Bounds.NumRows() && ranLowIdx < len(statsNode.Ranges); i += 2 {\n+\t\tnewBkt := Bucket{Repeat: c.Buckets[i/2].Repeat}\n+\t\t// Find the bucket which is the first one whose have intersection with the bucket.\n+\t\tfor ; ranLowIdx < len(statsNode.Ranges); ranLowIdx++ {\n+\t\t\tif chunk.Compare(c.Bounds.GetRow(i), 0, &statsNode.Ranges[ranLowIdx].HighVal[0]) <= 0 {\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t}\n+\t\tranHighIdx := ranLowIdx\n+\t\t// Find the bucket which is the first one whose lowVal is bigger than bucket's high bound, i.e. out of the bucket.\n+\t\tfor ; ranHighIdx < len(statsNode.Ranges); ranHighIdx++ {\n+\t\t\tif chunk.Compare(c.Bounds.GetRow(i+1), 0, &statsNode.Ranges[ranHighIdx].LowVal[0]) < 0 {\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t}\n+\t\tif ranLowIdx == ranHighIdx {\n+\t\t\tcontinue\n+\t\t}\n+\t\toverlapped := 0.0\n+\t\t// Compute the overlap ratio.\n+\t\tfor ranIdx := ranLowIdx; ranIdx < ranHighIdx; ranIdx++ {\n+\t\t\toverlapped += c.CalcRangeFraction(i/2, &statsNode.Ranges[ranIdx].LowVal[0], &statsNode.Ranges[ranIdx].HighVal[0])","path":"statistics/histogram.go","position":155,"original_position":155,"commit_id":"37dbb1fca2e72b33a0e0069291af15e7f694b820","original_commit_id":"37dbb1fca2e72b33a0e0069291af15e7f694b820","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":"How to decide the overlap ratio to calculate the count of new histogram?\r\nI need some more explanation to get your point 😂 ","created_at":"2018-11-07T07:43:58Z","updated_at":"2018-11-07T07:43:59Z","html_url":"https://github.com/pingcap/tidb/pull/7921#discussion_r231405209","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/7921","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/231405209"},"html":{"href":"https://github.com/pingcap/tidb/pull/7921#discussion_r231405209"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7921"}},"in_reply_to_id":228411912},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/7921","id":223294710,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIzMjk0NzEw","html_url":"https://github.com/pingcap/tidb/pull/7921","diff_url":"https://github.com/pingcap/tidb/pull/7921.diff","patch_url":"https://github.com/pingcap/tidb/pull/7921.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/7921","number":7921,"state":"open","locked":false,"title":" planner, statistics: build new histogram using range information","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\nNot a problem. To enhance the `histColl` held by `DataSoure`'s `StatsInfo` if we will hold it.\r\n\r\n### What is changed and how it works?\r\nCut the histograms' buckets by the given range information.\r\nCurrently only numeric column's bucket' bound will be changed during this process.\r\nOther column and index will only remove the bucket that have no intersection with ranges.\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 - Unit test\r\n\r\nCode changes\r\n\r\n - Has exported function/method change\r\n - Has exported variable/fields change\r\n\r\nSide effects\r\n\r\n - Possible performance regression\r\n - Increased code complexity\r\n\r\nRelated changes\r\n\r\n - Need to update the documentation\r\n - Need to be included in the release note\r\n","created_at":"2018-10-16T15:25:19Z","updated_at":"2018-11-07T07:43:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2db10f874197467de9bb24aade33d0ae44aa05eb","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},{"id":722152533,"node_id":"MDU6TGFiZWw3MjIxNTI1MzM=","url":"https://api.github.com/repos/pingcap/tidb/labels/component/statistics","name":"component/statistics","color":"80e58d","default":false},{"id":256872088,"node_id":"MDU6TGFiZWwyNTY4NzIwODg=","url":"https://api.github.com/repos/pingcap/tidb/labels/type/enhancement","name":"type/enhancement","color":"84b6eb","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/7921/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/7921/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/7921/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/37dbb1fca2e72b33a0e0069291af15e7f694b820","head":{"label":"winoros:selectivity","ref":"selectivity","sha":"37dbb1fca2e72b33a0e0069291af15e7f694b820","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","private":false,"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},"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-08-30T09:16:21Z","pushed_at":"2018-11-05T12:54:36Z","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":60129,"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":"d606b0d55fdfe1997857ea7b4bb4d85e6a0f6b09","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","private":false,"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},"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-11-07T07:00:09Z","pushed_at":"2018-11-07T07:15:37Z","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":87165,"stargazers_count":15696,"watchers_count":15696,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2220,"mirror_url":null,"archived":false,"open_issues_count":594,"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":2220,"open_issues":594,"watchers":15696,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7921"},"html":{"href":"https://github.com/pingcap/tidb/pull/7921"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/7921"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/7921/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7921/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7921/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/37dbb1fca2e72b33a0e0069291af15e7f694b820"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"winoros"}}