kosiew commented on code in PR #22476:
URL: https://github.com/apache/datafusion/pull/22476#discussion_r3367392171


##########
datafusion/optimizer/src/optimize_projections/mod.rs:
##########
@@ -381,29 +379,12 @@ fn optimize_projections(
             // These operators have no inputs, so stop the optimization 
process.
             return Ok(Transformed::no(plan));
         }
-        LogicalPlan::RecursiveQuery(recursive) => {
-            // Only allow subqueries that reference the current CTE; nested 
subqueries are not yet
-            // supported for projection pushdown for simplicity.
-            // TODO: be able to do projection pushdown on recursive CTEs with 
subqueries
-            if plan_contains_other_subqueries(
-                recursive.static_term.as_ref(),
-                &recursive.name,
-            ) || plan_contains_other_subqueries(
-                recursive.recursive_term.as_ref(),
-                &recursive.name,
-            ) {
-                return Ok(Transformed::no(plan));
-            }
-
-            plan.inputs()
-                .into_iter()
-                .map(|input| {
-                    indices
-                        .clone()
-                        .with_projection_beneficial()
-                        .with_plan_exprs(&plan, input.schema())
-                })
-                .collect::<Result<Vec<_>>>()?
+        LogicalPlan::RecursiveQuery(_) => {
+            // optimize the static and recursive terms

Review Comment:
   Nice addition. This branch is encoding an important invariant: recursive CTE 
terms are optimization boundaries and should not inherit projection 
requirements from the parent plan.
   
   It may be worth making that a bit more explicit in the comment so the intent 
is clear to future readers. Something along the lines of:
   
   `// Treat each recursive CTE term like a standalone subquery: optimize its 
internals, but do not push parent required indices through the RecursiveQuery 
boundary.`
   
   That extra context could help prevent outer-column pruning from accidentally 
being reintroduced here later.



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