diff --git a/presto-main/src/main/java/io/prestosql/sql/planner/PlanOptimizers.java b/presto-main/src/main/java/io/prestosql/sql/planner/PlanOptimizers.java index 52c726217981..34ff9932dd57 100644 --- a/presto-main/src/main/java/io/prestosql/sql/planner/PlanOptimizers.java +++ b/presto-main/src/main/java/io/prestosql/sql/planner/PlanOptimizers.java @@ -326,8 +326,14 @@ public PlanOptimizers( new ImplementOffsetOverTopN(), new ImplementOffsetOverProjectTopN(), new ImplementOffsetOverSort(), - new ImplementOffsetOverProjectSort(), - new ImplementOffsetOverOther())), + new ImplementOffsetOverProjectSort())), + new IterativeOptimizer( + ruleStats, + statsCalculator, + estimatedExchangesCostCalculator, + // Temporary hack: separate optimizer step to avoid a plan that's missing a SortNode over a RowNumber node + // if the rules fires too early + ImmutableSet.of(new ImplementOffsetOverOther())), simplifyOptimizer, new UnaliasSymbolReferences(), new IterativeOptimizer(