From 09759d2bda8f4fdb30b3dbc21431510305550d94 Mon Sep 17 00:00:00 2001 From: kasiafi <30203062+kasiafi@users.noreply.github.com> Date: Fri, 10 May 2019 20:45:44 +0200 Subject: [PATCH] Ensure proper rule application order Before the change, the rule `ImplementOffsetOverOther` could be applied too early, and thus suppress creation of a mandatory SortNode in the resulting plan. --- .../java/io/prestosql/sql/planner/PlanOptimizers.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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(