{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/233386593","pull_request_review_id":174785363,"id":233386593,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMzM4NjU5Mw==","diff_hunk":"@@ -58,6 +58,10 @@ func (st *TxnState) Valid() bool {\n \treturn st.Transaction != nil && st.Transaction.Valid()\n }\n \n+func (st *TxnState) pending() bool {\n+\treturn st.txnFuture != nil && st.Transaction == nil","path":"session/txn.go","position":5,"original_position":5,"commit_id":"a0dd5097552febf79ae89b5eaeba3e714632cda6","original_commit_id":"a0dd5097552febf79ae89b5eaeba3e714632cda6","user":{"login":"tiancaiamao","id":1420062,"node_id":"MDQ6VXNlcjE0MjAwNjI=","avatar_url":"https://avatars2.githubusercontent.com/u/1420062?v=4","gravatar_id":"","url":"https://api.github.com/users/tiancaiamao","html_url":"https://github.com/tiancaiamao","followers_url":"https://api.github.com/users/tiancaiamao/followers","following_url":"https://api.github.com/users/tiancaiamao/following{/other_user}","gists_url":"https://api.github.com/users/tiancaiamao/gists{/gist_id}","starred_url":"https://api.github.com/users/tiancaiamao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tiancaiamao/subscriptions","organizations_url":"https://api.github.com/users/tiancaiamao/orgs","repos_url":"https://api.github.com/users/tiancaiamao/repos","events_url":"https://api.github.com/users/tiancaiamao/events{/privacy}","received_events_url":"https://api.github.com/users/tiancaiamao/received_events","type":"User","site_admin":false},"body":"It's hard for me to get the difference, could you explain why?","created_at":"2018-11-14T10:16:29Z","updated_at":"2018-11-14T10:16:29Z","html_url":"https://github.com/pingcap/tidb/pull/8260#discussion_r233386593","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/8260","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/233386593"},"html":{"href":"https://github.com/pingcap/tidb/pull/8260#discussion_r233386593"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/8260"}},"in_reply_to_id":233312061},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/8260","id":229777816,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI5Nzc3ODE2","html_url":"https://github.com/pingcap/tidb/pull/8260","diff_url":"https://github.com/pingcap/tidb/pull/8260.diff","patch_url":"https://github.com/pingcap/tidb/pull/8260.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/8260","number":8260,"state":"open","locked":false,"title":"session,executor: run statement without transaction","user":{"login":"tiancaiamao","id":1420062,"node_id":"MDQ6VXNlcjE0MjAwNjI=","avatar_url":"https://avatars2.githubusercontent.com/u/1420062?v=4","gravatar_id":"","url":"https://api.github.com/users/tiancaiamao","html_url":"https://github.com/tiancaiamao","followers_url":"https://api.github.com/users/tiancaiamao/followers","following_url":"https://api.github.com/users/tiancaiamao/following{/other_user}","gists_url":"https://api.github.com/users/tiancaiamao/gists{/gist_id}","starred_url":"https://api.github.com/users/tiancaiamao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tiancaiamao/subscriptions","organizations_url":"https://api.github.com/users/tiancaiamao/orgs","repos_url":"https://api.github.com/users/tiancaiamao/repos","events_url":"https://api.github.com/users/tiancaiamao/events{/privacy}","received_events_url":"https://api.github.com/users/tiancaiamao/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\nSome users  prefer `set @@autocommit = 0` ... `set @@autocommit = 1` to `begin ... commit`\r\nCurrently TiDB has problems with such kind of usage:\r\n\r\n```\r\nset @@autocommit = 0;  // get tso here, transaction start. oh, my god! \r\n// 30 minutes later ...\r\n// ...\r\nselect xxx    // transaction should have start here\r\ninsert into t values (3)\r\n```\r\n\r\nselect 1 // This statement should not make the session enter a transaction, because it never need Txn(). \r\n'set xxx' is similar\r\n\r\n\r\n### What is changed and how it works?\r\n\r\nDon't initialize `Txn()` for those statements that don't need it.\r\nDelay active pending transaction as much as possible.\r\n\r\n- ActivePendingTxn is removed from `ExecStmt.Exec` in adaptor.go\r\n- Call Txn() will active pending txn, so the process is delayed until Txn() is called\r\n- If Txn() is not called, the statement will not set `mysql.ServerStatusInTrans`\r\n- Txn() function signature is changed, I'll update it in a separate PR as that involves too many changes\r\n\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 interface methods change\r\n\r\n","created_at":"2018-11-09T18:19:10Z","updated_at":"2018-11-14T10:16:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1c23471e8d5a42c4afcf66ea795e0afcd2284f50","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":970807266,"node_id":"MDU6TGFiZWw5NzA4MDcyNjY=","url":"https://api.github.com/repos/pingcap/tidb/labels/component/executor","name":"component/executor","color":"000000","default":false},{"id":916643523,"node_id":"MDU6TGFiZWw5MTY2NDM1MjM=","url":"https://api.github.com/repos/pingcap/tidb/labels/require-LGT3","name":"require-LGT3","color":"d93f0b","default":false},{"id":564574080,"node_id":"MDU6TGFiZWw1NjQ1NzQwODA=","url":"https://api.github.com/repos/pingcap/tidb/labels/status/LGT1","name":"status/LGT1","color":"d4c5f9","default":false},{"id":770872605,"node_id":"MDU6TGFiZWw3NzA4NzI2MDU=","url":"https://api.github.com/repos/pingcap/tidb/labels/status/all%20tests%20passed","name":"status/all tests passed","color":"2cbe4e","default":false},{"id":630229257,"node_id":"MDU6TGFiZWw2MzAyMjkyNTc=","url":"https://api.github.com/repos/pingcap/tidb/labels/type/bug-fix","name":"type/bug-fix","color":"fc2929","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/8260/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/8260/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/8260/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/a0dd5097552febf79ae89b5eaeba3e714632cda6","head":{"label":"tiancaiamao:autocommit","ref":"autocommit","sha":"a0dd5097552febf79ae89b5eaeba3e714632cda6","user":{"login":"tiancaiamao","id":1420062,"node_id":"MDQ6VXNlcjE0MjAwNjI=","avatar_url":"https://avatars2.githubusercontent.com/u/1420062?v=4","gravatar_id":"","url":"https://api.github.com/users/tiancaiamao","html_url":"https://github.com/tiancaiamao","followers_url":"https://api.github.com/users/tiancaiamao/followers","following_url":"https://api.github.com/users/tiancaiamao/following{/other_user}","gists_url":"https://api.github.com/users/tiancaiamao/gists{/gist_id}","starred_url":"https://api.github.com/users/tiancaiamao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tiancaiamao/subscriptions","organizations_url":"https://api.github.com/users/tiancaiamao/orgs","repos_url":"https://api.github.com/users/tiancaiamao/repos","events_url":"https://api.github.com/users/tiancaiamao/events{/privacy}","received_events_url":"https://api.github.com/users/tiancaiamao/received_events","type":"User","site_admin":false},"repo":{"id":63065396,"node_id":"MDEwOlJlcG9zaXRvcnk2MzA2NTM5Ng==","name":"tidb","full_name":"tiancaiamao/tidb","private":false,"owner":{"login":"tiancaiamao","id":1420062,"node_id":"MDQ6VXNlcjE0MjAwNjI=","avatar_url":"https://avatars2.githubusercontent.com/u/1420062?v=4","gravatar_id":"","url":"https://api.github.com/users/tiancaiamao","html_url":"https://github.com/tiancaiamao","followers_url":"https://api.github.com/users/tiancaiamao/followers","following_url":"https://api.github.com/users/tiancaiamao/following{/other_user}","gists_url":"https://api.github.com/users/tiancaiamao/gists{/gist_id}","starred_url":"https://api.github.com/users/tiancaiamao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tiancaiamao/subscriptions","organizations_url":"https://api.github.com/users/tiancaiamao/orgs","repos_url":"https://api.github.com/users/tiancaiamao/repos","events_url":"https://api.github.com/users/tiancaiamao/events{/privacy}","received_events_url":"https://api.github.com/users/tiancaiamao/received_events","type":"User","site_admin":false},"html_url":"https://github.com/tiancaiamao/tidb","description":"TiDB is a distributed NewSQL database compatible with MySQL protocol ","fork":true,"url":"https://api.github.com/repos/tiancaiamao/tidb","forks_url":"https://api.github.com/repos/tiancaiamao/tidb/forks","keys_url":"https://api.github.com/repos/tiancaiamao/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tiancaiamao/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tiancaiamao/tidb/teams","hooks_url":"https://api.github.com/repos/tiancaiamao/tidb/hooks","issue_events_url":"https://api.github.com/repos/tiancaiamao/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/tiancaiamao/tidb/events","assignees_url":"https://api.github.com/repos/tiancaiamao/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/tiancaiamao/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/tiancaiamao/tidb/tags","blobs_url":"https://api.github.com/repos/tiancaiamao/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tiancaiamao/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tiancaiamao/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/tiancaiamao/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tiancaiamao/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/tiancaiamao/tidb/languages","stargazers_url":"https://api.github.com/repos/tiancaiamao/tidb/stargazers","contributors_url":"https://api.github.com/repos/tiancaiamao/tidb/contributors","subscribers_url":"https://api.github.com/repos/tiancaiamao/tidb/subscribers","subscription_url":"https://api.github.com/repos/tiancaiamao/tidb/subscription","commits_url":"https://api.github.com/repos/tiancaiamao/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/tiancaiamao/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/tiancaiamao/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/tiancaiamao/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/tiancaiamao/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/tiancaiamao/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tiancaiamao/tidb/merges","archive_url":"https://api.github.com/repos/tiancaiamao/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tiancaiamao/tidb/downloads","issues_url":"https://api.github.com/repos/tiancaiamao/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/tiancaiamao/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/tiancaiamao/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/tiancaiamao/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tiancaiamao/tidb/labels{/name}","releases_url":"https://api.github.com/repos/tiancaiamao/tidb/releases{/id}","deployments_url":"https://api.github.com/repos/tiancaiamao/tidb/deployments","created_at":"2016-07-11T12:20:13Z","updated_at":"2018-11-08T12:08:01Z","pushed_at":"2018-11-14T03:30:15Z","git_url":"git://github.com/tiancaiamao/tidb.git","ssh_url":"git@github.com:tiancaiamao/tidb.git","clone_url":"https://github.com/tiancaiamao/tidb.git","svn_url":"https://github.com/tiancaiamao/tidb","homepage":"","size":63065,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"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":"aa979705df0333d98395d8f548114e989eb0dcbd","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-14T10:03:50Z","pushed_at":"2018-11-14T10:06:05Z","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":87789,"stargazers_count":15823,"watchers_count":15823,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2239,"mirror_url":null,"archived":false,"open_issues_count":608,"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":2239,"open_issues":608,"watchers":15823,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/8260"},"html":{"href":"https://github.com/pingcap/tidb/pull/8260"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/8260"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/8260/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/8260/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/8260/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/a0dd5097552febf79ae89b5eaeba3e714632cda6"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"tiancaiamao"}}