cloud-fan commented on code in PR #37074: URL: https://github.com/apache/spark/pull/37074#discussion_r920151643
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala: ########## @@ -742,12 +742,28 @@ object ColumnPruning extends Rule[LogicalPlan] { * order, otherwise lower Projects can be missed. */ private def removeProjectBeforeFilter(plan: LogicalPlan): LogicalPlan = plan transformUp { - case p1 @ Project(_, f @ Filter(_, p2 @ Project(_, child))) + case p1 @ Project(_, f @ Filter(e, p2 @ Project(_, child))) if p2.outputSet.subsetOf(child.outputSet) && // We only remove attribute-only project. - p2.projectList.forall(_.isInstanceOf[AttributeReference]) => + p2.projectList.forall(_.isInstanceOf[AttributeReference]) && + !hasConflictingAttrsWithSubquery(e, child) => p1.copy(child = f.copy(child = child)) } + + private def hasConflictingAttrsWithSubquery(predicate: Expression, + child: LogicalPlan): Boolean = { + def hasConflictingAttrs(s: SubqueryExpression): Boolean = { + s.references.intersect(child.outputSet).nonEmpty + } + + splitConjunctivePredicates(predicate).exists { e => + e.find { + case s: ListQuery if hasConflictingAttrs(s) => true + case s: Exists if e.children.nonEmpty && hasConflictingAttrs(s) => true Review Comment: We can match `SubqueryExpression` directly. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org