{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/38926127","id":38926127,"diff_hunk":"@@ -267,12 +267,32 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] {\n   }\n \n   object CartesianProduct extends Strategy {\n+    def createCartesianProduct(left: LogicalPlan, right: LogicalPlan): SparkPlan = {\n+      // If plan can broadcast we use BroadcastNestedLoopJoin, as we know for inner join with true\n+      // condition is same as Cartesian.\n+      // For CartesianProduct we will use the small size plan as cartesian left rdd.\n+      if (right.statistics.sizeInBytes <= left.statistics.sizeInBytes) {\n+        right match {\n+          case CanBroadcast(right) => joins.BroadcastNestedLoopJoin(planLater(left),\n+              planLater(right), joins.BuildRight, Inner, None)\n+          case _ => execution.joins.CartesianProduct(planLater(left), planLater(right),\n+            joins.BuildRight)\n+        }\n+      } else {\n+        left match {\n+          case CanBroadcast(left) => joins.BroadcastNestedLoopJoin(planLater(left),\n+            planLater(right), joins.BuildLeft, Inner, None)","path":"sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala","position":18,"original_position":18,"commit_id":"8a8658cee375975d96685ec8ce90cab6eba777b5","original_commit_id":"8a8658cee375975d96685ec8ce90cab6eba777b5","user":{"login":"chenghao-intel","id":2367031,"avatar_url":"https://avatars.githubusercontent.com/u/2367031?v=3","gravatar_id":"","url":"https://api.github.com/users/chenghao-intel","html_url":"https://github.com/chenghao-intel","followers_url":"https://api.github.com/users/chenghao-intel/followers","following_url":"https://api.github.com/users/chenghao-intel/following{/other_user}","gists_url":"https://api.github.com/users/chenghao-intel/gists{/gist_id}","starred_url":"https://api.github.com/users/chenghao-intel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chenghao-intel/subscriptions","organizations_url":"https://api.github.com/users/chenghao-intel/orgs","repos_url":"https://api.github.com/users/chenghao-intel/repos","events_url":"https://api.github.com/users/chenghao-intel/events{/privacy}","received_events_url":"https://api.github.com/users/chenghao-intel/received_events","type":"User","site_admin":false},"body":"I think `BroadcastNestedLoopJoin` can support the condition, and push down the filter into the operator can also reduce the memory overhead, as `BroadcastNestedLoopJoin` will put all of the valid tuple into a compact buffer.","created_at":"2015-09-08T13:42:07Z","updated_at":"2015-09-08T13:42:07Z","html_url":"https://github.com/apache/spark/pull/7417#discussion_r38926127","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/7417","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/38926127"},"html":{"href":"https://github.com/apache/spark/pull/7417#discussion_r38926127"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/7417"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/7417","id":40002610,"html_url":"https://github.com/apache/spark/pull/7417","diff_url":"https://github.com/apache/spark/pull/7417.diff","patch_url":"https://github.com/apache/spark/pull/7417.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/7417","number":7417,"state":"open","locked":false,"title":"[SPARK-9066][SQL] Improve cartesian performance","user":{"login":"Sephiroth-Lin","id":10866770,"avatar_url":"https://avatars.githubusercontent.com/u/10866770?v=3","gravatar_id":"","url":"https://api.github.com/users/Sephiroth-Lin","html_url":"https://github.com/Sephiroth-Lin","followers_url":"https://api.github.com/users/Sephiroth-Lin/followers","following_url":"https://api.github.com/users/Sephiroth-Lin/following{/other_user}","gists_url":"https://api.github.com/users/Sephiroth-Lin/gists{/gist_id}","starred_url":"https://api.github.com/users/Sephiroth-Lin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sephiroth-Lin/subscriptions","organizations_url":"https://api.github.com/users/Sephiroth-Lin/orgs","repos_url":"https://api.github.com/users/Sephiroth-Lin/repos","events_url":"https://api.github.com/users/Sephiroth-Lin/events{/privacy}","received_events_url":"https://api.github.com/users/Sephiroth-Lin/received_events","type":"User","site_admin":false},"body":"see jira https://issues.apache.org/jira/browse/SPARK-9066\r\n\r\nuse tpc-ds to test, for below SQL clause:\r\n```\r\nwith single_value as (\r\n  select 1 tpcds_val from date_dim\r\n)\r\nselect sum(ss_quantity * ss_sales_price) ssales, tpcds_val\r\nfrom store_sales, single_value\r\ngroup by tpcds_val\r\n```\r\nuse this patch run1h55min, without this patch run half tasks use 16.7h\r\n\r\n@scwf ","created_at":"2015-07-15T09:19:55Z","updated_at":"2015-09-08T13:42:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"770f0871629a14f3e03f78d9e09d7229f8920f1e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/7417/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/7417/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/7417/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/8a8658cee375975d96685ec8ce90cab6eba777b5","head":{"label":"Sephiroth-Lin:SPARK-9066","ref":"SPARK-9066","sha":"8a8658cee375975d96685ec8ce90cab6eba777b5","user":{"login":"Sephiroth-Lin","id":10866770,"avatar_url":"https://avatars.githubusercontent.com/u/10866770?v=3","gravatar_id":"","url":"https://api.github.com/users/Sephiroth-Lin","html_url":"https://github.com/Sephiroth-Lin","followers_url":"https://api.github.com/users/Sephiroth-Lin/followers","following_url":"https://api.github.com/users/Sephiroth-Lin/following{/other_user}","gists_url":"https://api.github.com/users/Sephiroth-Lin/gists{/gist_id}","starred_url":"https://api.github.com/users/Sephiroth-Lin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sephiroth-Lin/subscriptions","organizations_url":"https://api.github.com/users/Sephiroth-Lin/orgs","repos_url":"https://api.github.com/users/Sephiroth-Lin/repos","events_url":"https://api.github.com/users/Sephiroth-Lin/events{/privacy}","received_events_url":"https://api.github.com/users/Sephiroth-Lin/received_events","type":"User","site_admin":false},"repo":{"id":30388176,"name":"spark","full_name":"Sephiroth-Lin/spark","owner":{"login":"Sephiroth-Lin","id":10866770,"avatar_url":"https://avatars.githubusercontent.com/u/10866770?v=3","gravatar_id":"","url":"https://api.github.com/users/Sephiroth-Lin","html_url":"https://github.com/Sephiroth-Lin","followers_url":"https://api.github.com/users/Sephiroth-Lin/followers","following_url":"https://api.github.com/users/Sephiroth-Lin/following{/other_user}","gists_url":"https://api.github.com/users/Sephiroth-Lin/gists{/gist_id}","starred_url":"https://api.github.com/users/Sephiroth-Lin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sephiroth-Lin/subscriptions","organizations_url":"https://api.github.com/users/Sephiroth-Lin/orgs","repos_url":"https://api.github.com/users/Sephiroth-Lin/repos","events_url":"https://api.github.com/users/Sephiroth-Lin/events{/privacy}","received_events_url":"https://api.github.com/users/Sephiroth-Lin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Sephiroth-Lin/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/Sephiroth-Lin/spark","forks_url":"https://api.github.com/repos/Sephiroth-Lin/spark/forks","keys_url":"https://api.github.com/repos/Sephiroth-Lin/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Sephiroth-Lin/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Sephiroth-Lin/spark/teams","hooks_url":"https://api.github.com/repos/Sephiroth-Lin/spark/hooks","issue_events_url":"https://api.github.com/repos/Sephiroth-Lin/spark/issues/events{/number}","events_url":"https://api.github.com/repos/Sephiroth-Lin/spark/events","assignees_url":"https://api.github.com/repos/Sephiroth-Lin/spark/assignees{/user}","branches_url":"https://api.github.com/repos/Sephiroth-Lin/spark/branches{/branch}","tags_url":"https://api.github.com/repos/Sephiroth-Lin/spark/tags","blobs_url":"https://api.github.com/repos/Sephiroth-Lin/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Sephiroth-Lin/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Sephiroth-Lin/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/Sephiroth-Lin/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Sephiroth-Lin/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/Sephiroth-Lin/spark/languages","stargazers_url":"https://api.github.com/repos/Sephiroth-Lin/spark/stargazers","contributors_url":"https://api.github.com/repos/Sephiroth-Lin/spark/contributors","subscribers_url":"https://api.github.com/repos/Sephiroth-Lin/spark/subscribers","subscription_url":"https://api.github.com/repos/Sephiroth-Lin/spark/subscription","commits_url":"https://api.github.com/repos/Sephiroth-Lin/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/Sephiroth-Lin/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/Sephiroth-Lin/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/Sephiroth-Lin/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/Sephiroth-Lin/spark/contents/{+path}","compare_url":"https://api.github.com/repos/Sephiroth-Lin/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Sephiroth-Lin/spark/merges","archive_url":"https://api.github.com/repos/Sephiroth-Lin/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Sephiroth-Lin/spark/downloads","issues_url":"https://api.github.com/repos/Sephiroth-Lin/spark/issues{/number}","pulls_url":"https://api.github.com/repos/Sephiroth-Lin/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/Sephiroth-Lin/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/Sephiroth-Lin/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Sephiroth-Lin/spark/labels{/name}","releases_url":"https://api.github.com/repos/Sephiroth-Lin/spark/releases{/id}","created_at":"2015-02-06T01:20:43Z","updated_at":"2015-02-06T01:21:00Z","pushed_at":"2015-09-08T13:06:08Z","git_url":"git://github.com/Sephiroth-Lin/spark.git","ssh_url":"git@github.com:Sephiroth-Lin/spark.git","clone_url":"https://github.com/Sephiroth-Lin/spark.git","svn_url":"https://github.com/Sephiroth-Lin/spark","homepage":null,"size":113639,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"5ffe752b59e468d55363f1f24b17a3677927ca8f","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-09-08T12:25:17Z","pushed_at":"2015-09-08T13:38:40Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1617029,"stargazers_count":5327,"watchers_count":5327,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4917,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":360,"forks":4917,"open_issues":360,"watchers":5327,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/7417"},"html":{"href":"https://github.com/apache/spark/pull/7417"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/7417"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/7417/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/7417/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/7417/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/8a8658cee375975d96685ec8ce90cab6eba777b5"}}}}