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

    https://github.com/apache/spark/pull/17186#discussion_r106166444
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/PruneFiltersSuite.scala
 ---
    @@ -133,4 +146,28 @@ class PruneFiltersSuite extends PlanTest {
         val correctAnswer = testRelation.where(Rand(10) > 5).where(Rand(10) > 
5).select('a).analyze
         comparePlans(optimized, correctAnswer)
       }
    +
    +  test("No pruning when constraint propagation is disabled") {
    +    val tr1 = LocalRelation('a.int, 'b.int, 'c.int).subquery('tr1)
    +    val tr2 = LocalRelation('a.int, 'd.int, 'e.int).subquery('tr2)
    +
    +    val query = tr1
    +      .where("tr1.a".attr > 10 || "tr1.c".attr < 10)
    +      .join(tr2.where('d.attr < 100), Inner, Some("tr1.a".attr === 
"tr2.a".attr))
    +
    +    val queryWithUselessFilter =
    +      query.where(
    +        ("tr1.a".attr > 10 || "tr1.c".attr < 10) &&
    +          'd.attr < 100)
    +
    +    val optimized = 
OptimizeDisableConstraintPropagation.execute(queryWithUselessFilter.analyze)
    +    // When constraint propagation is disabled, the useless filter won't 
be pruned.
    +    // It gets pushed down. Because the rule `CombineFilters` runs only 
once, there are redundant
    +    // and duplicate filters.
    --- End diff --
    
    This behaviour does not make sense to me. If I write a query like
    
    `select * from (select * from t1 where t1.a1 > 1) tx where tx.a1 > 1`
    
    I expect that Spark evaluates the predicate only once. The wording of 
"constraint propagation" is misleading. In this example, there is no activity 
of propagation at all. Perhaps we want to distinguish the "constraints" between 
the ones written originally and the ones that are inferred from relationships 
with other predicates. When the "propagation" (or perhaps a more meaningful 
term "predicate inference") is set to OFF, we want to exclude those inferred 
predicates in the `def constraints`.


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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to