wangyum opened a new pull request #26409: [SPARK-29655][SQL] Enable adaptive execution should not add more ShuffleExchange URL: https://github.com/apache/spark/pull/26409 ### What changes were proposed in this pull request? In order to avoid frequently changing the value of `spark.sql.adaptive.shuffle.maxNumPostShufflePartitions`, we usually set `spark.sql.adaptive.shuffle.maxNumPostShufflePartitions` much larger than `spark.sql.shuffle.partitions` after enabling adaptive execution, which causes some bucket map join lose efficacy and add more `ShuffleExchange`. How to reproduce: ```scala spark.conf.set("spark.sql.autoBroadcastJoinThreshold", -1) spark.conf.set("spark.sql.shuffle.partitions", 4) spark.conf.set("spark.sql.adaptive.shuffle.maxNumPostShufflePartitions", 5) val bucketedTableName = "bucketed_table" spark.range(10).write.bucketBy(4, "id").sortBy("id").mode(org.apache.spark.sql.SaveMode.Overwrite).saveAsTable(bucketedTableName) val bucketedTable = spark.table(bucketedTableName) val df = spark.range(8) bucketedTable.join(df, "id").explain() spark.conf.set("spark.sql.adaptive.enabled", true) bucketedTable.join(df, "id").explain() ``` ``` scala> bucketedTable.join(df, "id").explain() == Physical Plan == *(4) Project [id#3L] +- *(4) SortMergeJoin [id#3L], [id#5L], Inner :- *(1) Sort [id#3L ASC NULLS FIRST], false, 0 : +- *(1) Project [id#3L] : +- *(1) Filter isnotnull(id#3L) : +- *(1) ColumnarToRow : +- FileScan parquet default.bucketed_table[id#3L] Batched: true, DataFilters: [isnotnull(id#3L)], Format: Parquet, Location: InMemoryFileIndex[file:/root/opensource/apache-spark/spark-3.0.0-SNAPSHOT-bin-2.7.4/spark-warehou..., PartitionFilters: [], PushedFilters: [IsNotNull(id)], ReadSchema: struct<id:bigint>, SelectedBucketsCount: 4 out of 4 +- *(3) Sort [id#5L ASC NULLS FIRST], false, 0 +- Exchange hashpartitioning(id#5L, 4), true, [id=#49] +- *(2) Range (0, 8, step=1, splits=16) ``` vs ``` scala> bucketedTable.join(df, "id").explain() == Physical Plan == AdaptiveSparkPlan(isFinalPlan=false) +- Project [id#3L] +- SortMergeJoin [id#3L], [id#5L], Inner :- Sort [id#3L ASC NULLS FIRST], false, 0 : +- Exchange hashpartitioning(id#3L, 5), true, [id=#93] : +- Project [id#3L] : +- Filter isnotnull(id#3L) : +- FileScan parquet default.bucketed_table[id#3L] Batched: true, DataFilters: [isnotnull(id#3L)], Format: Parquet, Location: InMemoryFileIndex[file:/root/opensource/apache-spark/spark-3.0.0-SNAPSHOT-bin-2.7.4/spark-warehou..., PartitionFilters: [], PushedFilters: [IsNotNull(id)], ReadSchema: struct<id:bigint>, SelectedBucketsCount: 4 out of 4 +- Sort [id#5L ASC NULLS FIRST], false, 0 +- Exchange hashpartitioning(id#5L, 5), true, [id=#92] +- Range (0, 8, step=1, splits=16) ``` This PR makes `targetNumPartitions` from `childrenNumPartitions.max` to `math.min(math.max(withoutShuffleChildrenNumPartitions.max, conf.numShufflePartitions), conf.maxNumPostShufflePartitions)` when doing ensureDistributionAndOrdering after enabling adaptive execution to avoid add more `ShuffleExchange`. ### Why are the changes needed? Do not degrade performance after enabling adaptive execution. ### 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
