diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala index 7801cd347f7dc..ddb6e3349d80d 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala @@ -623,11 +623,9 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]] * A variant of [[foreach]] which considers plan nodes inside subqueries as well. */ def foreachWithSubqueries(f: PlanType => Unit): Unit = { - def actualFunc(plan: PlanType): Unit = { - f(plan) - plan.subqueries.foreach(_.foreachWithSubqueries(f)) - } - foreach(actualFunc) + f(this) + subqueries.foreach(_.foreachWithSubqueries(f)) + children.foreach(_.foreachWithSubqueries(f)) } /**