You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/01/23 05:52:07 UTC
[GitHub] [spark] wangyum opened a new pull request #35287: [SPARK-37989][SQL] Push down limit through Aggregate if it is group only
wangyum opened a new pull request #35287:
URL: https://github.com/apache/spark/pull/35287
### What changes were proposed in this pull request?
This pr add a new logical plan(`PartialDistinct`) to support partially deduplicate input rows and use it push down limit through Aggregate if it is group only.
For example:
```scala
spark.range(10000L).write.saveAsTable("t1")
spark.sql("SELECT DISTINCT * FROM t1 LIMIT 5").explain(true)
```
Before this pr:
```
== Optimized Logical Plan ==
GlobalLimit 5
+- LocalLimit 5
+- Aggregate [id#3L], [id#3L]
+- Relation default.t1[id#3L] parquet
```
After this pr:
```
== Optimized Logical Plan ==
GlobalLimit 5
+- LocalLimit 5
+- PartialDistinct
+- Relation default.t1[id#3L] parquet
```
### Why are the changes needed?
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on a change in pull request #35287: [SPARK-37989][SQL] Push down limit through Aggregate if it is group only
Posted by GitBox <gi...@apache.org>.
wangyum commented on a change in pull request #35287:
URL: https://github.com/apache/spark/pull/35287#discussion_r791255798
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -724,6 +724,16 @@ object LimitPushDown extends Rule[LogicalPlan] {
Limit(le, Project(a.output, LocalLimit(le, a.child)))
case Limit(le @ IntegerLiteral(1), p @ Project(_, a: Aggregate)) if a.groupOnly =>
Limit(le, p.copy(child = Project(a.output, LocalLimit(le, a.child))))
+ // Only push down when the limit number is less than or equal to 5000,
+ // which is the default_limit value of Hue.
+ case Limit(le @ IntegerLiteral(limit), a @ Aggregate(_, _, child))
+ if a.groupOnly && child.maxRowsPerPartition.forall(_ > limit) &&
+ limit <= math.min(conf.topKSortFallbackThreshold, 5000) =>
Review comment:
The maximum threshold is 5000 to benefit most SQL editors:
https://github.com/cloudera/hue/blob/release-4.10.0/desktop/conf.dist/hue.ini#L948-L949
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on pull request #35287: [SPARK-37989][SQL] Push down limit through Aggregate if it is group only
Posted by GitBox <gi...@apache.org>.
wangyum commented on pull request #35287:
URL: https://github.com/apache/spark/pull/35287#issuecomment-1021923766
cc @cloud-fan
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on a change in pull request #35287: [SPARK-37989][SQL] Push down limit through Aggregate if it is group only
Posted by GitBox <gi...@apache.org>.
wangyum commented on a change in pull request #35287:
URL: https://github.com/apache/spark/pull/35287#discussion_r791255798
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -724,6 +724,16 @@ object LimitPushDown extends Rule[LogicalPlan] {
Limit(le, Project(a.output, LocalLimit(le, a.child)))
case Limit(le @ IntegerLiteral(1), p @ Project(_, a: Aggregate)) if a.groupOnly =>
Limit(le, p.copy(child = Project(a.output, LocalLimit(le, a.child))))
+ // Only push down when the limit number is less than or equal to 5000,
+ // which is the default_limit value of Hue.
+ case Limit(le @ IntegerLiteral(limit), a @ Aggregate(_, _, child))
+ if a.groupOnly && child.maxRowsPerPartition.forall(_ > limit) &&
+ limit <= math.min(conf.topKSortFallbackThreshold, 5000) =>
Review comment:
The maximum threshold is 5000 to benefit most SQL editors:
https://github.com/cloudera/hue/blob/release-4.10.0/desktop/conf.dist/hue.ini#L948-L949
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on a change in pull request #35287: [SPARK-37989][SQL] Push down limit through Aggregate if it is group only
Posted by GitBox <gi...@apache.org>.
wangyum commented on a change in pull request #35287:
URL: https://github.com/apache/spark/pull/35287#discussion_r792357161
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -724,6 +724,16 @@ object LimitPushDown extends Rule[LogicalPlan] {
Limit(le, Project(a.aggregateExpressions, LocalLimit(le, a.child)))
case Limit(le @ IntegerLiteral(1), p @ Project(_, a: Aggregate)) if a.groupOnly =>
Limit(le, p.copy(child = Project(a.aggregateExpressions, LocalLimit(le, a.child))))
+ // Only push down when the limit number is less than or equal to 5000,
+ // which is the default_limit value of Hue.
+ case Limit(le @ IntegerLiteral(limit), a @ Aggregate(_, _, child))
+ if a.groupOnly && child.maxRowsPerPartition.forall(_ > limit) &&
+ limit <= math.min(conf.topKSortFallbackThreshold, 5000) =>
Review comment:
We do not push down all cases because number of limit rows need to do an extra `HashAggregate`. The maximum threshold is 5000 to benefit most SQL editors:
https://github.com/cloudera/hue/blob/release-4.10.0/desktop/conf.dist/hue.ini#L948-L949
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on a change in pull request #35287: [SPARK-37989][SQL] Push down limit through Aggregate if it is group only
Posted by GitBox <gi...@apache.org>.
wangyum commented on a change in pull request #35287:
URL: https://github.com/apache/spark/pull/35287#discussion_r791255798
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -724,6 +724,16 @@ object LimitPushDown extends Rule[LogicalPlan] {
Limit(le, Project(a.output, LocalLimit(le, a.child)))
case Limit(le @ IntegerLiteral(1), p @ Project(_, a: Aggregate)) if a.groupOnly =>
Limit(le, p.copy(child = Project(a.output, LocalLimit(le, a.child))))
+ // Only push down when the limit number is less than or equal to 5000,
+ // which is the default_limit value of Hue.
+ case Limit(le @ IntegerLiteral(limit), a @ Aggregate(_, _, child))
+ if a.groupOnly && child.maxRowsPerPartition.forall(_ > limit) &&
+ limit <= math.min(conf.topKSortFallbackThreshold, 5000) =>
Review comment:
The maximum threshold is 5000 to benefit most SQL editors:
https://github.com/cloudera/hue/blob/release-4.10.0/desktop/conf.dist/hue.ini#L948-L949
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org