This is an automated email from the ASF dual-hosted git repository.

englefly pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new a7040dc28c8 [fix](nereids) fix topn-filter expr bug (#35832)
a7040dc28c8 is described below

commit a7040dc28c820da2b2511bfeff23c8836a311106
Author: minghong <[email protected]>
AuthorDate: Thu Jun 13 10:02:09 2024 +0800

    [fix](nereids) fix topn-filter expr bug (#35832)
    
    ## Proposed changes
    in previous version, topn-filter requires the first order key is a base
    table column. this restriction is abolished now
    
    Issue Number: close #xxx
    
    <!--Describe your changes.-->
---
 .../java/org/apache/doris/analysis/CastExpr.java   |  2 +-
 .../doris/nereids/processor/post/TopNScanOpt.java  | 26 +---------------------
 .../processor/post/TopnFilterPushDownVisitor.java  |  5 ++++-
 3 files changed, 6 insertions(+), 27 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
index ac871c72608..acd26dfb6f7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
@@ -120,7 +120,7 @@ public class CastExpr extends Expr {
      */
     public CastExpr(Type targetType, Expr e, Void v) {
         Preconditions.checkArgument(targetType.isValid());
-        Preconditions.checkNotNull(e);
+        Preconditions.checkNotNull(e, "cast child is null");
         opcode = TExprOpcode.CAST;
         type = targetType;
         targetTypeDef = null;
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopNScanOpt.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopNScanOpt.java
index fd3c794317d..60b4aa8ea59 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopNScanOpt.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopNScanOpt.java
@@ -23,14 +23,7 @@ import org.apache.doris.nereids.trees.expressions.Expression;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.SortPhase;
 import org.apache.doris.nereids.trees.plans.algebra.TopN;
-import 
org.apache.doris.nereids.trees.plans.physical.PhysicalDeferMaterializeOlapScan;
 import 
org.apache.doris.nereids.trees.plans.physical.PhysicalDeferMaterializeTopN;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalEsScan;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalFileScan;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalJdbcScan;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalOdbcScan;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalOlapScan;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalRelation;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalTopN;
 import org.apache.doris.qe.ConnectContext;
 
@@ -80,16 +73,8 @@ public class TopNScanOpt extends PlanPostProcessor {
         if (topNOptLimitThreshold == -1 || topN.getLimit() > 
topNOptLimitThreshold) {
             return false;
         }
-        // if firstKey's column is not present, it means the firstKey is not 
an original column from scan node
-        // for example: "select cast(k1 as INT) as id from tbl1 order by id 
limit 2;" the firstKey "id" is
-        // a cast expr which is not from tbl1 and its column is not present.
-        // On the other hand "select k1 as id from tbl1 order by id limit 2;" 
the firstKey "id" is just an alias of k1
-        // so its column is present which is valid for topN optimize
-        // see Alias::toSlot() method to get how column info is passed around 
by alias of slotReference
+
         Expression firstKey = topN.getOrderKeys().get(0).getExpr();
-        if (!firstKey.isColumnFromTable()) {
-            return false;
-        }
 
         if (firstKey.getDataType().isFloatType()
                 || firstKey.getDataType().isDoubleType()) {
@@ -118,13 +103,4 @@ public class TopNScanOpt extends PlanPostProcessor {
         }
         return -1;
     }
-
-    private boolean supportPhysicalRelations(PhysicalRelation relation) {
-        return relation instanceof PhysicalOlapScan
-                || relation instanceof PhysicalOdbcScan
-                || relation instanceof PhysicalEsScan
-                || relation instanceof PhysicalFileScan
-                || relation instanceof PhysicalJdbcScan
-                || relation instanceof PhysicalDeferMaterializeOlapScan;
-    }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopnFilterPushDownVisitor.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopnFilterPushDownVisitor.java
index 6962f3fddf2..8c9792b6751 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopnFilterPushDownVisitor.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopnFilterPushDownVisitor.java
@@ -41,6 +41,7 @@ import 
org.apache.doris.nereids.trees.plans.physical.PhysicalSetOperation;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalTopN;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalWindow;
 import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.nereids.types.VariantType;
 
 import com.google.common.collect.Maps;
 
@@ -214,7 +215,9 @@ public class TopnFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownCont
     public Boolean visitPhysicalRelation(PhysicalRelation relation, 
PushDownContext ctx) {
         if (supportPhysicalRelations(relation)
                 && 
relation.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())) {
-            if 
(relation.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())) {
+            if 
(relation.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())
+                    && ctx.probeExpr.getInputSlots().stream().noneMatch(
+                            slot -> slot.getDataType() instanceof 
VariantType)) {
                 topnFilterContext.addTopnFilter(ctx.topn, relation, 
ctx.probeExpr);
                 return true;
             }


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

Reply via email to