{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/presto/pulls/comments/46644247","id":46644247,"diff_hunk":"@@ -33,20 +33,29 @@\n import com.facebook.presto.sql.planner.plan.TableCommitNode;\n import com.facebook.presto.sql.planner.plan.TableScanNode;\n import com.facebook.presto.sql.planner.plan.TableWriterNode;\n+import com.facebook.presto.sql.planner.plan.TableWriterNode.CreateHandle;\n+import com.facebook.presto.sql.planner.plan.TableWriterNode.CreateName;\n import com.facebook.presto.sql.planner.plan.TableWriterNode.DeleteHandle;\n+import com.facebook.presto.sql.planner.plan.TableWriterNode.InsertReference;\n+import com.facebook.presto.sql.planner.plan.TableWriterNode.WriterTarget;\n import com.google.common.collect.ImmutableList;\n+import com.google.common.collect.ImmutableMap;\n import com.google.common.collect.ImmutableSet;\n import com.google.common.collect.Iterables;\n \n import java.util.List;\n import java.util.Map;\n import java.util.Optional;\n+import java.util.Set;\n \n import static com.facebook.presto.sql.planner.plan.ChildReplacer.replaceChildren;\n+import static com.google.common.base.Preconditions.checkArgument;\n import static com.google.common.base.Verify.verify;\n+import static java.util.Objects.requireNonNull;\n+import static java.util.stream.Collectors.toSet;\n \n /*\n- * Major HACK alert!!!\n+ * Major HACK alert!!!!","path":"presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/BeginTableWrite.java","position":27,"original_position":27,"commit_id":"575d8f83352404c71bd7e8a680005d8994793915","original_commit_id":"575d8f83352404c71bd7e8a680005d8994793915","user":{"login":"raghavsethi","id":715788,"avatar_url":"https://avatars.githubusercontent.com/u/715788?v=3","gravatar_id":"","url":"https://api.github.com/users/raghavsethi","html_url":"https://github.com/raghavsethi","followers_url":"https://api.github.com/users/raghavsethi/followers","following_url":"https://api.github.com/users/raghavsethi/following{/other_user}","gists_url":"https://api.github.com/users/raghavsethi/gists{/gist_id}","starred_url":"https://api.github.com/users/raghavsethi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raghavsethi/subscriptions","organizations_url":"https://api.github.com/users/raghavsethi/orgs","repos_url":"https://api.github.com/users/raghavsethi/repos","events_url":"https://api.github.com/users/raghavsethi/events{/privacy}","received_events_url":"https://api.github.com/users/raghavsethi/received_events","type":"User","site_admin":false},"body":"Haha I wanted to say how much I agree with that statement :stuck_out_tongue_winking_eye: ","created_at":"2015-12-04T02:57:14Z","updated_at":"2015-12-04T02:57:14Z","html_url":"https://github.com/facebook/presto/pull/4031#discussion_r46644247","pull_request_url":"https://api.github.com/repos/facebook/presto/pulls/4031","_links":{"self":{"href":"https://api.github.com/repos/facebook/presto/pulls/comments/46644247"},"html":{"href":"https://github.com/facebook/presto/pull/4031#discussion_r46644247"},"pull_request":{"href":"https://api.github.com/repos/facebook/presto/pulls/4031"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/presto/pulls/4031","id":51738149,"html_url":"https://github.com/facebook/presto/pull/4031","diff_url":"https://github.com/facebook/presto/pull/4031.diff","patch_url":"https://github.com/facebook/presto/pull/4031.patch","issue_url":"https://api.github.com/repos/facebook/presto/issues/4031","number":4031,"state":"open","locked":false,"title":"Add optimizer to pushdown writes through UNION ALL","user":{"login":"raghavsethi","id":715788,"avatar_url":"https://avatars.githubusercontent.com/u/715788?v=3","gravatar_id":"","url":"https://api.github.com/users/raghavsethi","html_url":"https://github.com/raghavsethi","followers_url":"https://api.github.com/users/raghavsethi/followers","following_url":"https://api.github.com/users/raghavsethi/following{/other_user}","gists_url":"https://api.github.com/users/raghavsethi/gists{/gist_id}","starred_url":"https://api.github.com/users/raghavsethi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raghavsethi/subscriptions","organizations_url":"https://api.github.com/users/raghavsethi/orgs","repos_url":"https://api.github.com/users/raghavsethi/repos","events_url":"https://api.github.com/users/raghavsethi/events{/privacy}","received_events_url":"https://api.github.com/users/raghavsethi/received_events","type":"User","site_admin":false},"body":"When processing queries that created tables from UNION ALLs of other tables, Presto would collect all results from the UNION ALL into a single node prior to writing. Added an optimizer that pushes the TableWriter nodes through the union. This will improve performance by allowing workers to write to the new table in parallel.\r\n\r\nFixes #3965.\r\n\r\nFor this sample query\r\n```\r\nCREATE TABLE test AS SELECT * FROM table1 WHERE id%3 = 0 UNION ALL SELECT * FROM table2 WHERE id%3 = 1 UNION ALL SELECT * FROM table3 WHERE user_id%3 = 2;\r\n```\r\nwhich writes 1.6 billion rows into the table `test`, this decreases query completion time from 3m35s to about 40s (on a 12 node cluster), and reduces data transferred by about half.","created_at":"2015-11-25T00:36:31Z","updated_at":"2015-12-04T02:57:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bbe886a52c5b27e162b5fc45a49a895ab038a358","assignee":{"login":"haozhun","id":2020503,"avatar_url":"https://avatars.githubusercontent.com/u/2020503?v=3","gravatar_id":"","url":"https://api.github.com/users/haozhun","html_url":"https://github.com/haozhun","followers_url":"https://api.github.com/users/haozhun/followers","following_url":"https://api.github.com/users/haozhun/following{/other_user}","gists_url":"https://api.github.com/users/haozhun/gists{/gist_id}","starred_url":"https://api.github.com/users/haozhun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haozhun/subscriptions","organizations_url":"https://api.github.com/users/haozhun/orgs","repos_url":"https://api.github.com/users/haozhun/repos","events_url":"https://api.github.com/users/haozhun/events{/privacy}","received_events_url":"https://api.github.com/users/haozhun/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/facebook/presto/pulls/4031/commits","review_comments_url":"https://api.github.com/repos/facebook/presto/pulls/4031/comments","review_comment_url":"https://api.github.com/repos/facebook/presto/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/presto/issues/4031/comments","statuses_url":"https://api.github.com/repos/facebook/presto/statuses/575d8f83352404c71bd7e8a680005d8994793915","head":{"label":"raghavsethi:unionall","ref":"unionall","sha":"575d8f83352404c71bd7e8a680005d8994793915","user":{"login":"raghavsethi","id":715788,"avatar_url":"https://avatars.githubusercontent.com/u/715788?v=3","gravatar_id":"","url":"https://api.github.com/users/raghavsethi","html_url":"https://github.com/raghavsethi","followers_url":"https://api.github.com/users/raghavsethi/followers","following_url":"https://api.github.com/users/raghavsethi/following{/other_user}","gists_url":"https://api.github.com/users/raghavsethi/gists{/gist_id}","starred_url":"https://api.github.com/users/raghavsethi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raghavsethi/subscriptions","organizations_url":"https://api.github.com/users/raghavsethi/orgs","repos_url":"https://api.github.com/users/raghavsethi/repos","events_url":"https://api.github.com/users/raghavsethi/events{/privacy}","received_events_url":"https://api.github.com/users/raghavsethi/received_events","type":"User","site_admin":false},"repo":{"id":42330619,"name":"presto","full_name":"raghavsethi/presto","owner":{"login":"raghavsethi","id":715788,"avatar_url":"https://avatars.githubusercontent.com/u/715788?v=3","gravatar_id":"","url":"https://api.github.com/users/raghavsethi","html_url":"https://github.com/raghavsethi","followers_url":"https://api.github.com/users/raghavsethi/followers","following_url":"https://api.github.com/users/raghavsethi/following{/other_user}","gists_url":"https://api.github.com/users/raghavsethi/gists{/gist_id}","starred_url":"https://api.github.com/users/raghavsethi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raghavsethi/subscriptions","organizations_url":"https://api.github.com/users/raghavsethi/orgs","repos_url":"https://api.github.com/users/raghavsethi/repos","events_url":"https://api.github.com/users/raghavsethi/events{/privacy}","received_events_url":"https://api.github.com/users/raghavsethi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/raghavsethi/presto","description":"Distributed SQL query engine for running interactive analytic queries against big data sources.","fork":true,"url":"https://api.github.com/repos/raghavsethi/presto","forks_url":"https://api.github.com/repos/raghavsethi/presto/forks","keys_url":"https://api.github.com/repos/raghavsethi/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/raghavsethi/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/raghavsethi/presto/teams","hooks_url":"https://api.github.com/repos/raghavsethi/presto/hooks","issue_events_url":"https://api.github.com/repos/raghavsethi/presto/issues/events{/number}","events_url":"https://api.github.com/repos/raghavsethi/presto/events","assignees_url":"https://api.github.com/repos/raghavsethi/presto/assignees{/user}","branches_url":"https://api.github.com/repos/raghavsethi/presto/branches{/branch}","tags_url":"https://api.github.com/repos/raghavsethi/presto/tags","blobs_url":"https://api.github.com/repos/raghavsethi/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/raghavsethi/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/raghavsethi/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/raghavsethi/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/raghavsethi/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/raghavsethi/presto/languages","stargazers_url":"https://api.github.com/repos/raghavsethi/presto/stargazers","contributors_url":"https://api.github.com/repos/raghavsethi/presto/contributors","subscribers_url":"https://api.github.com/repos/raghavsethi/presto/subscribers","subscription_url":"https://api.github.com/repos/raghavsethi/presto/subscription","commits_url":"https://api.github.com/repos/raghavsethi/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/raghavsethi/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/raghavsethi/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/raghavsethi/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/raghavsethi/presto/contents/{+path}","compare_url":"https://api.github.com/repos/raghavsethi/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/raghavsethi/presto/merges","archive_url":"https://api.github.com/repos/raghavsethi/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/raghavsethi/presto/downloads","issues_url":"https://api.github.com/repos/raghavsethi/presto/issues{/number}","pulls_url":"https://api.github.com/repos/raghavsethi/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/raghavsethi/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/raghavsethi/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/raghavsethi/presto/labels{/name}","releases_url":"https://api.github.com/repos/raghavsethi/presto/releases{/id}","created_at":"2015-09-11T20:28:31Z","updated_at":"2015-09-11T20:28:39Z","pushed_at":"2015-12-04T02:28:11Z","git_url":"git://github.com/raghavsethi/presto.git","ssh_url":"git@github.com:raghavsethi/presto.git","clone_url":"https://github.com/raghavsethi/presto.git","svn_url":"https://github.com/raghavsethi/presto","homepage":"https://prestodb.io","size":51954,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"76468809428da1af433cc14871b874482c5be9bd","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":5349565,"name":"presto","full_name":"facebook/presto","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/presto","description":"Distributed SQL query engine for running interactive analytic queries against big data sources.","fork":false,"url":"https://api.github.com/repos/facebook/presto","forks_url":"https://api.github.com/repos/facebook/presto/forks","keys_url":"https://api.github.com/repos/facebook/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/presto/teams","hooks_url":"https://api.github.com/repos/facebook/presto/hooks","issue_events_url":"https://api.github.com/repos/facebook/presto/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/presto/events","assignees_url":"https://api.github.com/repos/facebook/presto/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/presto/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/presto/tags","blobs_url":"https://api.github.com/repos/facebook/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/presto/languages","stargazers_url":"https://api.github.com/repos/facebook/presto/stargazers","contributors_url":"https://api.github.com/repos/facebook/presto/contributors","subscribers_url":"https://api.github.com/repos/facebook/presto/subscribers","subscription_url":"https://api.github.com/repos/facebook/presto/subscription","commits_url":"https://api.github.com/repos/facebook/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/presto/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/presto/merges","archive_url":"https://api.github.com/repos/facebook/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/presto/downloads","issues_url":"https://api.github.com/repos/facebook/presto/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/presto/labels{/name}","releases_url":"https://api.github.com/repos/facebook/presto/releases{/id}","created_at":"2012-08-09T01:03:37Z","updated_at":"2015-12-03T17:22:25Z","pushed_at":"2015-12-04T02:52:52Z","git_url":"git://github.com/facebook/presto.git","ssh_url":"git@github.com:facebook/presto.git","clone_url":"https://github.com/facebook/presto.git","svn_url":"https://github.com/facebook/presto","homepage":"https://prestodb.io","size":103736,"stargazers_count":4173,"watchers_count":4173,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1116,"mirror_url":null,"open_issues_count":402,"forks":1116,"open_issues":402,"watchers":4173,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/presto/pulls/4031"},"html":{"href":"https://github.com/facebook/presto/pull/4031"},"issue":{"href":"https://api.github.com/repos/facebook/presto/issues/4031"},"comments":{"href":"https://api.github.com/repos/facebook/presto/issues/4031/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/presto/pulls/4031/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/presto/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/presto/pulls/4031/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/presto/statuses/575d8f83352404c71bd7e8a680005d8994793915"}}}}