Skip to content

Commit

Permalink
[enhancement](Nereids): rearrange Limit optimization rules (apache#26378
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jackwener authored and seawinde committed Nov 12, 2023
1 parent c2d57a7 commit f0af2af
Showing 1 changed file with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,19 @@ public class Rewriter extends AbstractBatchJobExecutor {
// ),

topic("Limit optimization",
// TODO: the logical plan should not contains any phase information,
// we should refactor like AggregateStrategies, e.g. LimitStrategies,
// generate one PhysicalLimit if current distribution is gather or two
// PhysicalLimits with gather exchange
topDown(new LimitSortToTopN()),
topDown(new SplitLimit()),
topDown(
// TODO: the logical plan should not contains any phase information,
// we should refactor like AggregateStrategies, e.g. LimitStrategies,
// generate one PhysicalLimit if current distribution is gather or two
// PhysicalLimits with gather exchange
new LimitSortToTopN(),
new SplitLimit(),
new PushdownLimit(),
new PushdownTopNThroughJoin(),
new PushdownLimitDistinctThroughJoin(),
new PushdownTopNThroughWindow(),
new CreatePartitionTopNFromWindow()
new PushdownTopNThroughWindow()
),
topDown(new CreatePartitionTopNFromWindow()),
topDown(
new PullUpProjectUnderTopN(),
new PullUpProjectUnderLimit()
Expand Down Expand Up @@ -323,16 +323,16 @@ public class Rewriter extends AbstractBatchJobExecutor {
topic("topn optimize",
topDown(new DeferMaterializeTopNResult())
),
topic("eliminate",
// SORT_PRUNING should be applied after mergeLimit
custom(RuleType.ELIMINATE_SORT, EliminateSort::new),
bottomUp(new EliminateEmptyRelation())
),
// this rule batch must keep at the end of rewrite to do some plan check
topic("Final rewrite and check",
custom(RuleType.CHECK_DATA_TYPES, CheckDataTypes::new),
custom(RuleType.ENSURE_PROJECT_ON_TOP_JOIN, EnsureProjectOnTopJoin::new),
topDown(
new PushdownFilterThroughProject(),
new MergeProjects()
),
// SORT_PRUNING should be applied after mergeLimit
custom(RuleType.ELIMINATE_SORT, EliminateSort::new),
topDown(new PushdownFilterThroughProject(), new MergeProjects()),
custom(RuleType.ADJUST_CONJUNCTS_RETURN_TYPE, AdjustConjunctsReturnType::new),
bottomUp(
new ExpressionRewrite(CheckLegalityAfterRewrite.INSTANCE),
Expand All @@ -346,10 +346,6 @@ public class Rewriter extends AbstractBatchJobExecutor {
new CollectFilterAboveConsumer(),
new CollectProjectAboveConsumer()
)
),

topic("eliminate empty relation",
bottomUp(new EliminateEmptyRelation())
)
);

Expand Down

0 comments on commit f0af2af

Please sign in to comment.