wangyum opened a new pull request, #37104:
URL: https://github.com/apache/spark/pull/37104

   ### What changes were proposed in this pull request?
   
   Spark will set maxRows at runtime:
   
https://github.com/apache/spark/blob/bb6f65acca2918a0ceb13b612d210f1b46fa1add/sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/LogicalQueryStage.scala#L58
   
   This PR update `SpecialLimits` to use `TakeOrderedAndProject` if maxRows 
below the `spark.sql.execution.topKSortFallbackThreshold`. For example:
   ```sql
   create table t1 using parquet as select id, cast(id as string) as value from 
range(10);
   select * from (select distinct * from t1) order by id;
   ```
   The query plan:
   ```
   == Physical Plan ==
   AdaptiveSparkPlan (14)
   +- == Final Plan ==
      TakeOrderedAndProject (8)
      +- * HashAggregate (7)
         +- AQEShuffleRead (6)
            +- ShuffleQueryStage (5), Statistics(sizeInBytes=320.0 B, 
rowCount=10)
               +- Exchange (4)
                  +- * HashAggregate (3)
                     +- * ColumnarToRow (2)
                        +- Scan parquet spark_catalog.default.t1 (1)
   +- == Initial Plan ==
      Sort (13)
      +- Exchange (12)
         +- HashAggregate (11)
            +- Exchange (10)
               +- HashAggregate (9)
                  +- Scan parquet spark_catalog.default.t1 (1)
   ```
   
   ### Why are the changes needed?
   
   Improve query performance by reduce shuffle.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   Unit test.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to