dqkqd commented on PR #17852:
URL: https://github.com/apache/datafusion/pull/17852#issuecomment-3358384589

   I noticed that if I disable the `common_sub_expression_eliminate` rule, the 
optimizer will fail.
   (I'm not sure if this is the correct way to test, I think the optimizer 
rules should be optional, 
   and df should work even if some of them are disabled)
   
   ```diff
   diff --git a/datafusion/optimizer/src/optimizer.rs 
b/datafusion/optimizer/src/optimizer.rs
   index 084152d40..ca4a85692 100644
   --- a/datafusion/optimizer/src/optimizer.rs
   +++ b/datafusion/optimizer/src/optimizer.rs
   @@ -252,7 +252,7 @@ impl Optimizer {
                // The previous optimizations added expressions and projections,
                // that might benefit from the following rules
                Arc::new(EliminateGroupByConstant::new()),
   -            Arc::new(CommonSubexprEliminate::new()),
   +            // Arc::new(CommonSubexprEliminate::new()),
                Arc::new(OptimizeProjections::new()),
            ];
   ```
   
   ```
   DataFusion CLI v50.0.0
   > WITH suppliers AS (
     SELECT *
     FROM (VALUES (1, 10.0), (1, 20.0)) AS t(nation, acctbal)
   )
   SELECT
     ROW_NUMBER() OVER (PARTITION BY nation ORDER BY acctbal DESC) AS rn
   FROM suppliers AS s
   WHERE acctbal > (
     SELECT AVG(acctbal) FROM suppliers
   );
   Optimizer rule 'optimize_projections' failed
   caused by
   Schema error: No field named "row_number() PARTITION BY [s.nation] ORDER BY 
[s.acctbal DESC NULLS FIRST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT 
ROW". Valid fields are s.acctbal, __scalar_sq_1."avg(suppliers.acctbal)".
   >
   ```
   
   In fact, it fails if I disable everything in between `ScalarSubqueryToJoin` 
and `OptimizeProjections`.
   
   ```diff
   diff --git a/datafusion/optimizer/src/optimizer.rs 
b/datafusion/optimizer/src/optimizer.rs
   index 084152d40..684b01b88 100644
   --- a/datafusion/optimizer/src/optimizer.rs
   +++ b/datafusion/optimizer/src/optimizer.rs
   @@ -234,25 +234,25 @@ impl Optimizer {
                Arc::new(EliminateJoin::new()),
                Arc::new(DecorrelatePredicateSubquery::new()),
                Arc::new(ScalarSubqueryToJoin::new()),
   -            Arc::new(DecorrelateLateralJoin::new()),
   -            Arc::new(ExtractEquijoinPredicate::new()),
   -            Arc::new(EliminateDuplicatedExpr::new()),
   -            Arc::new(EliminateFilter::new()),
   -            Arc::new(EliminateCrossJoin::new()),
   -            Arc::new(EliminateLimit::new()),
   -            Arc::new(PropagateEmptyRelation::new()),
   -            // Must be after PropagateEmptyRelation
   -            Arc::new(EliminateOneUnion::new()),
   -            Arc::new(FilterNullJoinKeys::default()),
   -            Arc::new(EliminateOuterJoin::new()),
   -            // Filters can't be pushed down past Limits, we should do 
PushDownFilter after PushDownLimit
   -            Arc::new(PushDownLimit::new()),
   -            Arc::new(PushDownFilter::new()),
   -            Arc::new(SingleDistinctToGroupBy::new()),
   -            // The previous optimizations added expressions and projections,
   -            // that might benefit from the following rules
   -            Arc::new(EliminateGroupByConstant::new()),
   -            Arc::new(CommonSubexprEliminate::new()),
   +            // Arc::new(DecorrelateLateralJoin::new()),
   +            // Arc::new(ExtractEquijoinPredicate::new()),
   +            // Arc::new(EliminateDuplicatedExpr::new()),
   +            // Arc::new(EliminateFilter::new()),
   +            // Arc::new(EliminateCrossJoin::new()),
   +            // Arc::new(EliminateLimit::new()),
   +            // Arc::new(PropagateEmptyRelation::new()),
   +            // // Must be after PropagateEmptyRelation
   +            // Arc::new(EliminateOneUnion::new()),
   +            // Arc::new(FilterNullJoinKeys::default()),
   +            // Arc::new(EliminateOuterJoin::new()),
   +            // // Filters can't be pushed down past Limits, we should do 
PushDownFilter after PushDownLimit
   +            // Arc::new(PushDownLimit::new()),
   +            // Arc::new(PushDownFilter::new()),
   +            // Arc::new(SingleDistinctToGroupBy::new()),
   +            // // The previous optimizations added expressions and 
projections,
   +            // // that might benefit from the following rules
   +            // Arc::new(EliminateGroupByConstant::new()),
   +            // Arc::new(CommonSubexprEliminate::new()),
                Arc::new(OptimizeProjections::new()),
            ];
   
   ```


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to