Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-13235

Remove an Extra Distinct in Union

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.0.0
    • SQL
    • None

    Description

      Union Distinct has two Distinct that generate two Aggregation in the plan.

      sql("select * from t0 union select * from t0").explain(true)
      
      == Parsed Logical Plan ==
      'Project [unresolvedalias(*,None)]
      +- 'Subquery u_2
         +- 'Distinct
            +- 'Project [unresolvedalias(*,None)]
               +- 'Subquery u_1
                  +- 'Distinct
                     +- 'Union
                        :- 'Project [unresolvedalias(*,None)]
                        :  +- 'UnresolvedRelation `t0`, None
                        +- 'Project [unresolvedalias(*,None)]
                           +- 'UnresolvedRelation `t0`, None
      
      == Analyzed Logical Plan ==
      id: bigint
      Project [id#16L]
      +- Subquery u_2
         +- Distinct
            +- Project [id#16L]
               +- Subquery u_1
                  +- Distinct
                     +- Union
                        :- Project [id#16L]
                        :  +- Subquery t0
                        :     +- Relation[id#16L] ParquetRelation
                        +- Project [id#16L]
                           +- Subquery t0
                              +- Relation[id#16L] ParquetRelation
      
      == Optimized Logical Plan ==
      Aggregate [id#16L], [id#16L]
      +- Aggregate [id#16L], [id#16L]
         +- Union
            :- Project [id#16L]
            :  +- Relation[id#16L] ParquetRelation
            +- Project [id#16L]
               +- Relation[id#16L] ParquetRelation
      

      Attachments

        Issue Links

          Activity

            People

              smilegator Xiao Li
              smilegator Xiao Li
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: