morrySnow commented on code in PR #65569:
URL: https://github.com/apache/doris/pull/65569#discussion_r3602081835


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/materialize/LazyMaterializeTopN.java:
##########
@@ -19,301 +19,172 @@
 
 import org.apache.doris.catalog.AggregateType;
 import org.apache.doris.catalog.Column;
-import org.apache.doris.catalog.KeysType;
-import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.TableIf;
 import org.apache.doris.catalog.Type;
 import org.apache.doris.nereids.CascadesContext;
 import org.apache.doris.nereids.StatementContext;
 import org.apache.doris.nereids.processor.post.PlanPostProcessor;
 import org.apache.doris.nereids.processor.post.Validator;
-import org.apache.doris.nereids.trees.expressions.Alias;
 import org.apache.doris.nereids.trees.expressions.NamedExpression;
 import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.expressions.SlotReference;
 import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator;
 import org.apache.doris.nereids.trees.plans.AbstractPlan;
 import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.RelationId;
 import org.apache.doris.nereids.trees.plans.algebra.CatalogRelation;
 import org.apache.doris.nereids.trees.plans.algebra.Relation;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalCatalogRelation;
+import org.apache.doris.nereids.trees.plans.physical.AbstractPhysicalJoin;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalLazyMaterialize;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalProject;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalTVFRelation;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalTopN;
+import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanRewriter;
 import org.apache.doris.qe.SessionVariable;
 
-import com.google.common.collect.BiMap;
-import com.google.common.collect.HashBiMap;
 import com.google.common.collect.ImmutableList;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 import java.util.Set;
+import java.util.TreeMap;
 
 /**
  * Post rule to insert MaterializeNode for TopN lazy materialization.
- * Expression pull-up is handled by PullUpProjectExprUnderTopN in the logical 
phase.
+ * Expression pull-up is handled by PullUpProjectExprUnderTopN in the logical 
phase. That stage may only move
+ * expressions accepted by TopNLazyExpressionEligibility and must preserve 
their input slots below TopN. This
+ * physical stage never moves expressions; it resolves source lineage, chooses 
a fetch schedule, and rewrites slots.
+ *
+ * <p>Separate branches receive independent specs. For nested TopNs, the 
outermost eligible TopN wins so that
+ * materialization remains above the complete local/merge TopN chain. Inner 
TopNs are considered only when the
+ * outer candidate is not applicable.
  */
 public class LazyMaterializeTopN extends PlanPostProcessor {
     private static final Logger LOG = 
LogManager.getLogger(LazyMaterializeTopN.class);
-    private boolean hasMaterialized = false;
 
     @Override
     public Plan visitPhysicalTopN(PhysicalTopN<? extends Plan> topN, 
CascadesContext ctx) {
-        try {
-            Plan result = computeTopN(topN, ctx);
+        Plan result = computeTopN(topN);

Review Comment:
   The try-catch wrapping computeTopN has been removed. The old code at this 
level caught Exception and returned the original plan on failure, ensuring that 
any unexpected error would not fail the query. The new code removes this safety 
net. If computeTopN throws from invariant checks inside 
TopNLazyMaterializationSpec, the rewriter, or the analyzer (e.g., 
Preconditions.checkArgument failure), the exception propagates and can fail the 
query instead of gracefully falling back. Consider restoring a try-catch to 
preserve fault-tolerant behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to