wangyum opened a new pull request, #40462:
URL: https://github.com/apache/spark/pull/40462
### What changes were proposed in this pull request?
This PR enhances `CollapseRepartition` to remove repartition if it is the
child of `LocalLimit`.
For example:
```sql
SELECT /*+ REBALANCE */ * FROM t WHERE id > 1 LIMIT 5;
```
Before this PR:
```
== Optimized Logical Plan ==
GlobalLimit 5
+- LocalLimit 5
+- RebalancePartitions
+- Filter (isnotnull(id#0L) AND (id#0L > 1))
+- Relation spark_catalog.default.t[id#0L] parquet
```
After this PR:
```
== Optimized Logical Plan ==
GlobalLimit 5
+- LocalLimit 5
+- Filter (isnotnull(id#0L) AND (id#0L > 1))
+- Relation spark_catalog.default.t[id#0L] parquet
```
Note that we don't remove repartition if it looks like the user might want
to get data randomly. For example:
```sql
SELECT /*+ REPARTITION(3) */ * FROM t WHERE id > 1 LIMIT 5;
SELECT * FROM t WHERE id > 1 DISTRIBUTE BY random() LIMIT 5;
```
### Why are the changes needed?
Reduce shuffle to improve query performance.
### 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]