jiangzhx opened a new issue, #6673:
URL: https://github.com/apache/arrow-datafusion/issues/6673

   ### Describe the bug
   
   after i added a new optimizer EliminateSubqueryAliases #6666.
   got error when query :`select * from (select 1 as e) t1,   (select 1 as e) 
t2;`
   `Schema error: No field named t1.e.`
   
   I discovered that `push_down_projection` optimization deleted the 
`projection Int64(1) AS t1.e`, which caused the error.
   
   ```
   ❯ explain verbose select * from (select 1 as e) t1,   (select 1 as e) t2;
   
+------------------------------------------------------------+------------------------------------+
   | plan_type                                                  | plan          
                     |
   
+------------------------------------------------------------+------------------------------------+
   | initial_logical_plan                                       | Projection: 
t1.e, t2.e             |
   |                                                            |   CrossJoin:  
                     |
   |                                                            |     
SubqueryAlias: t1              |
   |                                                            |       
Projection: Int64(1) AS e    |
   |                                                            |         
EmptyRelation              |
   |                                                            |     
SubqueryAlias: t2              |
   |                                                            |       
Projection: Int64(1) AS e    |
   |                                                            |         
EmptyRelation              |
   | logical_plan after inline_table_scan                       | SAME TEXT AS 
ABOVE                 |
   | logical_plan after type_coercion                           | SAME TEXT AS 
ABOVE                 |
   | logical_plan after count_wildcard_rule                     | SAME TEXT AS 
ABOVE                 |
   | analyzed_logical_plan                                      | SAME TEXT AS 
ABOVE                 |
   | logical_plan after simplify_expressions                    | SAME TEXT AS 
ABOVE                 |
   | logical_plan after unwrap_cast_in_comparison               | SAME TEXT AS 
ABOVE                 |
   | logical_plan after replace_distinct_aggregate              | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_join                          | SAME TEXT AS 
ABOVE                 |
   | logical_plan after decorrelate_predicate_subquery          | SAME TEXT AS 
ABOVE                 |
   | logical_plan after scalar_subquery_to_join                 | SAME TEXT AS 
ABOVE                 |
   | logical_plan after extract_equijoin_predicate              | SAME TEXT AS 
ABOVE                 |
   | logical_plan after simplify_expressions                    | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_subquery_aliases              | Projection: 
t1.e, t2.e             |
   |                                                            |   CrossJoin:  
                     |
   |                                                            |     
Projection: e AS t1.e          |
   |                                                            |       
Projection: Int64(1) AS e    |
   |                                                            |         
EmptyRelation              |
   |                                                            |     
Projection: e AS t2.e          |
   |                                                            |       
Projection: Int64(1) AS e    |
   |                                                            |         
EmptyRelation              |
   | logical_plan after merge_projection                        | Projection: 
t1.e, t2.e             |
   |                                                            |   CrossJoin:  
                     |
   |                                                            |     
Projection: Int64(1) AS t1.e   |
   |                                                            |       
EmptyRelation                |
   |                                                            |     
Projection: Int64(1) AS t2.e   |
   |                                                            |       
EmptyRelation                |
   | logical_plan after rewrite_disjunctive_predicate           | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_duplicated_expr               | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_filter                        | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_cross_join                    | SAME TEXT AS 
ABOVE                 |
   | logical_plan after common_sub_expression_eliminate         | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_limit                         | SAME TEXT AS 
ABOVE                 |
   | logical_plan after propagate_empty_relation                | SAME TEXT AS 
ABOVE                 |
   | logical_plan after filter_null_join_keys                   | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_outer_join                    | SAME TEXT AS 
ABOVE                 |
   | logical_plan after push_down_limit                         | SAME TEXT AS 
ABOVE                 |
   | logical_plan after push_down_filter                        | SAME TEXT AS 
ABOVE                 |
   | logical_plan after single_distinct_aggregation_to_group_by | SAME TEXT AS 
ABOVE                 |
   | logical_plan after simplify_expressions                    | SAME TEXT AS 
ABOVE                 |
   | logical_plan after unwrap_cast_in_comparison               | SAME TEXT AS 
ABOVE                 |
   | logical_plan after common_sub_expression_eliminate         | SAME TEXT AS 
ABOVE                 |
   | logical_plan after push_down_projection                    | Projection: 
t1.e, t2.e             |
   |                                                            |   CrossJoin:  
                     |
   |                                                            |     
Projection:                    |
   |                                                            |       
EmptyRelation                |
   |                                                            |     
Projection:                    |
   |                                                            |       
EmptyRelation                |
   | logical_plan after eliminate_projection                    | Projection: 
t1.e, t2.e             |
   |                                                            |   CrossJoin:  
                     |
   |                                                            |     
EmptyRelation                  |
   |                                                            |     
EmptyRelation                  |
   | logical_plan after push_down_limit                         | SAME TEXT AS 
ABOVE                 |
   | logical_plan after simplify_expressions                    | SAME TEXT AS 
ABOVE                 |
   | logical_plan after unwrap_cast_in_comparison               | SAME TEXT AS 
ABOVE                 |
   | logical_plan after replace_distinct_aggregate              | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_join                          | SAME TEXT AS 
ABOVE                 |
   | logical_plan after decorrelate_predicate_subquery          | SAME TEXT AS 
ABOVE                 |
   | logical_plan after scalar_subquery_to_join                 | SAME TEXT AS 
ABOVE                 |
   | logical_plan after extract_equijoin_predicate              | SAME TEXT AS 
ABOVE                 |
   | logical_plan after simplify_expressions                    | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_subquery_aliases              | SAME TEXT AS 
ABOVE                 |
   | logical_plan after merge_projection                        | SAME TEXT AS 
ABOVE                 |
   | logical_plan after rewrite_disjunctive_predicate           | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_duplicated_expr               | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_filter                        | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_cross_join                    | SAME TEXT AS 
ABOVE                 |
   | logical_plan after common_sub_expression_eliminate         | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_limit                         | SAME TEXT AS 
ABOVE                 |
   | logical_plan after propagate_empty_relation                | SAME TEXT AS 
ABOVE                 |
   | logical_plan after filter_null_join_keys                   | SAME TEXT AS 
ABOVE                 |
   | logical_plan after eliminate_outer_join                    | SAME TEXT AS 
ABOVE                 |
   | logical_plan after push_down_limit                         | SAME TEXT AS 
ABOVE                 |
   | logical_plan after push_down_filter                        | SAME TEXT AS 
ABOVE                 |
   | logical_plan after single_distinct_aggregation_to_group_by | SAME TEXT AS 
ABOVE                 |
   | logical_plan after simplify_expressions                    | SAME TEXT AS 
ABOVE                 |
   | logical_plan after unwrap_cast_in_comparison               | SAME TEXT AS 
ABOVE                 |
   | logical_plan after common_sub_expression_eliminate         | SAME TEXT AS 
ABOVE                 |
   | logical_plan after push_down_projection                    | Projection: 
t1.e, t2.e             |
   |                                                            |   CrossJoin:  
                     |
   |                                                            |     
Projection:                    |
   |                                                            |       
EmptyRelation                |
   |                                                            |     
Projection:                    |
   |                                                            |       
EmptyRelation                |
   | logical_plan after eliminate_projection                    | Projection: 
t1.e, t2.e             |
   |                                                            |   CrossJoin:  
                     |
   |                                                            |     
EmptyRelation                  |
   |                                                            |     
EmptyRelation                  |
   | logical_plan after push_down_limit                         | SAME TEXT AS 
ABOVE                 |
   | logical_plan                                               | Projection: 
t1.e, t2.e             |
   |                                                            |   CrossJoin:  
                     |
   |                                                            |     
EmptyRelation                  |
   |                                                            |     
EmptyRelation                  |
   | initial_physical_plan                                      | Schema error: 
No field named t1.e. |
   
+------------------------------------------------------------+------------------------------------+
   ```
   
   ### To Reproduce
   
   test on https://github.com/apache/arrow-datafusion/pull/6666
   
   
   
   ### Expected behavior
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to