{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/72372568","id":72372568,"diff_hunk":"@@ -13,179 +13,564 @@\n \n package plan\n \n-// Convert2PhysicalPlan implements LogicalPlan Convert2PhysicalPlan interface.\n-func (p *DataSource) Convert2PhysicalPlan() (np PhysicalPlan) {\n-\tindices, includeTableScan := availableIndices(p.table)\n-\tif includeTableScan && len(indices) == 0 {\n-\t\tnp = &PhysicalTableScan{\n-\t\t\tTable:       p.Table,\n-\t\t\tColumns:     p.Columns,\n-\t\t\tTableAsName: p.TableAsName,\n-\t\t\tDBName:      p.DBName,\n+import (\n+\t\"github.com/juju/errors\"\n+\t\"github.com/pingcap/tidb/expression\"\n+\t\"github.com/pingcap/tidb/model\"\n+\t\"github.com/pingcap/tidb/mysql\"\n+\t\"github.com/pingcap/tidb/plan/statistics\"\n+\t\"github.com/pingcap/tidb/util/types\"\n+\t\"math\"\n+)\n+\n+const (\n+\tnetWorkFactor   = 1.5\n+\tmemoryFactor    = 5.0\n+\tselectionFactor = 0.8\n+\tdistinctFactor  = 0.7\n+)\n+\n+func getRowCountByIndexRange(table *statistics.Table, indexRange *IndexRange, indexInfo *model.IndexInfo) (uint64, error) {\n+\tcount := float64(table.Count)\n+\tfor i := 0; i < len(indexRange.LowVal); i++ {\n+\t\tl := indexRange.LowVal[i]\n+\t\tr := indexRange.HighVal[i]","path":"plan/physical_plan_builder.go","position":34,"original_position":34,"commit_id":"bb772d91863550aa5f527ef573efd70a030f843a","original_commit_id":"bb772d91863550aa5f527ef573efd70a030f843a","user":{"login":"hanfei19910905","id":4242394,"avatar_url":"https://avatars.githubusercontent.com/u/4242394?v=3","gravatar_id":"","url":"https://api.github.com/users/hanfei19910905","html_url":"https://github.com/hanfei19910905","followers_url":"https://api.github.com/users/hanfei19910905/followers","following_url":"https://api.github.com/users/hanfei19910905/following{/other_user}","gists_url":"https://api.github.com/users/hanfei19910905/gists{/gist_id}","starred_url":"https://api.github.com/users/hanfei19910905/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hanfei19910905/subscriptions","organizations_url":"https://api.github.com/users/hanfei19910905/orgs","repos_url":"https://api.github.com/users/hanfei19910905/repos","events_url":"https://api.github.com/users/hanfei19910905/events{/privacy}","received_events_url":"https://api.github.com/users/hanfei19910905/received_events","type":"User","site_admin":false},"body":"I will consider it in next pr.","created_at":"2016-07-27T02:38:29Z","updated_at":"2016-07-27T02:38:29Z","html_url":"https://github.com/pingcap/tidb/pull/1498#discussion_r72372568","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/1498","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/72372568"},"html":{"href":"https://github.com/pingcap/tidb/pull/1498#discussion_r72372568"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1498"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/1498","id":78626835,"html_url":"https://github.com/pingcap/tidb/pull/1498","diff_url":"https://github.com/pingcap/tidb/pull/1498.diff","patch_url":"https://github.com/pingcap/tidb/pull/1498.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/1498","number":1498,"state":"open","locked":false,"title":"[DNM]support cbo","user":{"login":"hanfei19910905","id":4242394,"avatar_url":"https://avatars.githubusercontent.com/u/4242394?v=3","gravatar_id":"","url":"https://api.github.com/users/hanfei19910905","html_url":"https://github.com/hanfei19910905","followers_url":"https://api.github.com/users/hanfei19910905/followers","following_url":"https://api.github.com/users/hanfei19910905/following{/other_user}","gists_url":"https://api.github.com/users/hanfei19910905/gists{/gist_id}","starred_url":"https://api.github.com/users/hanfei19910905/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hanfei19910905/subscriptions","organizations_url":"https://api.github.com/users/hanfei19910905/orgs","repos_url":"https://api.github.com/users/hanfei19910905/repos","events_url":"https://api.github.com/users/hanfei19910905/events{/privacy}","received_events_url":"https://api.github.com/users/hanfei19910905/received_events","type":"User","site_admin":false},"body":"@shenli @zimulala @coocood @tiancaiamao PTAL","created_at":"2016-07-25T05:06:29Z","updated_at":"2016-07-27T02:38:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"667e43d294f7365b884163fff4b70686159d3af4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/1498/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/1498/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/1498/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/bb772d91863550aa5f527ef573efd70a030f843a","head":{"label":"pingcap:hanfei/cbo","ref":"hanfei/cbo","sha":"bb772d91863550aa5f527ef573efd70a030f843a","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","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,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","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 NewSQL database compatible with 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":"2016-07-26T21:22:49Z","pushed_at":"2016-07-27T02:35:23Z","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":"","size":21700,"stargazers_count":4353,"watchers_count":4353,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":548,"mirror_url":null,"open_issues_count":104,"forks":548,"open_issues":104,"watchers":4353,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"04da3d2f8b02bcb2b8184f6e25063cd9bd92e8e4","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","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,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","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 NewSQL database compatible with 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":"2016-07-26T21:22:49Z","pushed_at":"2016-07-27T02:35:23Z","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":"","size":21700,"stargazers_count":4353,"watchers_count":4353,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":548,"mirror_url":null,"open_issues_count":104,"forks":548,"open_issues":104,"watchers":4353,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1498"},"html":{"href":"https://github.com/pingcap/tidb/pull/1498"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/1498"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/1498/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1498/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1498/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/bb772d91863550aa5f527ef573efd70a030f843a"}}}}
{"actor":{"display_login":"hanfei19910905"}}