Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-35553 Improve correlated subqueries
  3. SPARK-36656

CollapseProject should not collapse correlated scalar subqueries

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.3.0
    • 3.3.0
    • SQL
    • None

    Description

      Currently, the optimizer rule `CollapseProject` inlines expressions generated from correlated scalar subqueries, which can create unnecessary left outer joins.

      select c1, s, s * 10 from (
      select c1, (select first(c2) from t2 where t1.c1 = t2.c1) s from t1)
      
      // Before
      Project [c1, s, (s * 10)]
      +- Project [c1, scalar-subquery [c1] AS s]
         :  +- Aggregate [c1], [first(c2), c1] 
         :      +- LocalRelation [c1, c2]
         +- LocalRelation [c1, c2]
      
      // After (scalar subqueries are inlined)
      Project [c1, scalar-subquery [c1], (scalar-subquery [c1] * 10)]
      :  +- Aggregate [c1], [first(c2), c1] 
      :      +- LocalRelation [c1, c2]
      :  +- Aggregate [c1], [first(c2), c1] 
      :      +- LocalRelation [c1, c2]
      +- LocalRelation [c1, c2]
      

      Then this query will have two LeftOuter joins created. We should only collapse projects after correlated subqueries are rewritten as joins.

      Attachments

        Activity

          People

            allisonwang-db Allison Wang
            allisonwang-db Allison Wang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: