{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/66052936","id":66052936,"diff_hunk":"@@ -0,0 +1,157 @@\n+// Copyright 2016 PingCAP, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+package executor\n+\n+import (\n+\t\"github.com/juju/errors\"\n+\t\"github.com/pingcap/tidb/expression\"\n+\t\"github.com/pingcap/tidb/kv\"\n+\t\"github.com/pingcap/tidb/model\"\n+\t\"github.com/pingcap/tidb/optimizer/plan\"\n+\t\"github.com/pingcap/tidb/parser/opcode\"\n+)\n+\n+// compose CNF items into a balance deep CNF tree, which benefits a lot for pb decoder/encoder.\n+func composeCondition(conditions []expression.Expression) expression.Expression {\n+\tlength := len(conditions)\n+\tif length == 0 {\n+\t\treturn nil\n+\t}\n+\tif length == 1 {\n+\t\treturn conditions[0]\n+\t}\n+\treturn expression.NewFunction(model.NewCIStr(opcode.Ops[opcode.AndAnd]), []expression.Expression{composeCondition(conditions[0 : length/2]), composeCondition(conditions[length/2:])})\n+}\n+\n+//TODO: select join algorithm during cbo phase.\n+func (b *executorBuilder) buildJoin(v *plan.Join) Executor {\n+\te := &HashJoinExec{\n+\t\tschema:      v.GetSchema(),\n+\t\totherFilter: composeCondition(v.OtherConditions),\n+\t\tprepared:    false,\n+\t\tctx:         b.ctx,\n+\t}\n+\tvar leftHashKey, rightHashKey []*expression.Column\n+\tfor _, eqCond := range v.EqualConditions {\n+\t\tln, _ := eqCond.Args[0].(*expression.Column)\n+\t\trn, _ := eqCond.Args[1].(*expression.Column)\n+\t\tleftHashKey = append(leftHashKey, ln)\n+\t\trightHashKey = append(rightHashKey, rn)\n+\t}\n+\tswitch v.JoinType {\n+\tcase plan.LeftOuterJoin:\n+\t\te.outter = true\n+\t\te.leftSmall = false\n+\t\te.smallFilter = composeCondition(v.RightConditions)\n+\t\te.bigFilter = composeCondition(v.LeftConditions)\n+\t\te.smallHashKey = rightHashKey\n+\t\te.bigHashKey = leftHashKey\n+\tcase plan.RightOuterJoin:\n+\t\te.outter = true\n+\t\te.leftSmall = true\n+\t\te.smallFilter = composeCondition(v.LeftConditions)\n+\t\te.bigFilter = composeCondition(v.RightConditions)\n+\t\te.smallHashKey = leftHashKey\n+\t\te.bigHashKey = rightHashKey\n+\tcase plan.InnerJoin:\n+\t\t//TODO: assume right table is the small one before cbo is realized.\n+\t\te.outter = false\n+\t\te.leftSmall = false\n+\t\te.smallFilter = composeCondition(v.RightConditions)\n+\t\te.bigFilter = composeCondition(v.LeftConditions)\n+\t\te.smallHashKey = rightHashKey\n+\t\te.bigHashKey = leftHashKey\n+\tdefault:\n+\t\tb.err = ErrUnknownPlan.Gen(\"Unknown Join Type !!\")\n+\t\treturn nil\n+\t}\n+\tif e.leftSmall {\n+\t\te.smallExec = b.build(v.GetChildByIndex(0))\n+\t\te.bigExec = b.build(v.GetChildByIndex(1))\n+\t} else {\n+\t\te.smallExec = b.build(v.GetChildByIndex(1))\n+\t\te.bigExec = b.build(v.GetChildByIndex(0))\n+\t}\n+\treturn e\n+}\n+\n+func (b *executorBuilder) buildAggregation(v *plan.Aggregation) Executor {\n+\treturn &AggregationExec{\n+\t\tSrc:          b.build(v.GetChildByIndex(0)),\n+\t\tschema:       v.GetSchema(),\n+\t\tctx:          b.ctx,\n+\t\tAggFuncs:     v.AggFuncs,\n+\t\tGroupByItems: v.GroupByItems,\n+\t}\n+}\n+\n+func (b *executorBuilder) buildSelection(v *plan.Selection) Executor {\n+\treturn &SelectionExec{\n+\t\tSrc:       b.build(v.GetChildByIndex(0)),\n+\t\tCondition: composeCondition(v.Conditions),\n+\t\tschema:    v.GetSchema(),\n+\t\tctx:       b.ctx,\n+\t}\n+}\n+\n+func (b *executorBuilder) buildProjection(v *plan.Projection) Executor {\n+\treturn &ProjectionExec{\n+\t\tSrc:    b.build(v.GetChildByIndex(0)),\n+\t\tctx:    b.ctx,\n+\t\texprs:  v.Exprs,\n+\t\tschema: v.GetSchema(),\n+\t}\n+}\n+\n+func (b *executorBuilder) buildNewTableScan(v *plan.NewTableScan) Executor {\n+\ttxn, err := b.ctx.GetTxn(false)\n+\tif err != nil {\n+\t\tb.err = err\n+\t\treturn nil\n+\t}\n+\ttable, _ := b.is.TableByID(v.Table.ID)\n+\tclient := txn.GetClient()\n+\tvar memDB bool\n+\tswitch v.DBName.L {\n+\tcase \"information_schema\", \"performance_schema\":\n+\t\tmemDB = true\n+\t}\n+\tsupportDesc := client.SupportRequestType(kv.ReqTypeSelect, kv.ReqSubTypeDesc)\n+\tif !memDB && client.SupportRequestType(kv.ReqTypeSelect, 0) {\n+\t\t// TODO: support condition pushdown and union scan exec.\n+\t\te := &NewTableScanExec{","path":"executor/new_builder.go","position":133,"original_position":133,"commit_id":"e96e7e12923531585eb33d1a587354338a5ba032","original_commit_id":"fff4eebb257981513634c4c620c535b700d70767","user":{"login":"zimulala","id":4242506,"avatar_url":"https://avatars.githubusercontent.com/u/4242506?v=3","gravatar_id":"","url":"https://api.github.com/users/zimulala","html_url":"https://github.com/zimulala","followers_url":"https://api.github.com/users/zimulala/followers","following_url":"https://api.github.com/users/zimulala/following{/other_user}","gists_url":"https://api.github.com/users/zimulala/gists{/gist_id}","starred_url":"https://api.github.com/users/zimulala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zimulala/subscriptions","organizations_url":"https://api.github.com/users/zimulala/orgs","repos_url":"https://api.github.com/users/zimulala/repos","events_url":"https://api.github.com/users/zimulala/events{/privacy}","received_events_url":"https://api.github.com/users/zimulala/received_events","type":"User","site_admin":false},"body":"return &...{...} directly.","created_at":"2016-06-07T11:26:04Z","updated_at":"2016-06-07T11:26:04Z","html_url":"https://github.com/pingcap/tidb/pull/1294#discussion_r66052936","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/1294","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/66052936"},"html":{"href":"https://github.com/pingcap/tidb/pull/1294#discussion_r66052936"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1294"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/1294","id":72663175,"html_url":"https://github.com/pingcap/tidb/pull/1294","diff_url":"https://github.com/pingcap/tidb/pull/1294.diff","patch_url":"https://github.com/pingcap/tidb/pull/1294.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/1294","number":1294,"state":"open","locked":false,"title":"rewrite executor.","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":"Replace \"result field\" with schema. Evaluate expression with indices of rows during execution.","created_at":"2016-06-06T06:53:30Z","updated_at":"2016-06-07T11:26:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"684aac3e9e9b56bdb19ab2f6f3b888205ec72673","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/1294/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/1294/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/1294/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/e96e7e12923531585eb33d1a587354338a5ba032","head":{"label":"pingcap:hanfei/rewrite_exec","ref":"hanfei/rewrite_exec","sha":"e96e7e12923531585eb33d1a587354338a5ba032","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-06-07T08:33:05Z","pushed_at":"2016-06-07T10:43:58Z","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":15244,"stargazers_count":4015,"watchers_count":4015,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":480,"mirror_url":null,"open_issues_count":82,"forks":480,"open_issues":82,"watchers":4015,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"1e7a9b44b31842b9e8d03e5a075e50b2449f7a6b","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-06-07T08:33:05Z","pushed_at":"2016-06-07T10:43:58Z","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":15244,"stargazers_count":4015,"watchers_count":4015,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":480,"mirror_url":null,"open_issues_count":82,"forks":480,"open_issues":82,"watchers":4015,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1294"},"html":{"href":"https://github.com/pingcap/tidb/pull/1294"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/1294"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/1294/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1294/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1294/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/e96e7e12923531585eb33d1a587354338a5ba032"}}}}
{"actor":{"display_login":"zimulala"}}