RabbidHY opened a new pull request #34334:
URL: https://github.com/apache/spark/pull/34334
### What changes were proposed in this pull request?
This pr pull out complex sorting expressions if it is global sorting to
reduce the evaluation of complex expressions. For example:
```sql
SELECT id AS a, id AS b FROM range(10) ORDER BY a - b
```
Before this pr:
```
== Physical Plan ==
AdaptiveSparkPlan isFinalPlan=false
+- Sort [(a#0L - b#1L) ASC NULLS FIRST], true, 0
+- Exchange rangepartitioning((a#0L - b#1L) ASC NULLS FIRST, 5),
ENSURE_REQUIREMENTS, [id=#12]
+- Project [id#2L AS a#0L, id#2L AS b#1L]
+- Range (0, 10, step=1, splits=2)
```
After this pr:
```
== Physical Plan ==
AdaptiveSparkPlan isFinalPlan=false
+- Project [a#0L, b#1L]
+- Sort [_sortingexpression#5L ASC NULLS FIRST], true, 0
+- Exchange rangepartitioning(_sortingexpression#5L ASC NULLS FIRST,
5), ENSURE_REQUIREMENTS, [id=#16]
+- Project [id#2L AS a#0L, id#2L AS b#1L, (id#2L - id#2L) AS
_sortingexpression#5L]
+- Range (0, 10, step=1, splits=2)
```
### Why are the changes needed?
Improve order performance if the sorting expressions contains complex
expressions.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Unit test and benchmark test:
```scala
import org.apache.spark.benchmark.Benchmark
val numRows = 1024 * 1024 * 10
spark.sql(s"CREATE TABLE t1 using parquet AS select id AS a, id AS b FROM
range(${numRows}L)")
val benchmark = new Benchmark("Benchmark pull out ordering expressions",
numRows, minNumIters = 5)
Seq(false, true).foreach { pullOutEnabled =>
val name = s"Pull out ordering expressions ${if (pullOutEnabled)
"(Enabled)" else "(Disabled)"}"
benchmark.addCase(name) { _ =>
withSQLConf("spark.sql.pullOutOrderingExpressions" ->
s"$pullOutEnabled") {
spark.sql("SELECT t1.* FROM t1 ORDER BY translate(t1.a, '123',
'abc')").write.format("noop").mode("Overwrite").save()
}
}
}
benchmark.run()
```
```
Java HotSpot(TM) 64-Bit Server VM 1.8.0_251-b08 on Mac OS X 10.15.7
Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Benchmark pull out ordering expressions: Best Time(ms) Avg Time(ms)
Stdev(ms) Rate(M/s) Per Row(ns) Relative
------------------------------------------------------------------------------------------------------------------------
Pull out ordering expressions (Disabled) 9232 9753
867 1.1 880.4 1.0X
Pull out ordering expressions (Enabled) 7084 7462
370 1.5 675.5 1.3X
```
--
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]