diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/PlanOptimizers.java b/core/trino-main/src/main/java/io/trino/sql/planner/PlanOptimizers.java index 67e07ff35036..410ab848f122 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/PlanOptimizers.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/PlanOptimizers.java @@ -378,6 +378,14 @@ public PlanOptimizers( new PushDownDereferencesThroughRowNumber(typeAnalyzer), new PushDownDereferencesThroughTopNRanking(typeAnalyzer)); + Set> limitPushdownRules = ImmutableSet.of( + new PushLimitThroughOffset(), + new PushLimitThroughProject(typeAnalyzer), + new PushLimitThroughMarkDistinct(), + new PushLimitThroughOuterJoin(), + new PushLimitThroughSemiJoin(), + new PushLimitThroughUnion()); + IterativeOptimizer inlineProjections = new IterativeOptimizer( metadata, ruleStats, @@ -445,6 +453,7 @@ public PlanOptimizers( ImmutableSet.>builder() .addAll(columnPruningRules) .addAll(projectionPushdownRules) + .addAll(limitPushdownRules) .addAll(new UnwrapRowSubscript().rules()) .addAll(new PushCastIntoRow().rules()) .addAll(ImmutableSet.of( @@ -458,16 +467,10 @@ public PlanOptimizers( new RemoveFullSample(), new EvaluateZeroSample(), new PushOffsetThroughProject(), - new PushLimitThroughOffset(), - new PushLimitThroughProject(typeAnalyzer), new MergeLimits(), new MergeLimitWithSort(), new MergeLimitOverProjectWithSort(), new MergeLimitWithTopN(), - new PushLimitThroughMarkDistinct(), - new PushLimitThroughOuterJoin(), - new PushLimitThroughSemiJoin(), - new PushLimitThroughUnion(), new RemoveTrivialFilters(), new RemoveRedundantLimit(), new RemoveRedundantOffset(),