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

starocean999 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 140eb7f49c6 [fix](nereids)AssertNumRow node's output should be 
nullable (#32136)
140eb7f49c6 is described below

commit 140eb7f49c60631411784b399544df7852eb15f0
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Fri Mar 15 17:07:27 2024 +0800

    [fix](nereids)AssertNumRow node's output should be nullable (#32136)
    
    Co-authored-by: Co-Author Jerry Hu <mrh...@gmail.com>
---
 be/src/pipeline/exec/assert_num_rows_operator.cpp  | 47 ++++++++++++--
 be/src/pipeline/exec/assert_num_rows_operator.h    |  1 +
 be/src/vec/exec/vassert_num_rows_node.cpp          | 47 ++++++++++++--
 be/src/vec/exec/vassert_num_rows_node.h            |  1 +
 .../glue/translator/PhysicalPlanTranslator.java    | 29 ++++++++-
 .../rules/rewrite/EliminateAssertNumRows.java      | 13 ++--
 .../nereids/rules/rewrite/ScalarApplyToJoin.java   |  7 +--
 .../trees/plans/logical/LogicalAssertNumRows.java  |  5 +-
 .../plans/physical/PhysicalAssertNumRows.java      |  5 +-
 .../apache/doris/planner/AssertNumRowsNode.java    | 22 ++++++-
 .../apache/doris/planner/StatisticDeriveTest.java  |  1 -
 gensrc/thrift/PlanNodes.thrift                     |  1 +
 .../data/nereids_p0/subquery/test_subquery.out     |  7 +++
 .../nereids_tpcds_shape_sf1000_p0/shape/query9.out | 73 +++++++++-------------
 .../noStatsRfPrune/query9.out                      | 73 +++++++++-------------
 .../no_stats_shape/query9.out                      | 73 +++++++++-------------
 .../rf_prune/query44.out                           | 71 ++++++++++-----------
 .../rf_prune/query9.out                            | 73 +++++++++-------------
 .../nereids_tpcds_shape_sf100_p0/shape/query44.out | 71 ++++++++++-----------
 .../nereids_tpcds_shape_sf100_p0/shape/query9.out  | 73 +++++++++-------------
 .../nereids_p0/subquery/test_subquery.groovy       | 23 ++++++-
 21 files changed, 392 insertions(+), 324 deletions(-)

diff --git a/be/src/pipeline/exec/assert_num_rows_operator.cpp 
b/be/src/pipeline/exec/assert_num_rows_operator.cpp
index c1db78e59b0..ef0efd3f86b 100644
--- a/be/src/pipeline/exec/assert_num_rows_operator.cpp
+++ b/be/src/pipeline/exec/assert_num_rows_operator.cpp
@@ -18,6 +18,7 @@
 #include "assert_num_rows_operator.h"
 
 #include "vec/exprs/vexpr_context.h"
+#include "vec/utils/util.hpp"
 
 namespace doris::pipeline {
 
@@ -35,6 +36,10 @@ AssertNumRowsOperatorX::AssertNumRowsOperatorX(ObjectPool* 
pool, const TPlanNode
     } else {
         _assertion = TAssertion::LE; // just compatible for the previous code
     }
+
+    _should_convert_output_to_nullable =
+            
tnode.assert_num_rows_node.__isset.should_convert_output_to_nullable &&
+            tnode.assert_num_rows_node.should_convert_output_to_nullable;
 }
 
 Status AssertNumRowsOperatorX::pull(doris::RuntimeState* state, 
vectorized::Block* block,
@@ -44,12 +49,14 @@ Status AssertNumRowsOperatorX::pull(doris::RuntimeState* 
state, vectorized::Bloc
     local_state.add_num_rows_returned(block->rows());
     int64_t num_rows_returned = local_state.num_rows_returned();
     bool assert_res = false;
+    const auto has_more_rows = !(*eos);
     switch (_assertion) {
     case TAssertion::EQ:
-        assert_res = num_rows_returned == _desired_num_rows;
+        assert_res = num_rows_returned == _desired_num_rows ||
+                     (has_more_rows && num_rows_returned < _desired_num_rows);
         break;
     case TAssertion::NE:
-        assert_res = num_rows_returned != _desired_num_rows;
+        assert_res = num_rows_returned != _desired_num_rows || (has_more_rows);
         break;
     case TAssertion::LT:
         assert_res = num_rows_returned < _desired_num_rows;
@@ -58,19 +65,47 @@ Status AssertNumRowsOperatorX::pull(doris::RuntimeState* 
state, vectorized::Bloc
         assert_res = num_rows_returned <= _desired_num_rows;
         break;
     case TAssertion::GT:
-        assert_res = num_rows_returned > _desired_num_rows;
+        assert_res = num_rows_returned > _desired_num_rows || has_more_rows;
         break;
     case TAssertion::GE:
-        assert_res = num_rows_returned >= _desired_num_rows;
+        assert_res = num_rows_returned >= _desired_num_rows || has_more_rows;
         break;
     default:
         break;
     }
 
+    /**
+     * For nereids planner:
+     * The output of `AssertNumRowsOperatorX` should be nullable.
+     * If the `num_rows_returned` is 0 and `_desired_num_rows` is 1,
+     * here need to insert one row of null.
+     */
+    if (_should_convert_output_to_nullable) {
+        if (block->rows() > 0) {
+            for (size_t i = 0; i != block->columns(); ++i) {
+                auto& data = block->get_by_position(i);
+                data.type = vectorized::make_nullable(data.type);
+                data.column = vectorized::make_nullable(data.column);
+            }
+        } else if (!has_more_rows && _assertion == TAssertion::EQ && 
num_rows_returned == 0 &&
+                   _desired_num_rows == 1) {
+            auto new_block =
+                    
vectorized::VectorizedUtils::create_columns_with_type_and_name(_row_descriptor);
+            block->swap(new_block);
+            for (size_t i = 0; i != block->columns(); ++i) {
+                auto& column = block->get_by_position(i).column;
+                auto& type = block->get_by_position(i).type;
+                type = vectorized::make_nullable(type);
+                column = type->create_column();
+                column->assume_mutable()->insert_default();
+            }
+            assert_res = true;
+        }
+    }
+
     if (!assert_res) {
         auto to_string_lambda = [](TAssertion::type assertion) {
-            std::map<int, const char*>::const_iterator it =
-                    _TAssertion_VALUES_TO_NAMES.find(assertion);
+            auto it = _TAssertion_VALUES_TO_NAMES.find(assertion);
 
             if (it == _TAggregationOp_VALUES_TO_NAMES.end()) {
                 return "NULL";
diff --git a/be/src/pipeline/exec/assert_num_rows_operator.h 
b/be/src/pipeline/exec/assert_num_rows_operator.h
index f3495b5bf9e..4d6d835f815 100644
--- a/be/src/pipeline/exec/assert_num_rows_operator.h
+++ b/be/src/pipeline/exec/assert_num_rows_operator.h
@@ -67,6 +67,7 @@ private:
     int64_t _desired_num_rows;
     const std::string _subquery_string;
     TAssertion::type _assertion;
+    bool _should_convert_output_to_nullable;
 };
 
 } // namespace pipeline
diff --git a/be/src/vec/exec/vassert_num_rows_node.cpp 
b/be/src/vec/exec/vassert_num_rows_node.cpp
index 9ef1166e2fb..4b65d6d52fb 100644
--- a/be/src/vec/exec/vassert_num_rows_node.cpp
+++ b/be/src/vec/exec/vassert_num_rows_node.cpp
@@ -30,6 +30,7 @@
 #include "runtime/runtime_state.h"
 #include "vec/core/block.h"
 #include "vec/exprs/vexpr_context.h"
+#include "vec/utils/util.hpp"
 
 namespace doris {
 class DescriptorTbl;
@@ -48,6 +49,10 @@ VAssertNumRowsNode::VAssertNumRowsNode(ObjectPool* pool, 
const TPlanNode& tnode,
     } else {
         _assertion = TAssertion::LE; // just compatible for the previous code
     }
+
+    _should_convert_output_to_nullable =
+            
tnode.assert_num_rows_node.__isset.should_convert_output_to_nullable &&
+            tnode.assert_num_rows_node.should_convert_output_to_nullable;
 }
 
 Status VAssertNumRowsNode::open(RuntimeState* state) {
@@ -61,12 +66,14 @@ Status VAssertNumRowsNode::open(RuntimeState* state) {
 Status VAssertNumRowsNode::pull(doris::RuntimeState* state, vectorized::Block* 
block, bool* eos) {
     _num_rows_returned += block->rows();
     bool assert_res = false;
+    const auto has_more_rows = !(*eos);
     switch (_assertion) {
     case TAssertion::EQ:
-        assert_res = _num_rows_returned == _desired_num_rows;
+        assert_res = _num_rows_returned == _desired_num_rows ||
+                     (has_more_rows && _num_rows_returned < _desired_num_rows);
         break;
     case TAssertion::NE:
-        assert_res = _num_rows_returned != _desired_num_rows;
+        assert_res = _num_rows_returned != _desired_num_rows || has_more_rows;
         break;
     case TAssertion::LT:
         assert_res = _num_rows_returned < _desired_num_rows;
@@ -75,19 +82,47 @@ Status VAssertNumRowsNode::pull(doris::RuntimeState* state, 
vectorized::Block* b
         assert_res = _num_rows_returned <= _desired_num_rows;
         break;
     case TAssertion::GT:
-        assert_res = _num_rows_returned > _desired_num_rows;
+        assert_res = _num_rows_returned > _desired_num_rows || has_more_rows;
         break;
     case TAssertion::GE:
-        assert_res = _num_rows_returned >= _desired_num_rows;
+        assert_res = _num_rows_returned >= _desired_num_rows || has_more_rows;
         break;
     default:
         break;
     }
 
+    /**
+     * For nereids planner:
+     * The output of `AssertNumRowsOperatorX` should be nullable.
+     * If the `_num_rows_returned` is 0 and `_desired_num_rows` is 1,
+     * here need to insert one row of null.
+     */
+    if (_should_convert_output_to_nullable) {
+        if (block->rows() > 0) {
+            for (size_t i = 0; i != block->columns(); ++i) {
+                auto& data = block->get_by_position(i);
+                data.type = vectorized::make_nullable(data.type);
+                data.column = vectorized::make_nullable(data.column);
+            }
+        } else if (!has_more_rows && _assertion == TAssertion::EQ && 
_num_rows_returned == 0 &&
+                   _desired_num_rows == 1) {
+            auto new_block =
+                    
vectorized::VectorizedUtils::create_columns_with_type_and_name(_row_descriptor);
+            block->swap(new_block);
+            for (size_t i = 0; i != block->columns(); ++i) {
+                auto& column = block->get_by_position(i).column;
+                auto& type = block->get_by_position(i).type;
+                type = vectorized::make_nullable(type);
+                column = type->create_column();
+                column->assume_mutable()->insert_default();
+            }
+            assert_res = true;
+        }
+    }
+
     if (!assert_res) {
         auto to_string_lambda = [](TAssertion::type assertion) {
-            std::map<int, const char*>::const_iterator it =
-                    _TAssertion_VALUES_TO_NAMES.find(assertion);
+            auto it = _TAssertion_VALUES_TO_NAMES.find(assertion);
 
             if (it == _TAggregationOp_VALUES_TO_NAMES.end()) {
                 return "NULL";
diff --git a/be/src/vec/exec/vassert_num_rows_node.h 
b/be/src/vec/exec/vassert_num_rows_node.h
index 90b74b0acb0..845f33e94cd 100644
--- a/be/src/vec/exec/vassert_num_rows_node.h
+++ b/be/src/vec/exec/vassert_num_rows_node.h
@@ -45,6 +45,7 @@ private:
     int64_t _desired_num_rows;
     const std::string _subquery_string;
     TAssertion::type _assertion;
+    bool _should_convert_output_to_nullable;
 };
 
 } // namespace doris::vectorized
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
index a482330c05f..6b02d3e7d34 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
@@ -1034,12 +1034,39 @@ public class PhysicalPlanTranslator extends 
DefaultPlanVisitor<PlanFragment, Pla
             PlanTranslatorContext context) {
         PlanFragment currentFragment = assertNumRows.child().accept(this, 
context);
         List<List<Expr>> distributeExprLists = 
getDistributeExprs(assertNumRows.child());
+
+        // we need convert all columns to nullable in AssertNumRows node
+        // create a tuple for AssertNumRowsNode
+        TupleDescriptor tupleDescriptor = context.generateTupleDesc();
         // create assertNode
         AssertNumRowsNode assertNumRowsNode = new 
AssertNumRowsNode(context.nextPlanNodeId(),
                 currentFragment.getPlanRoot(),
-                
ExpressionTranslator.translateAssert(assertNumRows.getAssertNumRowsElement()));
+                
ExpressionTranslator.translateAssert(assertNumRows.getAssertNumRowsElement()), 
true, tupleDescriptor);
         assertNumRowsNode.setChildrenDistributeExprLists(distributeExprLists);
         assertNumRowsNode.setNereidsId(assertNumRows.getId());
+
+        // collect all child output slots
+        List<TupleDescriptor> childTuples = 
context.getTupleDesc(currentFragment.getPlanRoot());
+        List<SlotDescriptor> childSlotDescriptors = childTuples.stream()
+                .map(TupleDescriptor::getSlots)
+                .flatMap(Collection::stream)
+                .collect(Collectors.toList());
+
+        // create output slot based on child output
+        Map<ExprId, SlotReference> childOutputMap = Maps.newHashMap();
+        assertNumRows.child().getOutput().stream()
+                .map(SlotReference.class::cast)
+                .forEach(s -> childOutputMap.put(s.getExprId(), s));
+        List<SlotDescriptor> slotDescriptors = Lists.newArrayList();
+        for (SlotDescriptor slot : childSlotDescriptors) {
+            SlotReference sf = 
childOutputMap.get(context.findExprId(slot.getId()));
+            SlotDescriptor sd = context.createSlotDesc(tupleDescriptor, sf, 
slot.getParent().getTable());
+            slotDescriptors.add(sd);
+        }
+
+        // set all output slot nullable
+        slotDescriptors.forEach(sd -> sd.setIsNullable(true));
+
         addPlanRoot(currentFragment, assertNumRowsNode, assertNumRows);
         return currentFragment;
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateAssertNumRows.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateAssertNumRows.java
index 84d459d30d9..e8d213db3e8 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateAssertNumRows.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateAssertNumRows.java
@@ -60,19 +60,22 @@ public class EliminateAssertNumRows extends 
OneRewriteRuleFactory {
 
     private boolean canEliminate(LogicalAssertNumRows<?> assertNumRows, Plan 
plan) {
         long maxOutputRowcount;
+        AssertNumRowsElement assertNumRowsElement = 
assertNumRows.getAssertNumRowsElement();
+        Assertion assertion = assertNumRowsElement.getAssertion();
+        long assertNum = assertNumRowsElement.getDesiredNumOfRows();
         // Don't need to consider TopN, because it's generated by Sort + Limit.
         if (plan instanceof LogicalLimit) {
             maxOutputRowcount = ((LogicalLimit<?>) plan).getLimit();
         } else if (plan instanceof LogicalAggregate && ((LogicalAggregate<?>) 
plan).getGroupByExpressions().isEmpty()) {
-            maxOutputRowcount = 1;
+            if (assertion == Assertion.EQ && assertNum == 1) {
+                return true;
+            } else {
+                maxOutputRowcount = 1;
+            }
         } else {
             return false;
         }
 
-        AssertNumRowsElement assertNumRowsElement = 
assertNumRows.getAssertNumRowsElement();
-        Assertion assertion = assertNumRowsElement.getAssertion();
-        long assertNum = assertNumRowsElement.getDesiredNumOfRows();
-
         switch (assertion) {
             case NE:
             case LT:
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ScalarApplyToJoin.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ScalarApplyToJoin.java
index e24e410f9e5..a7b2b9a2045 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ScalarApplyToJoin.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ScalarApplyToJoin.java
@@ -54,11 +54,8 @@ public class ScalarApplyToJoin extends OneRewriteRuleFactory 
{
     }
 
     private Plan unCorrelatedToJoin(LogicalApply apply) {
-        LogicalAssertNumRows assertNumRows = new LogicalAssertNumRows<>(
-                new AssertNumRowsElement(
-                        1, apply.getSubqueryExpr().toString(),
-                        apply.isInProject()
-                            ? AssertNumRowsElement.Assertion.EQ : 
AssertNumRowsElement.Assertion.LE),
+        LogicalAssertNumRows assertNumRows = new LogicalAssertNumRows<>(new 
AssertNumRowsElement(1,
+                apply.getSubqueryExpr().toString(), 
AssertNumRowsElement.Assertion.EQ),
                 (LogicalPlan) apply.right());
         return new LogicalJoin<>(JoinType.CROSS_JOIN,
                 ExpressionUtils.EMPTY_CONDITION,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAssertNumRows.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAssertNumRows.java
index 21c2a11e561..0279c9701ca 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAssertNumRows.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAssertNumRows.java
@@ -34,6 +34,7 @@ import com.google.common.collect.ImmutableList;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * Assert num rows node is used to determine whether the number of rows is 
less than desired num of rows.
@@ -115,8 +116,6 @@ public class LogicalAssertNumRows<CHILD_TYPE extends Plan> 
extends LogicalUnary<
 
     @Override
     public List<Slot> computeOutput() {
-        return ImmutableList.<Slot>builder()
-                .addAll(child().getOutput())
-                .build();
+        return child().getOutput().stream().map(o -> 
o.withNullable(true)).collect(Collectors.toList());
     }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalAssertNumRows.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalAssertNumRows.java
index be209c07f9e..ba03050c7af 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalAssertNumRows.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalAssertNumRows.java
@@ -35,6 +35,7 @@ import com.google.common.collect.ImmutableList;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * Physical assertNumRows.
@@ -59,9 +60,7 @@ public class PhysicalAssertNumRows<CHILD_TYPE extends Plan> 
extends PhysicalUnar
 
     @Override
     public List<Slot> computeOutput() {
-        return ImmutableList.<Slot>builder()
-                .addAll(child().getOutput())
-                .build();
+        return child().getOutput().stream().map(o -> 
o.withNullable(true)).collect(Collectors.toList());
     }
 
     public AssertNumRowsElement getAssertNumRowsElement() {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/AssertNumRowsNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/AssertNumRowsNode.java
index 0ae50ce0e4c..57d9ce8742f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/AssertNumRowsNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/AssertNumRowsNode.java
@@ -19,6 +19,7 @@ package org.apache.doris.planner;
 
 import org.apache.doris.analysis.Analyzer;
 import org.apache.doris.analysis.AssertNumRowsElement;
+import org.apache.doris.analysis.TupleDescriptor;
 import org.apache.doris.common.UserException;
 import org.apache.doris.statistics.StatisticalType;
 import org.apache.doris.statistics.StatsRecursiveDerive;
@@ -43,21 +44,35 @@ public class AssertNumRowsNode extends PlanNode {
     private String subqueryString;
     private AssertNumRowsElement.Assertion assertion;
 
+    private boolean shouldConvertOutputToNullable = false;
+
     public AssertNumRowsNode(PlanNodeId id, PlanNode input, 
AssertNumRowsElement assertNumRowsElement) {
+        this(id, input, assertNumRowsElement, false, null);
+    }
+
+    public AssertNumRowsNode(PlanNodeId id, PlanNode input, 
AssertNumRowsElement assertNumRowsElement,
+                             boolean convertToNullable, TupleDescriptor 
tupleDescriptor) {
         super(id, "ASSERT NUMBER OF ROWS", 
StatisticalType.ASSERT_NUM_ROWS_NODE);
         this.desiredNumOfRows = assertNumRowsElement.getDesiredNumOfRows();
         this.subqueryString = assertNumRowsElement.getSubqueryString();
         this.assertion = assertNumRowsElement.getAssertion();
         this.children.add(input);
-        if (input.getOutputTupleDesc() != null) {
-            this.tupleIds.add(input.getOutputTupleDesc().getId());
+        if (tupleDescriptor != null) {
+            this.tupleIds.add(tupleDescriptor.getId());
         } else {
-            this.tupleIds.addAll(input.getTupleIds());
+            if (input.getOutputTupleDesc() != null) {
+                this.tupleIds.add(input.getOutputTupleDesc().getId());
+            } else {
+                this.tupleIds.addAll(input.getTupleIds());
+            }
         }
+
         this.tblRefIds.addAll(input.getTblRefIds());
         this.nullableTupleIds.addAll(input.getNullableTupleIds());
+        this.shouldConvertOutputToNullable = convertToNullable;
     }
 
+
     @Override
     public void init(Analyzer analyzer) throws UserException {
         super.init(analyzer);
@@ -94,6 +109,7 @@ public class AssertNumRowsNode extends PlanNode {
         msg.assert_num_rows_node.setDesiredNumRows(desiredNumOfRows);
         msg.assert_num_rows_node.setSubqueryString(subqueryString);
         msg.assert_num_rows_node.setAssertion(assertion.toThrift());
+        
msg.assert_num_rows_node.setShouldConvertOutputToNullable(shouldConvertOutputToNullable);
     }
 
     @Override
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/planner/StatisticDeriveTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/planner/StatisticDeriveTest.java
index 359a99d27b7..0b2ba756b1d 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/StatisticDeriveTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/StatisticDeriveTest.java
@@ -164,7 +164,6 @@ public class StatisticDeriveTest extends TestWithFeService {
         Assert.assertNotEquals(0, 
stmtExecutor.planner().getFragments().size());
         System.out.println(getSQLPlanOrErrorMsg("explain " + sql));
         assertSQLPlanOrErrorMsgContains(sql, "NESTED LOOP JOIN");
-        assertSQLPlanOrErrorMsgContains(sql, "ASSERT NUMBER OF ROWS");
         assertSQLPlanOrErrorMsgContains(sql, "EXCHANGE");
         assertSQLPlanOrErrorMsgContains(sql, "AGGREGATE");
         assertSQLPlanOrErrorMsgContains(sql, "OlapScanNode");
diff --git a/gensrc/thrift/PlanNodes.thrift b/gensrc/thrift/PlanNodes.thrift
index 81d1d923375..2d5e8bb7bb9 100644
--- a/gensrc/thrift/PlanNodes.thrift
+++ b/gensrc/thrift/PlanNodes.thrift
@@ -1136,6 +1136,7 @@ struct TAssertNumRowsNode {
     1: optional i64 desired_num_rows;
     2: optional string subquery_string;
     3: optional TAssertion assertion;
+    4: optional bool should_convert_output_to_nullable;
 }
 
 enum TRuntimeFilterType {
diff --git a/regression-test/data/nereids_p0/subquery/test_subquery.out 
b/regression-test/data/nereids_p0/subquery/test_subquery.out
index a8d6064680d..166714f43dd 100644
--- a/regression-test/data/nereids_p0/subquery/test_subquery.out
+++ b/regression-test/data/nereids_p0/subquery/test_subquery.out
@@ -33,3 +33,10 @@ true 15      1992    3021    11011920        0.000   true    
9999-12-12      2015-04-02T00:00                3.141592653     2
 -- !select_sub2 --
 9
 
+-- !select_assert_num_row --
+3      l       0
+3      s       5
+2              6
+\N             8
+5              9
+
diff --git 
a/regression-test/data/nereids_tpcds_shape_sf1000_p0/shape/query9.out 
b/regression-test/data/nereids_tpcds_shape_sf1000_p0/shape/query9.out
index 6f64f57ee2d..4ccfb2a4e34 100644
--- a/regression-test/data/nereids_tpcds_shape_sf1000_p0/shape/query9.out
+++ b/regression-test/data/nereids_tpcds_shape_sf1000_p0/shape/query9.out
@@ -23,123 +23,108 @@ PhysicalResultSink
 ----------------------------------------filter((reason.r_reason_sk = 1))
 ------------------------------------------PhysicalOlapScan[reason]
 
--------------------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------------------PhysicalAssertNumRows
-------------------------------------------hashAgg[GLOBAL]
---------------------------------------------PhysicalDistribute[DistributionSpecGather]
-----------------------------------------------hashAgg[LOCAL]
-------------------------------------------------PhysicalProject
---------------------------------------------------filter((store_sales.ss_quantity
 <= 20) and (store_sales.ss_quantity >= 1))
-----------------------------------------------------PhysicalOlapScan[store_sales]
+----------------------------------------hashAgg[GLOBAL]
+------------------------------------------PhysicalDistribute[DistributionSpecGather]
+--------------------------------------------hashAgg[LOCAL]
+----------------------------------------------PhysicalProject
+------------------------------------------------filter((store_sales.ss_quantity
 <= 20) and (store_sales.ss_quantity >= 1))
+--------------------------------------------------PhysicalOlapScan[store_sales]
 
----------------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------------PhysicalAssertNumRows
---------------------------------------hashAgg[GLOBAL]
-----------------------------------------PhysicalDistribute[DistributionSpecGather]
-------------------------------------------hashAgg[LOCAL]
---------------------------------------------PhysicalProject
-----------------------------------------------filter((store_sales.ss_quantity 
<= 20) and (store_sales.ss_quantity >= 1))
-------------------------------------------------PhysicalOlapScan[store_sales]
---------------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------------PhysicalAssertNumRows
 ------------------------------------hashAgg[GLOBAL]
 
--------------------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------------------hashAgg[LOCAL]
 ------------------------------------------PhysicalProject
 --------------------------------------------filter((store_sales.ss_quantity <= 
20) and (store_sales.ss_quantity >= 1))
 ----------------------------------------------PhysicalOlapScan[store_sales]
-------------------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------------------PhysicalAssertNumRows
+--------------------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------------------hashAgg[GLOBAL]
 ------------------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------------------hashAgg[LOCAL]
 ----------------------------------------PhysicalProject
-------------------------------------------filter((store_sales.ss_quantity <= 
40) and (store_sales.ss_quantity >= 21))
+------------------------------------------filter((store_sales.ss_quantity <= 
20) and (store_sales.ss_quantity >= 1))
 --------------------------------------------PhysicalOlapScan[store_sales]
-----------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------PhysicalAssertNumRows
+------------------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------------------hashAgg[GLOBAL]
 ----------------------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------------------hashAgg[LOCAL]
 --------------------------------------PhysicalProject
 ----------------------------------------filter((store_sales.ss_quantity <= 40) 
and (store_sales.ss_quantity >= 21))
 ------------------------------------------PhysicalOlapScan[store_sales]
---------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------PhysicalAssertNumRows
+----------------------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------------------hashAgg[GLOBAL]
 --------------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------------hashAgg[LOCAL]
 ------------------------------------PhysicalProject
 --------------------------------------filter((store_sales.ss_quantity <= 40) 
and (store_sales.ss_quantity >= 21))
 ----------------------------------------PhysicalOlapScan[store_sales]
-------------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------------PhysicalAssertNumRows
+--------------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------------hashAgg[GLOBAL]
 ------------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------------hashAgg[LOCAL]
 ----------------------------------PhysicalProject
-------------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
+------------------------------------filter((store_sales.ss_quantity <= 40) and 
(store_sales.ss_quantity >= 21))
 --------------------------------------PhysicalOlapScan[store_sales]
-----------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------PhysicalAssertNumRows
+------------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------------hashAgg[GLOBAL]
 ----------------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------------hashAgg[LOCAL]
 --------------------------------PhysicalProject
 ----------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 ------------------------------------PhysicalOlapScan[store_sales]
---------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------PhysicalAssertNumRows
+----------------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------------hashAgg[GLOBAL]
 --------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------hashAgg[LOCAL]
 ------------------------------PhysicalProject
 --------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 ----------------------------------PhysicalOlapScan[store_sales]
-------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------PhysicalAssertNumRows
+--------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------hashAgg[GLOBAL]
 ------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
+------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 --------------------------------PhysicalOlapScan[store_sales]
-----------------PhysicalDistribute[DistributionSpecReplicated]
-------------------PhysicalAssertNumRows
+------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------hashAgg[GLOBAL]
 ----------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------hashAgg[LOCAL]
 --------------------------PhysicalProject
 ----------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 ------------------------------PhysicalOlapScan[store_sales]
---------------PhysicalDistribute[DistributionSpecReplicated]
-----------------PhysicalAssertNumRows
+----------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------hashAgg[GLOBAL]
 --------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------hashAgg[LOCAL]
 ------------------------PhysicalProject
 --------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 ----------------------------PhysicalOlapScan[store_sales]
-------------PhysicalDistribute[DistributionSpecReplicated]
---------------PhysicalAssertNumRows
+--------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------hashAgg[GLOBAL]
 ------------------PhysicalDistribute[DistributionSpecGather]
 --------------------hashAgg[LOCAL]
 ----------------------PhysicalProject
-------------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
+------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 --------------------------PhysicalOlapScan[store_sales]
-----------PhysicalDistribute[DistributionSpecReplicated]
-------------PhysicalAssertNumRows
+------------PhysicalDistribute[DistributionSpecReplicated]
 --------------hashAgg[GLOBAL]
 ----------------PhysicalDistribute[DistributionSpecGather]
 ------------------hashAgg[LOCAL]
 --------------------PhysicalProject
 ----------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
 ------------------------PhysicalOlapScan[store_sales]
---------PhysicalDistribute[DistributionSpecReplicated]
-----------PhysicalAssertNumRows
+----------PhysicalDistribute[DistributionSpecReplicated]
 ------------hashAgg[GLOBAL]
 --------------PhysicalDistribute[DistributionSpecGather]
 ----------------hashAgg[LOCAL]
 ------------------PhysicalProject
 --------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
 ----------------------PhysicalOlapScan[store_sales]
+--------PhysicalDistribute[DistributionSpecReplicated]
+----------hashAgg[GLOBAL]
+------------PhysicalDistribute[DistributionSpecGather]
+--------------hashAgg[LOCAL]
+----------------PhysicalProject
+------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
+--------------------PhysicalOlapScan[store_sales]
 
diff --git 
a/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query9.out 
b/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query9.out
index 6f64f57ee2d..4ccfb2a4e34 100644
--- 
a/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query9.out
+++ 
b/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query9.out
@@ -23,123 +23,108 @@ PhysicalResultSink
 ----------------------------------------filter((reason.r_reason_sk = 1))
 ------------------------------------------PhysicalOlapScan[reason]
 
--------------------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------------------PhysicalAssertNumRows
-------------------------------------------hashAgg[GLOBAL]
---------------------------------------------PhysicalDistribute[DistributionSpecGather]
-----------------------------------------------hashAgg[LOCAL]
-------------------------------------------------PhysicalProject
---------------------------------------------------filter((store_sales.ss_quantity
 <= 20) and (store_sales.ss_quantity >= 1))
-----------------------------------------------------PhysicalOlapScan[store_sales]
+----------------------------------------hashAgg[GLOBAL]
+------------------------------------------PhysicalDistribute[DistributionSpecGather]
+--------------------------------------------hashAgg[LOCAL]
+----------------------------------------------PhysicalProject
+------------------------------------------------filter((store_sales.ss_quantity
 <= 20) and (store_sales.ss_quantity >= 1))
+--------------------------------------------------PhysicalOlapScan[store_sales]
 
----------------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------------PhysicalAssertNumRows
---------------------------------------hashAgg[GLOBAL]
-----------------------------------------PhysicalDistribute[DistributionSpecGather]
-------------------------------------------hashAgg[LOCAL]
---------------------------------------------PhysicalProject
-----------------------------------------------filter((store_sales.ss_quantity 
<= 20) and (store_sales.ss_quantity >= 1))
-------------------------------------------------PhysicalOlapScan[store_sales]
---------------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------------PhysicalAssertNumRows
 ------------------------------------hashAgg[GLOBAL]
 
--------------------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------------------hashAgg[LOCAL]
 ------------------------------------------PhysicalProject
 --------------------------------------------filter((store_sales.ss_quantity <= 
20) and (store_sales.ss_quantity >= 1))
 ----------------------------------------------PhysicalOlapScan[store_sales]
-------------------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------------------PhysicalAssertNumRows
+--------------------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------------------hashAgg[GLOBAL]
 ------------------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------------------hashAgg[LOCAL]
 ----------------------------------------PhysicalProject
-------------------------------------------filter((store_sales.ss_quantity <= 
40) and (store_sales.ss_quantity >= 21))
+------------------------------------------filter((store_sales.ss_quantity <= 
20) and (store_sales.ss_quantity >= 1))
 --------------------------------------------PhysicalOlapScan[store_sales]
-----------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------PhysicalAssertNumRows
+------------------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------------------hashAgg[GLOBAL]
 ----------------------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------------------hashAgg[LOCAL]
 --------------------------------------PhysicalProject
 ----------------------------------------filter((store_sales.ss_quantity <= 40) 
and (store_sales.ss_quantity >= 21))
 ------------------------------------------PhysicalOlapScan[store_sales]
---------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------PhysicalAssertNumRows
+----------------------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------------------hashAgg[GLOBAL]
 --------------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------------hashAgg[LOCAL]
 ------------------------------------PhysicalProject
 --------------------------------------filter((store_sales.ss_quantity <= 40) 
and (store_sales.ss_quantity >= 21))
 ----------------------------------------PhysicalOlapScan[store_sales]
-------------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------------PhysicalAssertNumRows
+--------------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------------hashAgg[GLOBAL]
 ------------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------------hashAgg[LOCAL]
 ----------------------------------PhysicalProject
-------------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
+------------------------------------filter((store_sales.ss_quantity <= 40) and 
(store_sales.ss_quantity >= 21))
 --------------------------------------PhysicalOlapScan[store_sales]
-----------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------PhysicalAssertNumRows
+------------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------------hashAgg[GLOBAL]
 ----------------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------------hashAgg[LOCAL]
 --------------------------------PhysicalProject
 ----------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 ------------------------------------PhysicalOlapScan[store_sales]
---------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------PhysicalAssertNumRows
+----------------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------------hashAgg[GLOBAL]
 --------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------hashAgg[LOCAL]
 ------------------------------PhysicalProject
 --------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 ----------------------------------PhysicalOlapScan[store_sales]
-------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------PhysicalAssertNumRows
+--------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------hashAgg[GLOBAL]
 ------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
+------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 --------------------------------PhysicalOlapScan[store_sales]
-----------------PhysicalDistribute[DistributionSpecReplicated]
-------------------PhysicalAssertNumRows
+------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------hashAgg[GLOBAL]
 ----------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------hashAgg[LOCAL]
 --------------------------PhysicalProject
 ----------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 ------------------------------PhysicalOlapScan[store_sales]
---------------PhysicalDistribute[DistributionSpecReplicated]
-----------------PhysicalAssertNumRows
+----------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------hashAgg[GLOBAL]
 --------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------hashAgg[LOCAL]
 ------------------------PhysicalProject
 --------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 ----------------------------PhysicalOlapScan[store_sales]
-------------PhysicalDistribute[DistributionSpecReplicated]
---------------PhysicalAssertNumRows
+--------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------hashAgg[GLOBAL]
 ------------------PhysicalDistribute[DistributionSpecGather]
 --------------------hashAgg[LOCAL]
 ----------------------PhysicalProject
-------------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
+------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 --------------------------PhysicalOlapScan[store_sales]
-----------PhysicalDistribute[DistributionSpecReplicated]
-------------PhysicalAssertNumRows
+------------PhysicalDistribute[DistributionSpecReplicated]
 --------------hashAgg[GLOBAL]
 ----------------PhysicalDistribute[DistributionSpecGather]
 ------------------hashAgg[LOCAL]
 --------------------PhysicalProject
 ----------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
 ------------------------PhysicalOlapScan[store_sales]
---------PhysicalDistribute[DistributionSpecReplicated]
-----------PhysicalAssertNumRows
+----------PhysicalDistribute[DistributionSpecReplicated]
 ------------hashAgg[GLOBAL]
 --------------PhysicalDistribute[DistributionSpecGather]
 ----------------hashAgg[LOCAL]
 ------------------PhysicalProject
 --------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
 ----------------------PhysicalOlapScan[store_sales]
+--------PhysicalDistribute[DistributionSpecReplicated]
+----------hashAgg[GLOBAL]
+------------PhysicalDistribute[DistributionSpecGather]
+--------------hashAgg[LOCAL]
+----------------PhysicalProject
+------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
+--------------------PhysicalOlapScan[store_sales]
 
diff --git 
a/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query9.out 
b/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query9.out
index 6f64f57ee2d..4ccfb2a4e34 100644
--- 
a/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query9.out
+++ 
b/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query9.out
@@ -23,123 +23,108 @@ PhysicalResultSink
 ----------------------------------------filter((reason.r_reason_sk = 1))
 ------------------------------------------PhysicalOlapScan[reason]
 
--------------------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------------------PhysicalAssertNumRows
-------------------------------------------hashAgg[GLOBAL]
---------------------------------------------PhysicalDistribute[DistributionSpecGather]
-----------------------------------------------hashAgg[LOCAL]
-------------------------------------------------PhysicalProject
---------------------------------------------------filter((store_sales.ss_quantity
 <= 20) and (store_sales.ss_quantity >= 1))
-----------------------------------------------------PhysicalOlapScan[store_sales]
+----------------------------------------hashAgg[GLOBAL]
+------------------------------------------PhysicalDistribute[DistributionSpecGather]
+--------------------------------------------hashAgg[LOCAL]
+----------------------------------------------PhysicalProject
+------------------------------------------------filter((store_sales.ss_quantity
 <= 20) and (store_sales.ss_quantity >= 1))
+--------------------------------------------------PhysicalOlapScan[store_sales]
 
----------------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------------PhysicalAssertNumRows
---------------------------------------hashAgg[GLOBAL]
-----------------------------------------PhysicalDistribute[DistributionSpecGather]
-------------------------------------------hashAgg[LOCAL]
---------------------------------------------PhysicalProject
-----------------------------------------------filter((store_sales.ss_quantity 
<= 20) and (store_sales.ss_quantity >= 1))
-------------------------------------------------PhysicalOlapScan[store_sales]
---------------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------------PhysicalAssertNumRows
 ------------------------------------hashAgg[GLOBAL]
 
--------------------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------------------hashAgg[LOCAL]
 ------------------------------------------PhysicalProject
 --------------------------------------------filter((store_sales.ss_quantity <= 
20) and (store_sales.ss_quantity >= 1))
 ----------------------------------------------PhysicalOlapScan[store_sales]
-------------------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------------------PhysicalAssertNumRows
+--------------------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------------------hashAgg[GLOBAL]
 ------------------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------------------hashAgg[LOCAL]
 ----------------------------------------PhysicalProject
-------------------------------------------filter((store_sales.ss_quantity <= 
40) and (store_sales.ss_quantity >= 21))
+------------------------------------------filter((store_sales.ss_quantity <= 
20) and (store_sales.ss_quantity >= 1))
 --------------------------------------------PhysicalOlapScan[store_sales]
-----------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------PhysicalAssertNumRows
+------------------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------------------hashAgg[GLOBAL]
 ----------------------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------------------hashAgg[LOCAL]
 --------------------------------------PhysicalProject
 ----------------------------------------filter((store_sales.ss_quantity <= 40) 
and (store_sales.ss_quantity >= 21))
 ------------------------------------------PhysicalOlapScan[store_sales]
---------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------PhysicalAssertNumRows
+----------------------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------------------hashAgg[GLOBAL]
 --------------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------------hashAgg[LOCAL]
 ------------------------------------PhysicalProject
 --------------------------------------filter((store_sales.ss_quantity <= 40) 
and (store_sales.ss_quantity >= 21))
 ----------------------------------------PhysicalOlapScan[store_sales]
-------------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------------PhysicalAssertNumRows
+--------------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------------hashAgg[GLOBAL]
 ------------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------------hashAgg[LOCAL]
 ----------------------------------PhysicalProject
-------------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
+------------------------------------filter((store_sales.ss_quantity <= 40) and 
(store_sales.ss_quantity >= 21))
 --------------------------------------PhysicalOlapScan[store_sales]
-----------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------PhysicalAssertNumRows
+------------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------------hashAgg[GLOBAL]
 ----------------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------------hashAgg[LOCAL]
 --------------------------------PhysicalProject
 ----------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 ------------------------------------PhysicalOlapScan[store_sales]
---------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------PhysicalAssertNumRows
+----------------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------------hashAgg[GLOBAL]
 --------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------hashAgg[LOCAL]
 ------------------------------PhysicalProject
 --------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 ----------------------------------PhysicalOlapScan[store_sales]
-------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------PhysicalAssertNumRows
+--------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------hashAgg[GLOBAL]
 ------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
+------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 --------------------------------PhysicalOlapScan[store_sales]
-----------------PhysicalDistribute[DistributionSpecReplicated]
-------------------PhysicalAssertNumRows
+------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------hashAgg[GLOBAL]
 ----------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------hashAgg[LOCAL]
 --------------------------PhysicalProject
 ----------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 ------------------------------PhysicalOlapScan[store_sales]
---------------PhysicalDistribute[DistributionSpecReplicated]
-----------------PhysicalAssertNumRows
+----------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------hashAgg[GLOBAL]
 --------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------hashAgg[LOCAL]
 ------------------------PhysicalProject
 --------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 ----------------------------PhysicalOlapScan[store_sales]
-------------PhysicalDistribute[DistributionSpecReplicated]
---------------PhysicalAssertNumRows
+--------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------hashAgg[GLOBAL]
 ------------------PhysicalDistribute[DistributionSpecGather]
 --------------------hashAgg[LOCAL]
 ----------------------PhysicalProject
-------------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
+------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 --------------------------PhysicalOlapScan[store_sales]
-----------PhysicalDistribute[DistributionSpecReplicated]
-------------PhysicalAssertNumRows
+------------PhysicalDistribute[DistributionSpecReplicated]
 --------------hashAgg[GLOBAL]
 ----------------PhysicalDistribute[DistributionSpecGather]
 ------------------hashAgg[LOCAL]
 --------------------PhysicalProject
 ----------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
 ------------------------PhysicalOlapScan[store_sales]
---------PhysicalDistribute[DistributionSpecReplicated]
-----------PhysicalAssertNumRows
+----------PhysicalDistribute[DistributionSpecReplicated]
 ------------hashAgg[GLOBAL]
 --------------PhysicalDistribute[DistributionSpecGather]
 ----------------hashAgg[LOCAL]
 ------------------PhysicalProject
 --------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
 ----------------------PhysicalOlapScan[store_sales]
+--------PhysicalDistribute[DistributionSpecReplicated]
+----------hashAgg[GLOBAL]
+------------PhysicalDistribute[DistributionSpecGather]
+--------------hashAgg[LOCAL]
+----------------PhysicalProject
+------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
+--------------------PhysicalOlapScan[store_sales]
 
diff --git 
a/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query44.out 
b/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query44.out
index cde6a04b5d4..78d9a82df01 100644
--- a/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query44.out
+++ b/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query44.out
@@ -5,43 +5,13 @@ PhysicalResultSink
 ----PhysicalDistribute[DistributionSpecGather]
 ------PhysicalTopN[LOCAL_SORT]
 --------PhysicalProject
-----------hashJoin[INNER_JOIN] hashCondition=((i2.i_item_sk = 
descending.item_sk)) otherCondition=() build RFs:RF1 item_sk->[i_item_sk]
-------------PhysicalProject
---------------PhysicalOlapScan[item] apply RFs: RF1
+----------hashJoin[INNER_JOIN] hashCondition=((asceding.rnk = descending.rnk)) 
otherCondition=()
 ------------PhysicalDistribute[DistributionSpecHash]
 --------------PhysicalProject
-----------------hashJoin[INNER_JOIN] hashCondition=((asceding.rnk = 
descending.rnk)) otherCondition=()
-------------------hashJoin[INNER_JOIN] hashCondition=((i1.i_item_sk = 
asceding.item_sk)) otherCondition=() build RFs:RF0 item_sk->[i_item_sk]
---------------------PhysicalProject
-----------------------PhysicalOlapScan[item] apply RFs: RF0
---------------------PhysicalDistribute[DistributionSpecHash]
-----------------------PhysicalProject
-------------------------filter((rnk < 11))
---------------------------PhysicalWindow
-----------------------------PhysicalQuickSort[MERGE_SORT]
-------------------------------PhysicalDistribute[DistributionSpecGather]
---------------------------------PhysicalQuickSort[LOCAL_SORT]
-----------------------------------PhysicalPartitionTopN
-------------------------------------PhysicalProject
---------------------------------------NestedLoopJoin[INNER_JOIN](cast(rank_col 
as DOUBLE) > cast((0.9 * rank_col) as DOUBLE))
-----------------------------------------PhysicalProject
-------------------------------------------hashAgg[GLOBAL]
---------------------------------------------PhysicalDistribute[DistributionSpecHash]
-----------------------------------------------hashAgg[LOCAL]
-------------------------------------------------PhysicalProject
---------------------------------------------------filter((ss1.ss_store_sk = 
146))
-----------------------------------------------------PhysicalOlapScan[store_sales]
-----------------------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------------------PhysicalAssertNumRows
---------------------------------------------PhysicalDistribute[DistributionSpecGather]
-----------------------------------------------PhysicalProject
-------------------------------------------------hashAgg[GLOBAL]
---------------------------------------------------PhysicalDistribute[DistributionSpecHash]
-----------------------------------------------------hashAgg[LOCAL]
-------------------------------------------------------PhysicalProject
---------------------------------------------------------filter((store_sales.ss_store_sk
 = 146) and ss_addr_sk IS NULL)
-----------------------------------------------------------PhysicalOlapScan[store_sales]
-------------------PhysicalDistribute[DistributionSpecReplicated]
+----------------hashJoin[INNER_JOIN] hashCondition=((i1.i_item_sk = 
asceding.item_sk)) otherCondition=() build RFs:RF1 item_sk->[i_item_sk]
+------------------PhysicalProject
+--------------------PhysicalOlapScan[item] apply RFs: RF1
+------------------PhysicalDistribute[DistributionSpecHash]
 --------------------PhysicalProject
 ----------------------filter((rnk < 11))
 ------------------------PhysicalWindow
@@ -68,4 +38,35 @@ PhysicalResultSink
 ----------------------------------------------------PhysicalProject
 
------------------------------------------------------filter((store_sales.ss_store_sk
 = 146) and ss_addr_sk IS NULL)
 
--------------------------------------------------------PhysicalOlapScan[store_sales]
+------------PhysicalDistribute[DistributionSpecHash]
+--------------hashJoin[INNER_JOIN] hashCondition=((i2.i_item_sk = 
descending.item_sk)) otherCondition=() build RFs:RF0 item_sk->[i_item_sk]
+----------------PhysicalProject
+------------------PhysicalOlapScan[item] apply RFs: RF0
+----------------PhysicalDistribute[DistributionSpecHash]
+------------------PhysicalProject
+--------------------filter((rnk < 11))
+----------------------PhysicalWindow
+------------------------PhysicalQuickSort[MERGE_SORT]
+--------------------------PhysicalDistribute[DistributionSpecGather]
+----------------------------PhysicalQuickSort[LOCAL_SORT]
+------------------------------PhysicalPartitionTopN
+--------------------------------PhysicalProject
+----------------------------------NestedLoopJoin[INNER_JOIN](cast(rank_col as 
DOUBLE) > cast((0.9 * rank_col) as DOUBLE))
+------------------------------------PhysicalProject
+--------------------------------------hashAgg[GLOBAL]
+----------------------------------------PhysicalDistribute[DistributionSpecHash]
+------------------------------------------hashAgg[LOCAL]
+--------------------------------------------PhysicalProject
+----------------------------------------------filter((ss1.ss_store_sk = 146))
+------------------------------------------------PhysicalOlapScan[store_sales]
+------------------------------------PhysicalDistribute[DistributionSpecReplicated]
+--------------------------------------PhysicalAssertNumRows
+----------------------------------------PhysicalDistribute[DistributionSpecGather]
+------------------------------------------PhysicalProject
+--------------------------------------------hashAgg[GLOBAL]
+----------------------------------------------PhysicalDistribute[DistributionSpecHash]
+------------------------------------------------hashAgg[LOCAL]
+--------------------------------------------------PhysicalProject
+----------------------------------------------------filter((store_sales.ss_store_sk
 = 146) and ss_addr_sk IS NULL)
+------------------------------------------------------PhysicalOlapScan[store_sales]
 
diff --git 
a/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query9.out 
b/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query9.out
index 6f64f57ee2d..4ccfb2a4e34 100644
--- a/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query9.out
+++ b/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query9.out
@@ -23,123 +23,108 @@ PhysicalResultSink
 ----------------------------------------filter((reason.r_reason_sk = 1))
 ------------------------------------------PhysicalOlapScan[reason]
 
--------------------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------------------PhysicalAssertNumRows
-------------------------------------------hashAgg[GLOBAL]
---------------------------------------------PhysicalDistribute[DistributionSpecGather]
-----------------------------------------------hashAgg[LOCAL]
-------------------------------------------------PhysicalProject
---------------------------------------------------filter((store_sales.ss_quantity
 <= 20) and (store_sales.ss_quantity >= 1))
-----------------------------------------------------PhysicalOlapScan[store_sales]
+----------------------------------------hashAgg[GLOBAL]
+------------------------------------------PhysicalDistribute[DistributionSpecGather]
+--------------------------------------------hashAgg[LOCAL]
+----------------------------------------------PhysicalProject
+------------------------------------------------filter((store_sales.ss_quantity
 <= 20) and (store_sales.ss_quantity >= 1))
+--------------------------------------------------PhysicalOlapScan[store_sales]
 
----------------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------------PhysicalAssertNumRows
---------------------------------------hashAgg[GLOBAL]
-----------------------------------------PhysicalDistribute[DistributionSpecGather]
-------------------------------------------hashAgg[LOCAL]
---------------------------------------------PhysicalProject
-----------------------------------------------filter((store_sales.ss_quantity 
<= 20) and (store_sales.ss_quantity >= 1))
-------------------------------------------------PhysicalOlapScan[store_sales]
---------------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------------PhysicalAssertNumRows
 ------------------------------------hashAgg[GLOBAL]
 
--------------------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------------------hashAgg[LOCAL]
 ------------------------------------------PhysicalProject
 --------------------------------------------filter((store_sales.ss_quantity <= 
20) and (store_sales.ss_quantity >= 1))
 ----------------------------------------------PhysicalOlapScan[store_sales]
-------------------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------------------PhysicalAssertNumRows
+--------------------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------------------hashAgg[GLOBAL]
 ------------------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------------------hashAgg[LOCAL]
 ----------------------------------------PhysicalProject
-------------------------------------------filter((store_sales.ss_quantity <= 
40) and (store_sales.ss_quantity >= 21))
+------------------------------------------filter((store_sales.ss_quantity <= 
20) and (store_sales.ss_quantity >= 1))
 --------------------------------------------PhysicalOlapScan[store_sales]
-----------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------PhysicalAssertNumRows
+------------------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------------------hashAgg[GLOBAL]
 ----------------------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------------------hashAgg[LOCAL]
 --------------------------------------PhysicalProject
 ----------------------------------------filter((store_sales.ss_quantity <= 40) 
and (store_sales.ss_quantity >= 21))
 ------------------------------------------PhysicalOlapScan[store_sales]
---------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------PhysicalAssertNumRows
+----------------------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------------------hashAgg[GLOBAL]
 --------------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------------hashAgg[LOCAL]
 ------------------------------------PhysicalProject
 --------------------------------------filter((store_sales.ss_quantity <= 40) 
and (store_sales.ss_quantity >= 21))
 ----------------------------------------PhysicalOlapScan[store_sales]
-------------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------------PhysicalAssertNumRows
+--------------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------------hashAgg[GLOBAL]
 ------------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------------hashAgg[LOCAL]
 ----------------------------------PhysicalProject
-------------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
+------------------------------------filter((store_sales.ss_quantity <= 40) and 
(store_sales.ss_quantity >= 21))
 --------------------------------------PhysicalOlapScan[store_sales]
-----------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------PhysicalAssertNumRows
+------------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------------hashAgg[GLOBAL]
 ----------------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------------hashAgg[LOCAL]
 --------------------------------PhysicalProject
 ----------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 ------------------------------------PhysicalOlapScan[store_sales]
---------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------PhysicalAssertNumRows
+----------------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------------hashAgg[GLOBAL]
 --------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------hashAgg[LOCAL]
 ------------------------------PhysicalProject
 --------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 ----------------------------------PhysicalOlapScan[store_sales]
-------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------PhysicalAssertNumRows
+--------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------hashAgg[GLOBAL]
 ------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
+------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 --------------------------------PhysicalOlapScan[store_sales]
-----------------PhysicalDistribute[DistributionSpecReplicated]
-------------------PhysicalAssertNumRows
+------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------hashAgg[GLOBAL]
 ----------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------hashAgg[LOCAL]
 --------------------------PhysicalProject
 ----------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 ------------------------------PhysicalOlapScan[store_sales]
---------------PhysicalDistribute[DistributionSpecReplicated]
-----------------PhysicalAssertNumRows
+----------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------hashAgg[GLOBAL]
 --------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------hashAgg[LOCAL]
 ------------------------PhysicalProject
 --------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 ----------------------------PhysicalOlapScan[store_sales]
-------------PhysicalDistribute[DistributionSpecReplicated]
---------------PhysicalAssertNumRows
+--------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------hashAgg[GLOBAL]
 ------------------PhysicalDistribute[DistributionSpecGather]
 --------------------hashAgg[LOCAL]
 ----------------------PhysicalProject
-------------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
+------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 --------------------------PhysicalOlapScan[store_sales]
-----------PhysicalDistribute[DistributionSpecReplicated]
-------------PhysicalAssertNumRows
+------------PhysicalDistribute[DistributionSpecReplicated]
 --------------hashAgg[GLOBAL]
 ----------------PhysicalDistribute[DistributionSpecGather]
 ------------------hashAgg[LOCAL]
 --------------------PhysicalProject
 ----------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
 ------------------------PhysicalOlapScan[store_sales]
---------PhysicalDistribute[DistributionSpecReplicated]
-----------PhysicalAssertNumRows
+----------PhysicalDistribute[DistributionSpecReplicated]
 ------------hashAgg[GLOBAL]
 --------------PhysicalDistribute[DistributionSpecGather]
 ----------------hashAgg[LOCAL]
 ------------------PhysicalProject
 --------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
 ----------------------PhysicalOlapScan[store_sales]
+--------PhysicalDistribute[DistributionSpecReplicated]
+----------hashAgg[GLOBAL]
+------------PhysicalDistribute[DistributionSpecGather]
+--------------hashAgg[LOCAL]
+----------------PhysicalProject
+------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
+--------------------PhysicalOlapScan[store_sales]
 
diff --git 
a/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query44.out 
b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query44.out
index cde6a04b5d4..78d9a82df01 100644
--- a/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query44.out
+++ b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query44.out
@@ -5,43 +5,13 @@ PhysicalResultSink
 ----PhysicalDistribute[DistributionSpecGather]
 ------PhysicalTopN[LOCAL_SORT]
 --------PhysicalProject
-----------hashJoin[INNER_JOIN] hashCondition=((i2.i_item_sk = 
descending.item_sk)) otherCondition=() build RFs:RF1 item_sk->[i_item_sk]
-------------PhysicalProject
---------------PhysicalOlapScan[item] apply RFs: RF1
+----------hashJoin[INNER_JOIN] hashCondition=((asceding.rnk = descending.rnk)) 
otherCondition=()
 ------------PhysicalDistribute[DistributionSpecHash]
 --------------PhysicalProject
-----------------hashJoin[INNER_JOIN] hashCondition=((asceding.rnk = 
descending.rnk)) otherCondition=()
-------------------hashJoin[INNER_JOIN] hashCondition=((i1.i_item_sk = 
asceding.item_sk)) otherCondition=() build RFs:RF0 item_sk->[i_item_sk]
---------------------PhysicalProject
-----------------------PhysicalOlapScan[item] apply RFs: RF0
---------------------PhysicalDistribute[DistributionSpecHash]
-----------------------PhysicalProject
-------------------------filter((rnk < 11))
---------------------------PhysicalWindow
-----------------------------PhysicalQuickSort[MERGE_SORT]
-------------------------------PhysicalDistribute[DistributionSpecGather]
---------------------------------PhysicalQuickSort[LOCAL_SORT]
-----------------------------------PhysicalPartitionTopN
-------------------------------------PhysicalProject
---------------------------------------NestedLoopJoin[INNER_JOIN](cast(rank_col 
as DOUBLE) > cast((0.9 * rank_col) as DOUBLE))
-----------------------------------------PhysicalProject
-------------------------------------------hashAgg[GLOBAL]
---------------------------------------------PhysicalDistribute[DistributionSpecHash]
-----------------------------------------------hashAgg[LOCAL]
-------------------------------------------------PhysicalProject
---------------------------------------------------filter((ss1.ss_store_sk = 
146))
-----------------------------------------------------PhysicalOlapScan[store_sales]
-----------------------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------------------PhysicalAssertNumRows
---------------------------------------------PhysicalDistribute[DistributionSpecGather]
-----------------------------------------------PhysicalProject
-------------------------------------------------hashAgg[GLOBAL]
---------------------------------------------------PhysicalDistribute[DistributionSpecHash]
-----------------------------------------------------hashAgg[LOCAL]
-------------------------------------------------------PhysicalProject
---------------------------------------------------------filter((store_sales.ss_store_sk
 = 146) and ss_addr_sk IS NULL)
-----------------------------------------------------------PhysicalOlapScan[store_sales]
-------------------PhysicalDistribute[DistributionSpecReplicated]
+----------------hashJoin[INNER_JOIN] hashCondition=((i1.i_item_sk = 
asceding.item_sk)) otherCondition=() build RFs:RF1 item_sk->[i_item_sk]
+------------------PhysicalProject
+--------------------PhysicalOlapScan[item] apply RFs: RF1
+------------------PhysicalDistribute[DistributionSpecHash]
 --------------------PhysicalProject
 ----------------------filter((rnk < 11))
 ------------------------PhysicalWindow
@@ -68,4 +38,35 @@ PhysicalResultSink
 ----------------------------------------------------PhysicalProject
 
------------------------------------------------------filter((store_sales.ss_store_sk
 = 146) and ss_addr_sk IS NULL)
 
--------------------------------------------------------PhysicalOlapScan[store_sales]
+------------PhysicalDistribute[DistributionSpecHash]
+--------------hashJoin[INNER_JOIN] hashCondition=((i2.i_item_sk = 
descending.item_sk)) otherCondition=() build RFs:RF0 item_sk->[i_item_sk]
+----------------PhysicalProject
+------------------PhysicalOlapScan[item] apply RFs: RF0
+----------------PhysicalDistribute[DistributionSpecHash]
+------------------PhysicalProject
+--------------------filter((rnk < 11))
+----------------------PhysicalWindow
+------------------------PhysicalQuickSort[MERGE_SORT]
+--------------------------PhysicalDistribute[DistributionSpecGather]
+----------------------------PhysicalQuickSort[LOCAL_SORT]
+------------------------------PhysicalPartitionTopN
+--------------------------------PhysicalProject
+----------------------------------NestedLoopJoin[INNER_JOIN](cast(rank_col as 
DOUBLE) > cast((0.9 * rank_col) as DOUBLE))
+------------------------------------PhysicalProject
+--------------------------------------hashAgg[GLOBAL]
+----------------------------------------PhysicalDistribute[DistributionSpecHash]
+------------------------------------------hashAgg[LOCAL]
+--------------------------------------------PhysicalProject
+----------------------------------------------filter((ss1.ss_store_sk = 146))
+------------------------------------------------PhysicalOlapScan[store_sales]
+------------------------------------PhysicalDistribute[DistributionSpecReplicated]
+--------------------------------------PhysicalAssertNumRows
+----------------------------------------PhysicalDistribute[DistributionSpecGather]
+------------------------------------------PhysicalProject
+--------------------------------------------hashAgg[GLOBAL]
+----------------------------------------------PhysicalDistribute[DistributionSpecHash]
+------------------------------------------------hashAgg[LOCAL]
+--------------------------------------------------PhysicalProject
+----------------------------------------------------filter((store_sales.ss_store_sk
 = 146) and ss_addr_sk IS NULL)
+------------------------------------------------------PhysicalOlapScan[store_sales]
 
diff --git a/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query9.out 
b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query9.out
index 6f64f57ee2d..4ccfb2a4e34 100644
--- a/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query9.out
+++ b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query9.out
@@ -23,123 +23,108 @@ PhysicalResultSink
 ----------------------------------------filter((reason.r_reason_sk = 1))
 ------------------------------------------PhysicalOlapScan[reason]
 
--------------------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------------------PhysicalAssertNumRows
-------------------------------------------hashAgg[GLOBAL]
---------------------------------------------PhysicalDistribute[DistributionSpecGather]
-----------------------------------------------hashAgg[LOCAL]
-------------------------------------------------PhysicalProject
---------------------------------------------------filter((store_sales.ss_quantity
 <= 20) and (store_sales.ss_quantity >= 1))
-----------------------------------------------------PhysicalOlapScan[store_sales]
+----------------------------------------hashAgg[GLOBAL]
+------------------------------------------PhysicalDistribute[DistributionSpecGather]
+--------------------------------------------hashAgg[LOCAL]
+----------------------------------------------PhysicalProject
+------------------------------------------------filter((store_sales.ss_quantity
 <= 20) and (store_sales.ss_quantity >= 1))
+--------------------------------------------------PhysicalOlapScan[store_sales]
 
----------------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------------PhysicalAssertNumRows
---------------------------------------hashAgg[GLOBAL]
-----------------------------------------PhysicalDistribute[DistributionSpecGather]
-------------------------------------------hashAgg[LOCAL]
---------------------------------------------PhysicalProject
-----------------------------------------------filter((store_sales.ss_quantity 
<= 20) and (store_sales.ss_quantity >= 1))
-------------------------------------------------PhysicalOlapScan[store_sales]
---------------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------------PhysicalAssertNumRows
 ------------------------------------hashAgg[GLOBAL]
 
--------------------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------------------hashAgg[LOCAL]
 ------------------------------------------PhysicalProject
 --------------------------------------------filter((store_sales.ss_quantity <= 
20) and (store_sales.ss_quantity >= 1))
 ----------------------------------------------PhysicalOlapScan[store_sales]
-------------------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------------------PhysicalAssertNumRows
+--------------------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------------------hashAgg[GLOBAL]
 ------------------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------------------hashAgg[LOCAL]
 ----------------------------------------PhysicalProject
-------------------------------------------filter((store_sales.ss_quantity <= 
40) and (store_sales.ss_quantity >= 21))
+------------------------------------------filter((store_sales.ss_quantity <= 
20) and (store_sales.ss_quantity >= 1))
 --------------------------------------------PhysicalOlapScan[store_sales]
-----------------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------------PhysicalAssertNumRows
+------------------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------------------hashAgg[GLOBAL]
 ----------------------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------------------hashAgg[LOCAL]
 --------------------------------------PhysicalProject
 ----------------------------------------filter((store_sales.ss_quantity <= 40) 
and (store_sales.ss_quantity >= 21))
 ------------------------------------------PhysicalOlapScan[store_sales]
---------------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------------PhysicalAssertNumRows
+----------------------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------------------hashAgg[GLOBAL]
 --------------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------------hashAgg[LOCAL]
 ------------------------------------PhysicalProject
 --------------------------------------filter((store_sales.ss_quantity <= 40) 
and (store_sales.ss_quantity >= 21))
 ----------------------------------------PhysicalOlapScan[store_sales]
-------------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------------PhysicalAssertNumRows
+--------------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------------hashAgg[GLOBAL]
 ------------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------------hashAgg[LOCAL]
 ----------------------------------PhysicalProject
-------------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
+------------------------------------filter((store_sales.ss_quantity <= 40) and 
(store_sales.ss_quantity >= 21))
 --------------------------------------PhysicalOlapScan[store_sales]
-----------------------PhysicalDistribute[DistributionSpecReplicated]
-------------------------PhysicalAssertNumRows
+------------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------------hashAgg[GLOBAL]
 ----------------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------------hashAgg[LOCAL]
 --------------------------------PhysicalProject
 ----------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 ------------------------------------PhysicalOlapScan[store_sales]
---------------------PhysicalDistribute[DistributionSpecReplicated]
-----------------------PhysicalAssertNumRows
+----------------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------------hashAgg[GLOBAL]
 --------------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------------hashAgg[LOCAL]
 ------------------------------PhysicalProject
 --------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 ----------------------------------PhysicalOlapScan[store_sales]
-------------------PhysicalDistribute[DistributionSpecReplicated]
---------------------PhysicalAssertNumRows
+--------------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------------hashAgg[GLOBAL]
 ------------------------PhysicalDistribute[DistributionSpecGather]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
+------------------------------filter((store_sales.ss_quantity <= 60) and 
(store_sales.ss_quantity >= 41))
 --------------------------------PhysicalOlapScan[store_sales]
-----------------PhysicalDistribute[DistributionSpecReplicated]
-------------------PhysicalAssertNumRows
+------------------PhysicalDistribute[DistributionSpecReplicated]
 --------------------hashAgg[GLOBAL]
 ----------------------PhysicalDistribute[DistributionSpecGather]
 ------------------------hashAgg[LOCAL]
 --------------------------PhysicalProject
 ----------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 ------------------------------PhysicalOlapScan[store_sales]
---------------PhysicalDistribute[DistributionSpecReplicated]
-----------------PhysicalAssertNumRows
+----------------PhysicalDistribute[DistributionSpecReplicated]
 ------------------hashAgg[GLOBAL]
 --------------------PhysicalDistribute[DistributionSpecGather]
 ----------------------hashAgg[LOCAL]
 ------------------------PhysicalProject
 --------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 ----------------------------PhysicalOlapScan[store_sales]
-------------PhysicalDistribute[DistributionSpecReplicated]
---------------PhysicalAssertNumRows
+--------------PhysicalDistribute[DistributionSpecReplicated]
 ----------------hashAgg[GLOBAL]
 ------------------PhysicalDistribute[DistributionSpecGather]
 --------------------hashAgg[LOCAL]
 ----------------------PhysicalProject
-------------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
+------------------------filter((store_sales.ss_quantity <= 80) and 
(store_sales.ss_quantity >= 61))
 --------------------------PhysicalOlapScan[store_sales]
-----------PhysicalDistribute[DistributionSpecReplicated]
-------------PhysicalAssertNumRows
+------------PhysicalDistribute[DistributionSpecReplicated]
 --------------hashAgg[GLOBAL]
 ----------------PhysicalDistribute[DistributionSpecGather]
 ------------------hashAgg[LOCAL]
 --------------------PhysicalProject
 ----------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
 ------------------------PhysicalOlapScan[store_sales]
---------PhysicalDistribute[DistributionSpecReplicated]
-----------PhysicalAssertNumRows
+----------PhysicalDistribute[DistributionSpecReplicated]
 ------------hashAgg[GLOBAL]
 --------------PhysicalDistribute[DistributionSpecGather]
 ----------------hashAgg[LOCAL]
 ------------------PhysicalProject
 --------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
 ----------------------PhysicalOlapScan[store_sales]
+--------PhysicalDistribute[DistributionSpecReplicated]
+----------hashAgg[GLOBAL]
+------------PhysicalDistribute[DistributionSpecGather]
+--------------hashAgg[LOCAL]
+----------------PhysicalProject
+------------------filter((store_sales.ss_quantity <= 100) and 
(store_sales.ss_quantity >= 81))
+--------------------PhysicalOlapScan[store_sales]
 
diff --git a/regression-test/suites/nereids_p0/subquery/test_subquery.groovy 
b/regression-test/suites/nereids_p0/subquery/test_subquery.groovy
index aa94e91e8db..6e29d2205ce 100644
--- a/regression-test/suites/nereids_p0/subquery/test_subquery.groovy
+++ b/regression-test/suites/nereids_p0/subquery/test_subquery.groovy
@@ -64,7 +64,7 @@ suite("test_subquery") {
         sql """
             select * from nereids_test_query_db.baseall where k1 = (select k1 
from nereids_test_query_db.baseall limit 2)
         """
-        exception("Expected LE 1 to be returned by expression")
+        exception("Expected EQ 1 to be returned by expression")
     }
 
     // test uncorrelated scalar subquery with order by and limit
@@ -254,4 +254,25 @@ suite("test_subquery") {
     sql """drop table if exists table_20_undef_undef"""
     sql """drop table if exists table_9_undef_undef"""
 
+    sql """drop table if exists 
table_100_undef_partitions2_keys3_properties4_distributed_by5"""
+    sql """drop table if exists 
table_5_undef_partitions2_keys3_properties4_distributed_by5"""
+    sql """create table 
table_100_undef_partitions2_keys3_properties4_distributed_by5 (
+            col_int_undef_signed int/*agg_type_placeholder*/   ,
+            col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   
,
+            pk int/*agg_type_placeholder*/
+            ) engine=olap
+            distributed by hash(pk) buckets 10
+            properties("replication_num" = "1");"""
+    sql """create table 
table_5_undef_partitions2_keys3_properties4_distributed_by5 (
+            col_int_undef_signed int/*agg_type_placeholder*/   ,
+            col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   
,
+            pk int/*agg_type_placeholder*/
+            ) engine=olap
+            distributed by hash(pk) buckets 10
+            properties("replication_num" = "1");"""
+    sql """insert into 
table_100_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values 
(0,3,'l'),(1,null,''),(2,null,'really'),(3,4,''),(4,null,null),(5,3,'s'),(6,2,''),(7,1,''),(8,null,''),(9,5,''),(10,6,null),(11,9,'i'),(12,null,'u'),(13,1,'p'),(14,7,''),(15,null,'v'),(16,2,null),(17,null,''),(18,null,'my'),(19,2,null),(20,7,''),(21,9,''),(22,null,''),(23,null,'good'),(24,7,'n'),(25,1,'my'),(26,null,'k'),(27,null,'you'),(28,4,'
 [...]
+    sql """insert into 
table_5_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values (0,null,'r'),(1,null,'m'),(2,9,'his'),(3,1,'good'),(4,0,null);"""
+    qt_select_assert_num_row """SELECT * FROM 
table_100_undef_partitions2_keys3_properties4_distributed_by5 AS t1 WHERE 
t1.`pk` IN (0, 6, 8, 9, 5)  OR  t1.`pk`  -  0  <  (SELECT `pk` FROM 
table_5_undef_partitions2_keys3_properties4_distributed_by5 AS t2 WHERE t2.pk = 
9) order by t1.pk;"""
+    sql """drop table if exists 
table_100_undef_partitions2_keys3_properties4_distributed_by5"""
+    sql """drop table if exists 
table_5_undef_partitions2_keys3_properties4_distributed_by5"""
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org


Reply via email to