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

Combine Limit and Sort to avoid total ordering

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.3.1
    • 1.4.2, 1.5.0
    • SQL
    • None

    Description

      Optimize following sql

      select key from (select * from testData order by key) t limit 5

      from

      == Parsed Logical Plan ==
      'Limit 5
      'Project ['key]
      'Subquery t
      'Sort ['key ASC], true
      'Project [*]
      'UnresolvedRelation [testData], None

      == Analyzed Logical Plan ==
      Limit 5
      Project key#0
      Subquery t
      Sort key#0 ASC, true
      Project key#0,value#1
      Subquery testData
      LogicalRDD key#0,value#1, MapPartitionsRDD[1]

      == Optimized Logical Plan ==
      Limit 5
      Project key#0
      Sort key#0 ASC, true
      LogicalRDD key#0,value#1, MapPartitionsRDD[1]
      == Physical Plan ==
      Limit 5
      Project key#0
      Sort key#0 ASC, true
      Exchange (RangePartitioning key#0 ASC, 5), []
      PhysicalRDD key#0,value#1, MapPartitionsRDD[1]

      to

      == Parsed Logical Plan ==
      'Limit 5
      'Project ['key]
      'Subquery t
      'Sort ['key ASC], true
      'Project [*]
      'UnresolvedRelation [testData], None

      == Analyzed Logical Plan ==
      Limit 5
      Project key#0
      Subquery t
      Sort key#0 ASC, true
      Project key#0,value#1
      Subquery testData
      LogicalRDD key#0,value#1, MapPartitionsRDD[1]

      == Optimized Logical Plan ==
      Project key#0
      Limit 5
      Sort key#0 ASC, true
      LogicalRDD key#0,value#1, MapPartitionsRDD[1]

      == Physical Plan ==
      Project key#0
      TakeOrdered 5, key#0 ASC
      PhysicalRDD key#0,value#1, MapPartitionsRDD[1]

      Attachments

        Activity

          People

            cloud_fan Wenchen Fan
            scwf Fei Wang
            Michael Armbrust Michael Armbrust
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: