[fix](Nereids) top-n with top project should hit top-n opt (#29971)

in PR #29312, we limit top-n opt only enable in simplest cases.
in this PR, we let go of some restrictions.
This commit is contained in:
morrySnow
2024-01-15 14:48:25 +08:00
committed by yiguolei
parent 9e30a67a2a
commit b99b9efda8

View File

@ -52,6 +52,14 @@ public class TopNScanOpt extends PlanPostProcessor {
public Plan visitPhysicalSink(PhysicalSink<? extends Plan> physicalSink, CascadesContext context) {
if (physicalSink.child() instanceof TopN) {
return super.visit(physicalSink, context);
} else if (physicalSink.child() instanceof Project && physicalSink.child().child(0) instanceof TopN) {
PhysicalTopN<?> oldTopN = (PhysicalTopN<?>) physicalSink.child().child(0);
PhysicalTopN<?> newTopN = (PhysicalTopN<?>) oldTopN.accept(this, context);
if (newTopN == oldTopN) {
return physicalSink;
} else {
return physicalSink.withChildren(physicalSink.child().withChildren(newTopN));
}
}
return physicalSink;
}