GitHub user gatorsmile opened a pull request: https://github.com/apache/spark/pull/10476
[SPARK-12385] [SQL] [WIP] Push Projection into Join ```sql("SELECT * FROM testData JOIN testData2").explain(true)``` The current plan is like ``` == Analyzed Logical Plan == key: int, value: string, a: int, b: int Project [key#2,value#3,a#4,b#5] +- Join Inner, None :- Subquery testData : +- LogicalRDD [key#2,value#3], MapPartitionsRDD[3] at beforeAll at BeforeAndAfterAll.scala:187 +- Subquery testData2 +- LogicalRDD [a#4,b#5], MapPartitionsRDD[5] at beforeAll at BeforeAndAfterAll.scala:187 == Optimized Logical Plan == Project [key#2,value#3,a#4,b#5] +- Join Inner, None :- InMemoryRelation [key#2,value#3], true, 10000, StorageLevel(true, true, false, true, 1), ConvertToUnsafe, Some(testData) +- LogicalRDD [a#4,b#5], MapPartitionsRDD[5] at beforeAll at BeforeAndAfterAll.scala:187 ``` After this PR, the new plan does not have the unnecessary Project. ``` == Optimized Logical Plan == Join Inner, None :- InMemoryRelation [key#2,value#3], true, 10000, StorageLevel(true, true, false, true, 1), ConvertToUnsafe, Some(testData) +- LogicalRDD [a#4,b#5], MapPartitionsRDD[5] at beforeAll at BeforeAndAfterAll.scala:187 ``` However, it loses the ordering and alias information of attributes in `Projection`. This is just a preliminary work. If their `outputSet`s do not match, we still can push it into the `Join`, since the runtime/execution of Join will do the Projection. **Question**: Is that OK to add another field `projectList: Seq[NamedExpression]` into `Join` of `LogicalPlan`? Is this the right direction? Even more aggressively, we can add it into the `LogicalPlan` nodes? In the long term, should we push Projection into the other node types? Thank you! You can merge this pull request into a Git repository by running: $ git pull https://github.com/gatorsmile/spark combineProjectJoin Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/10476.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #10476 ---- commit ae408e8085b5777ef69206f37d5ece563b200926 Author: gatorsmile <gatorsm...@gmail.com> Date: 2015-12-25T06:17:53Z combine Project and Join. ---- --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org