Github user gatorsmile commented on the pull request: https://github.com/apache/spark/pull/11658#issuecomment-195672850 ```SQL SELECT x.key, x.value, y.a, y.b, y.c, y.d FROM parquet_t1 x JOIN parquet_t2 y ON x.key = y.a ``` The generated SQL is ```SQL SELECT `gen_attr_30` AS `key`, `gen_attr_31` AS `value`, `gen_attr_32` AS `a`, `gen_attr_33` AS `b`, `gen_attr_34` AS `c`, `gen_attr_35` AS `d` FROM (SELECT `gen_attr_30`, `gen_attr_31`, `gen_attr_32`, `gen_attr_33`, `gen_attr_34`, `gen_attr_35` FROM (SELECT `key` AS `gen_attr_30`, `value` AS `gen_attr_31` FROM `default`.`parquet_t1`) AS gen_subquery_0 INNER JOIN (SELECT `a` AS `gen_attr_32`, `b` AS `gen_attr_33`, `c` AS `gen_attr_34`, `d` AS `gen_attr_35` FROM `default`.`parquet_t2`) AS gen_subquery_1 ON (`gen_attr_30` = `gen_attr_32`)) AS gen_subquery_2 ``` I compared the Optimized Logical Plan of these two queries: ``` Join Inner, Some((key#30L = a#32L)) :- Filter isnotnull(key#30L) : +- Relation[key#30L,value#31] ParquetFormat part: struct<>, data: struct<key:bigint,value:string> +- Filter isnotnull(a#32L) +- Relation[a#32L,b#33L,c#34L,d#35L] ParquetFormat part: struct<>, data: struct<a:bigint,b:bigint,c:bigint,d:bigint> ``` ``` Project [gen_attr_30#71L AS key#77L,gen_attr_31#72 AS value#78,gen_attr_32#73L AS a#79L,gen_attr_33#74L AS b#80L,gen_attr_34#75L AS c#81L,gen_attr_35#76L AS d#82L] +- Join Inner, Some((gen_attr_30#71L = gen_attr_32#73L)) :- Project [key#30L AS gen_attr_30#71L,value#31 AS gen_attr_31#72] : +- Filter isnotnull(key#30L) : +- Relation[key#30L,value#31] ParquetFormat part: struct<>, data: struct<key:bigint,value:string> +- Project [a#32L AS gen_attr_32#73L,b#33L AS gen_attr_33#74L,c#34L AS gen_attr_34#75L,d#35L AS gen_attr_35#76L] +- Filter isnotnull(a#32L) +- Relation[a#32L,b#33L,c#34L,d#35L] ParquetFormat part: struct<>, data: struct<a:bigint,b:bigint,c:bigint,d:bigint> ``` Here, we always add extra `Project`s in SQL generation. I am just thinking if we need to do it even if no name ambiguity exists?
--- 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