@@ -39,20 +39,23 @@ object DefaultOptimizer extends Optimizer {
3939 Batch (" Distinct" , FixedPoint (100 ),
4040 ReplaceDistinctWithAggregate ) ::
4141 Batch (" Operator Optimizations" , FixedPoint (100 ),
42+ // Operator push down
4243 UnionPushDown ,
43- CombineFilters ,
44+ LimitPushDown ,
45+ PushPredicateThroughJoin ,
4446 PushPredicateThroughProject ,
4547 PushPredicateThroughGenerate ,
4648 ColumnPruning ,
47- LimitPushDown ,
49+ // Operator combine
4850 ProjectCollapsing ,
51+ CombineFilters ,
4952 CombineLimits ,
53+ // Constant folding
5054 NullPropagation ,
5155 OptimizeIn ,
5256 ConstantFolding ,
5357 LikeSimplification ,
5458 BooleanSimplification ,
55- PushPredicateThroughJoin ,
5659 RemovePositive ,
5760 SimplifyFilters ,
5861 SimplifyCasts ,
@@ -111,12 +114,14 @@ object UnionPushDown extends Rule[LogicalPlan] {
111114
112115object LimitPushDown extends Rule [LogicalPlan ] {
113116 def apply (plan : LogicalPlan ): LogicalPlan = plan transform {
114- // Push down limit when the child is project on limit
117+ // Push down limit when the child is project on limit.
115118 case Limit (expr, Project (projectList, l : Limit )) =>
116119 Project (projectList, Limit (expr, l))
117120
118- // Push down limit when the child is project on sort
119- case Limit (expr, Project (projectList, s : Sort )) =>
121+ // Push down limit when the child is project on sort,
122+ // and we cannot push down this project through sort.
123+ case Limit (expr, p @ Project (projectList, s : Sort ))
124+ if ! s.references.subsetOf(p.outputSet) =>
120125 Project (projectList, Limit (expr, s))
121126 }
122127}
0 commit comments