Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16785#discussion_r102364604
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
 ---
    @@ -314,7 +314,17 @@ abstract class UnaryNode extends LogicalPlan {
        * expressions with the corresponding alias
        */
       protected def getAliasedConstraints(projectList: Seq[NamedExpression]): 
Set[Expression] = {
    -    var allConstraints = child.constraints.asInstanceOf[Set[Expression]]
    +    val relativeReferences = AttributeSet(projectList.collect {
    +      case a: Alias => a
    +    }.flatMap(_.references)) ++ outputSet
    +
    +    // We only care about the constraints which refer to attributes in 
output and aliases.
    +    // For example, for a constraint 'a > b', if 'a' is aliased to 'c', we 
need to get aliased
    +    // constraint 'c > b' only if 'b' is in output.
    +    var allConstraints = child.constraints.filter { constraint =>
    +      constraint.references.subsetOf(relativeReferences)
    --- End diff --
    
    Yes. You can see the benchmark in the pr description. With pruning these 
attributes, the running time is cut half.
    
    If I understand your comment correctly, pruning them later in `QueryPlan` 
means we prune constraints which don't refer attributes in `outputSet`.
    
    But the pruning here is happened before the pruning you pointed out, we 
need to reduce the constraints taken for transforming aliasing attributes to 
lower the computation cost.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to