diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java index 3beed014aac9109..da53781fdf6f95b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java @@ -464,6 +464,19 @@ public Boolean visitAbstractPhysicalSort(AbstractPhysicalSort so return true; } + @Override + public Boolean visitPhysicalTopN(PhysicalTopN topN, Void context) { + // process must shuffle + visit(topN, context); + + // If child is DistributionSpecGather, topN should forbid two-phase topN + if (topN.getSortPhase() == SortPhase.LOCAL_SORT + && childrenProperties.get(0).getDistributionSpec().equals(DistributionSpecGather.INSTANCE)) { + return false; + } + return true; + } + /** * check both side real output hash key order are same or not. *