Github user DoingDone9 commented on the pull request:

    https://github.com/apache/spark/pull/6351#issuecomment-104817104
  
    This optimizer can void CartesianProduct
    Tables
    ```
    tableA        tableB        tableC
    a   int       c    int      f    int    
    b   int       d    int      g    int
                  e    int
    ```
    
    SQL
    ```
    select * from tableA, tableB, tableC where (d = f and  a = c and b = d) or 
(d = f and a = c and b = e)
    ```
    
    Plan before modify
    ```
    == Optimized Logical Plan ==
    Project [a#306,b#307,c#308,d#309,e#310,f#311,g#312]
     Join Inner, Some((((d#309 = f#311) && (a#306 = c#308)) && ((b#307 = d#309) 
|| (b#307 = e#310))))
      Join Inner, None
       MetastoreRelation default, tablea, None
       MetastoreRelation default, tableb, None
      MetastoreRelation default, tablec, None
    
    == Physical Plan ==
    Project [a#306,b#307,c#308,d#309,e#310,f#311,g#312]
     Filter ((a#306 = c#308) && ((b#307 = d#309) || (b#307 = e#310)))
      ShuffledHashJoin [d#309], [f#311], BuildRight
       Exchange (HashPartitioning 5), []
        CartesianProduct
         HiveTableScan [a#306,b#307], (MetastoreRelation default, tablea, 
None), None
         HiveTableScan [c#308,d#309,e#310], (MetastoreRelation default, tableb, 
None), None
       Exchange (HashPartitioning 5), []
        HiveTableScan [f#311,g#312], (MetastoreRelation default, tablec, None), 
None
    ```
    
    Plan after modify
    ```
    == Optimized Logical Plan ==
    Project [a#306,b#307,c#308,d#309,e#310,f#311,g#312]
     Join Inner, Some((d#309 = f#311))
      Join Inner, Some(((a#306 = c#308) && ((b#307 = d#309) || (b#307 = 
e#310))))
       MetastoreRelation default, tablea, None
       MetastoreRelation default, tableb, None
      MetastoreRelation default, tablec, None
    
    == Physical Plan ==
    Project [a#306,b#307,c#308,d#309,e#310,f#311,g#312]
     ShuffledHashJoin [d#309], [f#311], BuildRight
      Exchange (HashPartitioning 5), []
       Filter ((b#307 = d#309) || (b#307 = e#310))
        ShuffledHashJoin [a#306], [c#308], BuildRight
         Exchange (HashPartitioning 5), []
          HiveTableScan [a#306,b#307], (MetastoreRelation default, tablea, 
None), None
         Exchange (HashPartitioning 5), []
          HiveTableScan [c#308,d#309,e#310], (MetastoreRelation default, 
tableb, None), None
      Exchange (HashPartitioning 5), []
       HiveTableScan [f#311,g#312], (MetastoreRelation default, tablec, None), 
None
    ```



---
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