pan3793 commented on code in PR #58661:
URL: https://github.com/apache/spark/pull/58661#discussion_r3985564360


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InlineCTE.scala:
##########
@@ -77,15 +83,18 @@ case class InlineCTE(
   private def shouldInline(cteDef: CTERelationDef, refCount: Int): Boolean = {
     // A CTE definition that requests to skip inlining is never inlined, even 
in `alwaysInline`
     // mode, so that a producer can guarantee the CTE is materialized rather 
than duplicated.
-    !cteDef.forceSkipInline && (alwaysInline || {
-      // We do not need to check enclosed `CTERelationRef`s for 
`deterministic` or
-      // `OuterReference`, 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.
-      refCount == 1 ||
-        cteDef.deterministic ||
-        
cteDef.child.exists(_.expressions.exists(_.isInstanceOf[OuterReference]))
-    })
+    !cteDef.forceSkipInline && (alwaysInline || (cteDef.materialized match {

Review Comment:
   Widened in 82e5aee4caa to `forceSkipInline || materialized.contains(true)`, 
with a mirrored `InlineCTESuite` case. No change for SQL plans, which analysis 
already rejects; the guard stays a backstop for programmatic definitions.



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