Github user sameeragarwal commented on a diff in the pull request:
    --- Diff: 
    @@ -74,14 +74,26 @@ abstract class QueryPlan[PlanType <: 
QueryPlan[PlanType]] extends TreeNode[PlanT
        * additional constraint of the form `b = 5`
       private def inferAdditionalConstraints(constraints: Set[Expression]): 
Set[Expression] = {
    +    // Collect alias from expressions to avoid producing non-converging 
set of constraints
    +    // for recursive functions.
    +    //
    +    // Don't apply transform on constraints if the attribute used to 
replace is an alias,
    +    // because then both `QueryPlan.inferAdditionalConstraints` and
    +    // `UnaryNode.getAliasedConstraints` applies and may produce a 
non-converging set of
    +    // constraints.
    +    // For more details, refer to
    +    val aliasSet = AttributeSet((expressions ++ 
children.flatMap(_.expressions)).collect {
    +      case a: Alias => a.toAttribute
    +    })
         var inferredConstraints = Set.empty[Expression]
         constraints.foreach {
           case eq @ EqualTo(l: Attribute, r: Attribute) =>
             inferredConstraints ++= (constraints - eq).map(_ transform {
    -          case a: Attribute if a.semanticEquals(l) => r
    +          case a: Attribute if a.semanticEquals(l) && 
!aliasSet.contains(r) => r
    --- End diff --
    @jiangxb1987 isn't this a fairly restrictive way to solve this problem? You 
are essentially not inferring any additional constraints from those that 
contain aliases. For e.g., if we have have a query `SELECT a AS a1, b AS b1 
WHERE a1 = 1 AND a1 = b1`, this change would never allow us to infer a 
filter/constraint on `b = 1`. Can we identify and just disallow recursive 

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 or file a JIRA ticket
with INFRA.

To unsubscribe, e-mail:
For additional commands, e-mail:

Reply via email to