AveryQi115 commented on code in PR #53664:
URL: https://github.com/apache/spark/pull/53664#discussion_r2796526046


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InlineCTE.scala:
##########
@@ -60,9 +60,20 @@ case class InlineCTE(
     // because:
     // 1) It is fine to inline a CTE if it references another CTE that is 
non-deterministic;
     // 2) Any `CTERelationRef` that contains `OuterReference` would have been 
inlined first.
+
+    def hasOuterReference(plan: LogicalPlan): Boolean = {
+      plan.exists {
+        case table: ResolvedInlineTable =>
+          // Check rows explicitly as they're not included in plan.expressions
+          table.rows.flatten.exists(_.isInstanceOf[OuterReference])

Review Comment:
   Are there inline chances if the outer references can be resolved as 
constants?
   
   For example,
   ```
   ...
   - ResolvedInlineTable(outerReference(a_param))
   Project(1 as a_param)
   ```
   I'm wondering if inlining can be done because this is a fake correlation and 
it will cause unnecessary join with empty conditions without inlining the 
constants. Maybe something similar to `ResolveUDTF` is doing 
[here](https://github.com/apache/spark/blob/4e1cb88bba0c031f54dd07e3adc0d464d45cbfce/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala#L2704)?



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