You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by co...@apache.org on 2025/08/13 15:07:04 UTC

(datafusion-comet) branch main updated: feat: limit with offset support (#2070)

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

comphead pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git


The following commit(s) were added to refs/heads/main by this push:
     new f8ed10944 feat: limit with offset support (#2070)
f8ed10944 is described below

commit f8ed109440c96fa5a50d56421f698e7f9e1de7fb
Author: Artem Kupchinskiy <ak...@proton.me>
AuthorDate: Wed Aug 13 19:06:59 2025 +0400

    feat: limit with offset support (#2070)
    
    * feat: positive offset support for queries with limit
    
    * fix stability suite and spark tests
    
    * fix stability suite and spark tests
    
    * rolled back accidentally changed logic in a test
    
    * replace assert with explicit Err return
    
    * fix clippy warnings
    
    * Update native/core/src/execution/planner.rs
    
    Co-authored-by: Oleks V <co...@users.noreply.github.com>
    
    * Update spark/src/main/scala/org/apache/spark/sql/comet/CometCollectLimitExec.scala
    
    Co-authored-by: Oleks V <co...@users.noreply.github.com>
    
    * Update native/core/src/execution/planner.rs
    
    Co-authored-by: Oleks V <co...@users.noreply.github.com>
    
    * fix compile errors and format warnings
    
    * zero offset and limit test
    
    ---------
    
    Co-authored-by: Oleks V <co...@users.noreply.github.com>
---
 dev/diffs/4.0.0.diff                               | 23 ++++++---
 native/core/src/execution/planner.rs               | 38 +++++++++++---
 native/proto/src/proto/operator.proto              |  1 +
 .../org/apache/comet/rules/CometExecRule.scala     |  8 ++-
 .../org/apache/comet/serde/QueryPlanSerde.scala    |  7 +--
 .../spark/sql/comet/CometCollectLimitExec.scala    |  9 ++--
 .../apache/spark/sql/comet/CometExecUtils.scala    | 20 +++++---
 .../sql/comet/CometTakeOrderedAndProjectExec.scala | 11 ++--
 .../org/apache/spark/sql/comet/operators.scala     | 10 ++--
 .../approved-plans-v1_4-spark3_5/q1/explain.txt    |  2 +-
 .../approved-plans-v1_4-spark3_5/q11/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q14a/explain.txt  |  2 +-
 .../approved-plans-v1_4-spark3_5/q14b/explain.txt  |  2 +-
 .../approved-plans-v1_4-spark3_5/q15/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q17/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q18/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q19/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q21/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q22/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q23b/explain.txt  |  2 +-
 .../approved-plans-v1_4-spark3_5/q25/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q26/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q27/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q29/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q3/explain.txt    |  2 +-
 .../approved-plans-v1_4-spark3_5/q30/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q33/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q37/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q4/explain.txt    |  2 +-
 .../approved-plans-v1_4-spark3_5/q40/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q41/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q42/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q43/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q46/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q49/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q50/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q52/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q54/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q55/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q56/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q58/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q59/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q6/explain.txt    |  2 +-
 .../approved-plans-v1_4-spark3_5/q60/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q62/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q65/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q66/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q68/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q7/explain.txt    |  2 +-
 .../approved-plans-v1_4-spark3_5/q72/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q74/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q75/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q76/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q79/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q8/explain.txt    |  2 +-
 .../approved-plans-v1_4-spark3_5/q81/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q82/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q83/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q85/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q93/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark3_5/q99/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark4_0/q37/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark4_0/q41/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark4_0/q44/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark4_0/q49/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark4_0/q72/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark4_0/q75/explain.txt   |  2 +-
 .../approved-plans-v1_4-spark4_0/q82/explain.txt   |  2 +-
 .../approved-plans-v1_4/q1/explain.txt             |  2 +-
 .../approved-plans-v1_4/q11/explain.txt            |  2 +-
 .../approved-plans-v1_4/q14a/explain.txt           |  2 +-
 .../approved-plans-v1_4/q14b/explain.txt           |  2 +-
 .../approved-plans-v1_4/q15/explain.txt            |  2 +-
 .../approved-plans-v1_4/q17/explain.txt            |  2 +-
 .../approved-plans-v1_4/q18/explain.txt            |  2 +-
 .../approved-plans-v1_4/q19/explain.txt            |  2 +-
 .../approved-plans-v1_4/q21/explain.txt            |  2 +-
 .../approved-plans-v1_4/q22/explain.txt            |  2 +-
 .../approved-plans-v1_4/q23b/explain.txt           |  2 +-
 .../approved-plans-v1_4/q25/explain.txt            |  2 +-
 .../approved-plans-v1_4/q26/explain.txt            |  2 +-
 .../approved-plans-v1_4/q27/explain.txt            |  2 +-
 .../approved-plans-v1_4/q29/explain.txt            |  2 +-
 .../approved-plans-v1_4/q3/explain.txt             |  2 +-
 .../approved-plans-v1_4/q30/explain.txt            |  2 +-
 .../approved-plans-v1_4/q33/explain.txt            |  2 +-
 .../approved-plans-v1_4/q37/explain.txt            |  2 +-
 .../approved-plans-v1_4/q4/explain.txt             |  2 +-
 .../approved-plans-v1_4/q40/explain.txt            |  2 +-
 .../approved-plans-v1_4/q41/explain.txt            |  2 +-
 .../approved-plans-v1_4/q42/explain.txt            |  2 +-
 .../approved-plans-v1_4/q43/explain.txt            |  2 +-
 .../approved-plans-v1_4/q46/explain.txt            |  2 +-
 .../approved-plans-v1_4/q49/explain.txt            |  2 +-
 .../approved-plans-v1_4/q50/explain.txt            |  2 +-
 .../approved-plans-v1_4/q52/explain.txt            |  2 +-
 .../approved-plans-v1_4/q54/explain.txt            |  2 +-
 .../approved-plans-v1_4/q55/explain.txt            |  2 +-
 .../approved-plans-v1_4/q56/explain.txt            |  2 +-
 .../approved-plans-v1_4/q58/explain.txt            |  2 +-
 .../approved-plans-v1_4/q59/explain.txt            |  2 +-
 .../approved-plans-v1_4/q6/explain.txt             |  2 +-
 .../approved-plans-v1_4/q60/explain.txt            |  2 +-
 .../approved-plans-v1_4/q62/explain.txt            |  2 +-
 .../approved-plans-v1_4/q65/explain.txt            |  2 +-
 .../approved-plans-v1_4/q66/explain.txt            |  2 +-
 .../approved-plans-v1_4/q68/explain.txt            |  2 +-
 .../approved-plans-v1_4/q7/explain.txt             |  2 +-
 .../approved-plans-v1_4/q72/explain.txt            |  2 +-
 .../approved-plans-v1_4/q74/explain.txt            |  2 +-
 .../approved-plans-v1_4/q75/explain.txt            |  2 +-
 .../approved-plans-v1_4/q76/explain.txt            |  2 +-
 .../approved-plans-v1_4/q79/explain.txt            |  2 +-
 .../approved-plans-v1_4/q8/explain.txt             |  2 +-
 .../approved-plans-v1_4/q81/explain.txt            |  2 +-
 .../approved-plans-v1_4/q82/explain.txt            |  2 +-
 .../approved-plans-v1_4/q83/explain.txt            |  2 +-
 .../approved-plans-v1_4/q85/explain.txt            |  2 +-
 .../approved-plans-v1_4/q93/explain.txt            |  2 +-
 .../approved-plans-v1_4/q99/explain.txt            |  2 +-
 .../approved-plans-v2_7-spark3_5/q10a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark3_5/q11/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark3_5/q14/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark3_5/q14a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark3_5/q18a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark3_5/q22a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark3_5/q27a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark3_5/q35a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark3_5/q49/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark3_5/q5a/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark3_5/q6/explain.txt    |  2 +-
 .../approved-plans-v2_7-spark3_5/q72/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark3_5/q74/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark3_5/q75/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark3_5/q77a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark3_5/q80a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark4_0/q10a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark4_0/q14a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark4_0/q49/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark4_0/q5a/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark4_0/q72/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark4_0/q75/explain.txt   |  2 +-
 .../approved-plans-v2_7-spark4_0/q77a/explain.txt  |  2 +-
 .../approved-plans-v2_7-spark4_0/q80a/explain.txt  |  2 +-
 .../approved-plans-v2_7/q10a/explain.txt           |  2 +-
 .../approved-plans-v2_7/q11/explain.txt            |  2 +-
 .../approved-plans-v2_7/q14/explain.txt            |  2 +-
 .../approved-plans-v2_7/q14a/explain.txt           |  2 +-
 .../approved-plans-v2_7/q18a/explain.txt           |  2 +-
 .../approved-plans-v2_7/q22a/explain.txt           |  2 +-
 .../approved-plans-v2_7/q27a/explain.txt           |  2 +-
 .../approved-plans-v2_7/q35a/explain.txt           |  2 +-
 .../approved-plans-v2_7/q49/explain.txt            |  2 +-
 .../approved-plans-v2_7/q5a/explain.txt            |  2 +-
 .../approved-plans-v2_7/q6/explain.txt             |  2 +-
 .../approved-plans-v2_7/q72/explain.txt            |  2 +-
 .../approved-plans-v2_7/q74/explain.txt            |  2 +-
 .../approved-plans-v2_7/q75/explain.txt            |  2 +-
 .../approved-plans-v2_7/q77a/explain.txt           |  2 +-
 .../approved-plans-v2_7/q80a/explain.txt           |  2 +-
 .../org/apache/comet/CometExpressionSuite.scala    |  6 +--
 .../org/apache/comet/exec/CometExecSuite.scala     | 58 ++++++++++++++++++++--
 162 files changed, 292 insertions(+), 201 deletions(-)

diff --git a/dev/diffs/4.0.0.diff b/dev/diffs/4.0.0.diff
index fb4150a53..7d2dc790d 100644
--- a/dev/diffs/4.0.0.diff
+++ b/dev/diffs/4.0.0.diff
@@ -1,5 +1,5 @@
 diff --git a/pom.xml b/pom.xml
-index a4b1b2c3c9f..63ec4784625 100644
+index 443d46a4302..63ec4784625 100644
 --- a/pom.xml
 +++ b/pom.xml
 @@ -148,6 +148,8 @@
@@ -1523,19 +1523,30 @@ index 418ca3430bb..eb8267192f8 100644
        withTempPath { path =>
          val dir = path.getCanonicalPath
 diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/InsertSortForLimitAndOffsetSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/InsertSortForLimitAndOffsetSuite.scala
-index d1b11a74cf3..8ea0129b3af 100644
+index d1b11a74cf3..08087c80201 100644
 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/InsertSortForLimitAndOffsetSuite.scala
 +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/InsertSortForLimitAndOffsetSuite.scala
-@@ -17,7 +17,7 @@
+@@ -17,8 +17,9 @@
  
  package org.apache.spark.sql.execution
  
 -import org.apache.spark.sql.{Dataset, QueryTest}
 +import org.apache.spark.sql.{Dataset, IgnoreComet, QueryTest}
  import org.apache.spark.sql.IntegratedUDFTestUtils._
++import org.apache.spark.sql.comet.CometCollectLimitExec
  import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
  import org.apache.spark.sql.functions.rand
-@@ -77,7 +77,9 @@ class InsertSortForLimitAndOffsetSuite extends QueryTest
+ import org.apache.spark.sql.internal.SQLConf
+@@ -39,7 +40,7 @@ class InsertSortForLimitAndOffsetSuite extends QueryTest
+ 
+   private def assertHasCollectLimitExec(plan: SparkPlan): Unit = {
+     assert(find(plan) {
+-      case _: CollectLimitExec => true
++      case _: CollectLimitExec | _: CometCollectLimitExec => true
+       case _ => false
+     }.isDefined)
+   }
+@@ -77,7 +78,9 @@ class InsertSortForLimitAndOffsetSuite extends QueryTest
      assert(!hasLocalSort(physicalPlan))
    }
  
@@ -1546,7 +1557,7 @@ index d1b11a74cf3..8ea0129b3af 100644
      withSQLConf(SQLConf.TOP_K_SORT_FALLBACK_THRESHOLD.key -> "1") {
        val df = spark.range(10).orderBy($"id" % 8).limit(2)
        df.collect()
-@@ -88,7 +90,9 @@ class InsertSortForLimitAndOffsetSuite extends QueryTest
+@@ -88,7 +91,9 @@ class InsertSortForLimitAndOffsetSuite extends QueryTest
      }
    }
  
@@ -1557,7 +1568,7 @@ index d1b11a74cf3..8ea0129b3af 100644
      withSQLConf(
        SQLConf.TOP_K_SORT_FALLBACK_THRESHOLD.key -> "1",
        // To trigger the bug, we have to disable the coalescing optimization. Otherwise we use only
-@@ -117,7 +121,9 @@ class InsertSortForLimitAndOffsetSuite extends QueryTest
+@@ -117,7 +122,9 @@ class InsertSortForLimitAndOffsetSuite extends QueryTest
      assert(!hasLocalSort(physicalPlan))
    }
  
diff --git a/native/core/src/execution/planner.rs b/native/core/src/execution/planner.rs
index 6c46d1b0a..600c1ef2e 100644
--- a/native/core/src/execution/planner.rs
+++ b/native/core/src/execution/planner.rs
@@ -94,6 +94,7 @@ use arrow::buffer::BooleanBuffer;
 use datafusion::common::utils::SingleRowListArrayBuilder;
 use datafusion::physical_plan::coalesce_batches::CoalesceBatchesExec;
 use datafusion::physical_plan::filter::FilterExec as DataFusionFilterExec;
+use datafusion::physical_plan::limit::GlobalLimitExec;
 use datafusion_comet_proto::spark_operator::SparkFilePartition;
 use datafusion_comet_proto::{
     spark_expression::{
@@ -1283,12 +1284,30 @@ impl PhysicalPlanner {
             OpStruct::Limit(limit) => {
                 assert_eq!(children.len(), 1);
                 let num = limit.limit;
+                let offset: i32 = limit.offset;
+                if num != -1 && offset > num {
+                    return Err(GeneralError(format!(
+                        "Invalid limit/offset combination: [{num}. {offset}]"
+                    )));
+                }
                 let (scans, child) = self.create_plan(&children[0], inputs, partition_count)?;
-
-                let limit = Arc::new(LocalLimitExec::new(
-                    Arc::clone(&child.native_plan),
-                    num as usize,
-                ));
+                let limit: Arc<dyn ExecutionPlan> = if offset == 0 {
+                    Arc::new(LocalLimitExec::new(
+                        Arc::clone(&child.native_plan),
+                        num as usize,
+                    ))
+                } else {
+                    let fetch = if num == -1 {
+                        None
+                    } else {
+                        Some((num - offset) as usize)
+                    };
+                    Arc::new(GlobalLimitExec::new(
+                        Arc::clone(&child.native_plan),
+                        offset as usize,
+                        fetch,
+                    ))
+                };
                 Ok((
                     scans,
                     Arc::new(SparkPlan::new(spark_plan.plan_id, limit, vec![child])),
@@ -1305,23 +1324,26 @@ impl PhysicalPlanner {
                     .collect();
 
                 let fetch = sort.fetch.map(|num| num as usize);
-
                 // SortExec caches batches so we need to make a copy of incoming batches. Also,
                 // SortExec fails in some cases if we do not unpack dictionary-encoded arrays, and
                 // it would be more efficient if we could avoid that.
                 // https://github.com/apache/datafusion-comet/issues/963
                 let child_copied = Self::wrap_in_copy_exec(Arc::clone(&child.native_plan));
 
-                let sort = Arc::new(
+                let mut sort_exec: Arc<dyn ExecutionPlan> = Arc::new(
                     SortExec::new(LexOrdering::new(exprs?).unwrap(), Arc::clone(&child_copied))
                         .with_fetch(fetch),
                 );
 
+                if let Some(skip) = sort.skip.filter(|&n| n > 0).map(|n| n as usize) {
+                    sort_exec = Arc::new(GlobalLimitExec::new(sort_exec, skip, None));
+                }
+
                 Ok((
                     scans,
                     Arc::new(SparkPlan::new(
                         spark_plan.plan_id,
-                        sort,
+                        sort_exec,
                         vec![Arc::clone(&child)],
                     )),
                 ))
diff --git a/native/proto/src/proto/operator.proto b/native/proto/src/proto/operator.proto
index 3470ba810..ac34def81 100644
--- a/native/proto/src/proto/operator.proto
+++ b/native/proto/src/proto/operator.proto
@@ -117,6 +117,7 @@ message Filter {
 message Sort {
   repeated spark.spark_expression.Expr sort_orders = 1;
   optional int32 fetch = 3;
+  optional int32 skip = 4;
 }
 
 message HashAggregate {
diff --git a/spark/src/main/scala/org/apache/comet/rules/CometExecRule.scala b/spark/src/main/scala/org/apache/comet/rules/CometExecRule.scala
index a1464a2e0..ceee7145e 100644
--- a/spark/src/main/scala/org/apache/comet/rules/CometExecRule.scala
+++ b/spark/src/main/scala/org/apache/comet/rules/CometExecRule.scala
@@ -201,10 +201,10 @@ case class CometExecRule(session: SparkSession) extends Rule[SparkPlan] {
       case op: LocalLimitExec =>
         newPlanWithProto(op, CometLocalLimitExec(_, op, op.limit, op.child, SerializedPlan(None)))
 
-      case op: GlobalLimitExec if op.offset == 0 =>
+      case op: GlobalLimitExec =>
         newPlanWithProto(
           op,
-          CometGlobalLimitExec(_, op, op.limit, op.child, SerializedPlan(None)))
+          CometGlobalLimitExec(_, op, op.limit, op.offset, op.child, SerializedPlan(None)))
 
       case op: CollectLimitExec =>
         val fallbackReasons = new ListBuffer[String]()
@@ -214,9 +214,6 @@ case class CometExecRule(session: SparkSession) extends Rule[SparkPlan] {
         if (!isCometShuffleEnabled(conf)) {
           fallbackReasons += "Comet shuffle is not enabled"
         }
-        if (op.offset != 0) {
-          fallbackReasons += "CollectLimit with non-zero offset is not supported"
-        }
         if (fallbackReasons.nonEmpty) {
           withInfos(op, fallbackReasons.toSet)
         } else {
@@ -382,6 +379,7 @@ case class CometExecRule(session: SparkSession) extends Rule[SparkPlan] {
                 s,
                 s.output,
                 s.limit,
+                s.offset,
                 s.sortOrder,
                 s.projectList,
                 s.child)
diff --git a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
index 35ebabdac..f0b4059b9 100644
--- a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
+++ b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
@@ -1840,13 +1840,10 @@ object QueryPlanSerde extends Logging with CometExprShim {
 
       case globalLimitExec: GlobalLimitExec
           if CometConf.COMET_EXEC_GLOBAL_LIMIT_ENABLED.get(conf) =>
-        // TODO: We don't support negative limit for now.
-        if (childOp.nonEmpty && globalLimitExec.limit >= 0) {
+        if (childOp.nonEmpty) {
           val limitBuilder = OperatorOuterClass.Limit.newBuilder()
 
-          // TODO: Spark 3.3 might have negative limit (-1) for Offset usage.
-          // When we upgrade to Spark 3.3., we need to address it here.
-          limitBuilder.setLimit(globalLimitExec.limit)
+          limitBuilder.setLimit(globalLimitExec.limit).setOffset(globalLimitExec.offset)
 
           Some(builder.setLimit(limitBuilder).build())
         } else {
diff --git a/spark/src/main/scala/org/apache/spark/sql/comet/CometCollectLimitExec.scala b/spark/src/main/scala/org/apache/spark/sql/comet/CometCollectLimitExec.scala
index f75af5076..09794e8e2 100644
--- a/spark/src/main/scala/org/apache/spark/sql/comet/CometCollectLimitExec.scala
+++ b/spark/src/main/scala/org/apache/spark/sql/comet/CometCollectLimitExec.scala
@@ -36,8 +36,6 @@ import com.google.common.base.Objects
  *
  * Similar to `CometTakeOrderedAndProjectExec`, it contains two native executions seperated by a
  * Comet shuffle.
- *
- * TODO: support offset semantics
  */
 case class CometCollectLimitExec(
     override val originalPlan: SparkPlan,
@@ -64,7 +62,10 @@ case class CometCollectLimitExec(
     new UnsafeRowSerializer(child.output.size, longMetric("dataSize"))
 
   override def executeCollect(): Array[InternalRow] = {
-    ColumnarToRowExec(child).executeTake(limit)
+    val rows =
+      if (limit >= 0) ColumnarToRowExec(child).executeTake(limit)
+      else ColumnarToRowExec(child).executeCollect()
+    if (offset > 0) rows.drop(offset) else rows
   }
 
   protected override def doExecuteColumnar(): RDD[ColumnarBatch] = {
@@ -91,7 +92,7 @@ case class CometCollectLimitExec(
 
         new CometShuffledBatchRDD(dep, readMetrics)
       }
-      CometExecUtils.getNativeLimitRDD(singlePartitionRDD, output, limit)
+      CometExecUtils.getNativeLimitRDD(singlePartitionRDD, output, limit, offset)
     }
   }
 
diff --git a/spark/src/main/scala/org/apache/spark/sql/comet/CometExecUtils.scala b/spark/src/main/scala/org/apache/spark/sql/comet/CometExecUtils.scala
index 2fc73bb7c..63cf323a8 100644
--- a/spark/src/main/scala/org/apache/spark/sql/comet/CometExecUtils.scala
+++ b/spark/src/main/scala/org/apache/spark/sql/comet/CometExecUtils.scala
@@ -50,10 +50,11 @@ object CometExecUtils {
   def getNativeLimitRDD(
       childPlan: RDD[ColumnarBatch],
       outputAttribute: Seq[Attribute],
-      limit: Int): RDD[ColumnarBatch] = {
+      limit: Int,
+      offset: Int = 0): RDD[ColumnarBatch] = {
     val numParts = childPlan.getNumPartitions
     childPlan.mapPartitionsWithIndexInternal { case (idx, iter) =>
-      val limitOp = CometExecUtils.getLimitNativePlan(outputAttribute, limit).get
+      val limitOp = CometExecUtils.getLimitNativePlan(outputAttribute, limit, offset).get
       CometExec.getCometIterator(Seq(iter), outputAttribute.length, limitOp, numParts, idx)
     }
   }
@@ -66,8 +67,9 @@ object CometExecUtils {
       outputAttributes: Seq[Attribute],
       sortOrder: Seq[SortOrder],
       child: SparkPlan,
-      limit: Int): Option[Operator] = {
-    getTopKNativePlan(outputAttributes, sortOrder, child, limit).flatMap { topK =>
+      limit: Int,
+      offset: Int = 0): Option[Operator] = {
+    getTopKNativePlan(outputAttributes, sortOrder, child, limit, offset).flatMap { topK =>
       val exprs = projectList.map(exprToProto(_, child.output))
 
       if (exprs.forall(_.isDefined)) {
@@ -87,7 +89,10 @@ object CometExecUtils {
    * Prepare Limit native plan for Comet operators which take the first `limit` elements of each
    * child partition
    */
-  def getLimitNativePlan(outputAttributes: Seq[Attribute], limit: Int): Option[Operator] = {
+  def getLimitNativePlan(
+      outputAttributes: Seq[Attribute],
+      limit: Int,
+      offset: Int = 0): Option[Operator] = {
     val scanBuilder = OperatorOuterClass.Scan.newBuilder().setSource("LimitInput")
     val scanOpBuilder = OperatorOuterClass.Operator.newBuilder()
 
@@ -100,6 +105,7 @@ object CometExecUtils {
 
       val limitBuilder = OperatorOuterClass.Limit.newBuilder()
       limitBuilder.setLimit(limit)
+      limitBuilder.setOffset(offset)
 
       val limitOpBuilder = OperatorOuterClass.Operator
         .newBuilder()
@@ -117,7 +123,8 @@ object CometExecUtils {
       outputAttributes: Seq[Attribute],
       sortOrder: Seq[SortOrder],
       child: SparkPlan,
-      limit: Int): Option[Operator] = {
+      limit: Int,
+      offset: Int = 0): Option[Operator] = {
     val scanBuilder = OperatorOuterClass.Scan.newBuilder().setSource("TopKInput")
     val scanOpBuilder = OperatorOuterClass.Operator.newBuilder()
 
@@ -134,6 +141,7 @@ object CometExecUtils {
         val sortBuilder = OperatorOuterClass.Sort.newBuilder()
         sortBuilder.addAllSortOrders(sortOrders.map(_.get).asJava)
         sortBuilder.setFetch(limit)
+        sortBuilder.setSkip(offset)
 
         val sortOpBuilder = OperatorOuterClass.Operator
           .newBuilder()
diff --git a/spark/src/main/scala/org/apache/spark/sql/comet/CometTakeOrderedAndProjectExec.scala b/spark/src/main/scala/org/apache/spark/sql/comet/CometTakeOrderedAndProjectExec.scala
index 885253868..d6cc3602a 100644
--- a/spark/src/main/scala/org/apache/spark/sql/comet/CometTakeOrderedAndProjectExec.scala
+++ b/spark/src/main/scala/org/apache/spark/sql/comet/CometTakeOrderedAndProjectExec.scala
@@ -43,6 +43,7 @@ case class CometTakeOrderedAndProjectExec(
     override val originalPlan: SparkPlan,
     override val output: Seq[Attribute],
     limit: Int,
+    offset: Int,
     sortOrder: Seq[SortOrder],
     projectList: Seq[NamedExpression],
     child: SparkPlan)
@@ -68,7 +69,7 @@ case class CometTakeOrderedAndProjectExec(
 
   protected override def doExecuteColumnar(): RDD[ColumnarBatch] = {
     val childRDD = child.executeColumnar()
-    if (childRDD.getNumPartitions == 0) {
+    if (childRDD.getNumPartitions == 0 || limit == 0) {
       new ParallelCollectionRDD(sparkContext, Seq.empty[ColumnarBatch], 1, Map.empty)
     } else {
       val singlePartitionRDD = if (childRDD.getNumPartitions == 1) {
@@ -101,7 +102,7 @@ case class CometTakeOrderedAndProjectExec(
 
       singlePartitionRDD.mapPartitionsInternal { iter =>
         val topKAndProjection = CometExecUtils
-          .getProjectionNativePlan(projectList, child.output, sortOrder, child, limit)
+          .getProjectionNativePlan(projectList, child.output, sortOrder, child, limit, offset)
           .get
         val it = CometExec.getCometIterator(Seq(iter), output.length, topKAndProjection, 1, 0)
         setSubqueries(it.id, this)
@@ -122,7 +123,8 @@ case class CometTakeOrderedAndProjectExec(
     val orderByString = truncatedString(sortOrder, "[", ",", "]", maxFields)
     val outputString = truncatedString(output, "[", ",", "]", maxFields)
 
-    s"CometTakeOrderedAndProjectExec(limit=$limit, orderBy=$orderByString, output=$outputString)"
+    s"CometTakeOrderedAndProjectExec(limit=$limit, offset=$offset, " +
+      s"orderBy=$orderByString, output=$outputString)"
   }
 
   override protected def withNewChildInternal(newChild: SparkPlan): SparkPlan =
@@ -130,11 +132,10 @@ case class CometTakeOrderedAndProjectExec(
 }
 
 object CometTakeOrderedAndProjectExec {
-  // TODO: support offset for Spark 3.4
   def isSupported(plan: TakeOrderedAndProjectExec): Boolean = {
     val exprs = plan.projectList.map(exprToProto(_, plan.child.output))
     val sortOrders = plan.sortOrder.map(exprToProto(_, plan.child.output))
-    exprs.forall(_.isDefined) && sortOrders.forall(_.isDefined) && plan.offset == 0 &&
+    exprs.forall(_.isDefined) && sortOrders.forall(_.isDefined) &&
     supportedSortType(plan, plan.sortOrder)
   }
 }
diff --git a/spark/src/main/scala/org/apache/spark/sql/comet/operators.scala b/spark/src/main/scala/org/apache/spark/sql/comet/operators.scala
index 3b9c6bdbc..593f4f3a4 100644
--- a/spark/src/main/scala/org/apache/spark/sql/comet/operators.scala
+++ b/spark/src/main/scala/org/apache/spark/sql/comet/operators.scala
@@ -577,6 +577,7 @@ case class CometGlobalLimitExec(
     override val nativeOp: Operator,
     override val originalPlan: SparkPlan,
     limit: Int,
+    offset: Int,
     child: SparkPlan,
     override val serializedPlanOpt: SerializedPlan)
     extends CometUnaryExec {
@@ -588,20 +589,23 @@ case class CometGlobalLimitExec(
   override protected def withNewChildInternal(newChild: SparkPlan): SparkPlan =
     this.copy(child = newChild)
 
-  override def stringArgs: Iterator[Any] = Iterator(limit, child)
+  override def stringArgs: Iterator[Any] = Iterator(limit, offset, child)
 
   override def equals(obj: Any): Boolean = {
     obj match {
       case other: CometGlobalLimitExec =>
         this.output == other.output &&
-        this.limit == other.limit && this.child == other.child &&
+        this.limit == other.limit &&
+        this.offset == other.offset &&
+        this.child == other.child &&
         this.serializedPlanOpt == other.serializedPlanOpt
       case _ =>
         false
     }
   }
 
-  override def hashCode(): Int = Objects.hashCode(output, limit: java.lang.Integer, child)
+  override def hashCode(): Int =
+    Objects.hashCode(output, limit: java.lang.Integer, offset: java.lang.Integer, child)
 }
 
 case class CometExpandExec(
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q1/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q1/explain.txt
index 6b5d05df7..880e647e1 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q1/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q1/explain.txt
@@ -227,7 +227,7 @@ Arguments: [c_customer_id#28], [c_customer_id#28]
 
 (40) CometTakeOrderedAndProject
 Input [1]: [c_customer_id#28]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#28 ASC NULLS FIRST], output=[c_customer_id#28]), [c_customer_id#28], 100, [c_customer_id#28 ASC NULLS FIRST], [c_customer_id#28]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#28 ASC NULLS FIRST], output=[c_customer_id#28]), [c_customer_id#28], 100, 0, [c_customer_id#28 ASC NULLS FIRST], [c_customer_id#28]
 
 (41) CometColumnarToRow [codegen id : 1]
 Input [1]: [c_customer_id#28]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q11/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q11/explain.txt
index f2cee5ac3..4ff78694c 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q11/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q11/explain.txt
@@ -411,7 +411,7 @@ Arguments: [customer_preferred_cust_flag#42], [customer_preferred_cust_flag#42]
 
 (72) CometTakeOrderedAndProject
 Input [1]: [customer_preferred_cust_flag#42]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_preferred_cust_flag#42 ASC NULLS FIRST], output=[customer_preferred_cust_flag#42]), [customer_preferred_cust_flag#42], 100, [customer_preferred_cust_flag#42 ASC NULLS FIRST], [customer_preferred_cust_flag#42]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_preferred_cust_flag#42 ASC NULLS FIRST], output=[customer_preferred_cust_flag#42]), [customer_preferred_cust_flag#42], 100, 0, [customer_preferred_cust_flag#42 ASC NULLS FIRST], [customer_preferred_cust_flag#42]
 
 (73) CometColumnarToRow [codegen id : 1]
 Input [1]: [customer_preferred_cust_flag#42]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q14a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q14a/explain.txt
index 7d4428d5b..5a3251a10 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q14a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q14a/explain.txt
@@ -567,7 +567,7 @@ Functions [2]: [sum(sales#49), sum(number_sales#50)]
 
 (101) CometTakeOrderedAndProject
 Input [6]: [channel#91, i_brand_id#92, i_class_id#93, i_category_id#94, sum(sales)#99, sum(number_sales)#100]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#91 ASC NULLS FIRST,i_brand_id#92 ASC NULLS FIRST,i_class_id#93 ASC NULLS FIRST,i_category_id#94 ASC NULLS FIRST], output=[channel#91,i_brand_id#92,i_class_id#93,i_category_id#94,sum(sales)#99,sum(number_sales)#100]), [channel#91, i_brand_id#92, i_class_id#93, i_category_id#94, sum(sales)#99, sum(number_sales)#100], 100, [channel#91 ASC NULLS FIRST, i_brand_id#92 ASC NULLS FIRST, i_class_id#93 ASC NULLS FIRST, i_category_id#94 A [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#91 ASC NULLS FIRST,i_brand_id#92 ASC NULLS FIRST,i_class_id#93 ASC NULLS FIRST,i_category_id#94 ASC NULLS FIRST], output=[channel#91,i_brand_id#92,i_class_id#93,i_category_id#94,sum(sales)#99,sum(number_sales)#100]), [channel#91, i_brand_id#92, i_class_id#93, i_category_id#94, sum(sales)#99, sum(number_sales)#100], 100, 0, [channel#91 ASC NULLS FIRST, i_brand_id#92 ASC NULLS FIRST, i_class_id#93 ASC NULLS FIRST, i_category_id#9 [...]
 
 (102) CometColumnarToRow [codegen id : 1]
 Input [6]: [channel#91, i_brand_id#92, i_class_id#93, i_category_id#94, sum(sales)#99, sum(number_sales)#100]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q14b/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q14b/explain.txt
index a1c22982c..8ad86731e 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q14b/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q14b/explain.txt
@@ -478,7 +478,7 @@ Arguments: [i_brand_id#40, i_class_id#41, i_category_id#42], [i_brand_id#62, i_c
 
 (84) CometTakeOrderedAndProject
 Input [12]: [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#72, i_brand_id#62, i_class_id#63, i_category_id#64, sales#73, number_sales#74]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#50,i_brand_id#40,i_class_id#41,i_category_id#42,sales#51,number_sales#52,channel#72,i_brand_id#62,i_class_id#63,i_category_id#64,sales#73,number_sales#74]), [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#72, i_brand_id#62, i_class_id#63, i_category_id#64, sales#73, number_sales# [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#50,i_brand_id#40,i_class_id#41,i_category_id#42,sales#51,number_sales#52,channel#72,i_brand_id#62,i_class_id#63,i_category_id#64,sales#73,number_sales#74]), [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#72, i_brand_id#62, i_class_id#63, i_category_id#64, sales#73, number_sales# [...]
 
 (85) CometColumnarToRow [codegen id : 1]
 Input [12]: [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#72, i_brand_id#62, i_class_id#63, i_category_id#64, sales#73, number_sales#74]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q15/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q15/explain.txt
index a56066b83..9abb6a939 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q15/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q15/explain.txt
@@ -133,7 +133,7 @@ Functions [1]: [sum(UnscaledValue(cs_sales_price#2))]
 
 (23) CometTakeOrderedAndProject
 Input [2]: [ca_zip#11, sum(cs_sales_price)#16]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_zip#11 ASC NULLS FIRST], output=[ca_zip#11,sum(cs_sales_price)#16]), [ca_zip#11, sum(cs_sales_price)#16], 100, [ca_zip#11 ASC NULLS FIRST], [ca_zip#11, sum(cs_sales_price)#16]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_zip#11 ASC NULLS FIRST], output=[ca_zip#11,sum(cs_sales_price)#16]), [ca_zip#11, sum(cs_sales_price)#16], 100, 0, [ca_zip#11 ASC NULLS FIRST], [ca_zip#11, sum(cs_sales_price)#16]
 
 (24) CometColumnarToRow [codegen id : 1]
 Input [2]: [ca_zip#11, sum(cs_sales_price)#16]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q17/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q17/explain.txt
index ab58eb37e..ecd1fec3f 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q17/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q17/explain.txt
@@ -247,7 +247,7 @@ Functions [9]: [count(ss_quantity#5), avg(ss_quantity#5), stddev_samp(cast(ss_qu
 
 (43) CometTakeOrderedAndProject
 Input [15]: [i_item_id#30, i_item_desc#29, s_state#26, store_sales_quantitycount#49, store_sales_quantityave#50, store_sales_quantitystdev#51, store_sales_quantitycov#52, as_store_returns_quantitycount#53, as_store_returns_quantityave#54, as_store_returns_quantitystdev#55, store_returns_quantitycov#56, catalog_sales_quantitycount#57, catalog_sales_quantityave#58, catalog_sales_quantitystdev#59, catalog_sales_quantitycov#60]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#30 ASC NULLS FIRST,i_item_desc#29 ASC NULLS FIRST,s_state#26 ASC NULLS FIRST], output=[i_item_id#30,i_item_desc#29,s_state#26,store_sales_quantitycount#49,store_sales_quantityave#50,store_sales_quantitystdev#51,store_sales_quantitycov#52,as_store_returns_quantitycount#53,as_store_returns_quantityave#54,as_store_returns_quantitystdev#55,store_returns_quantitycov#56,catalog_sales_quantitycount#57,catalog_sales_quantityave#58,ca [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#30 ASC NULLS FIRST,i_item_desc#29 ASC NULLS FIRST,s_state#26 ASC NULLS FIRST], output=[i_item_id#30,i_item_desc#29,s_state#26,store_sales_quantitycount#49,store_sales_quantityave#50,store_sales_quantitystdev#51,store_sales_quantitycov#52,as_store_returns_quantitycount#53,as_store_returns_quantityave#54,as_store_returns_quantitystdev#55,store_returns_quantitycov#56,catalog_sales_quantitycount#57,catalog_sales_quantityave#58,ca [...]
 
 (44) CometColumnarToRow [codegen id : 1]
 Input [15]: [i_item_id#30, i_item_desc#29, s_state#26, store_sales_quantitycount#49, store_sales_quantityave#50, store_sales_quantitystdev#51, store_sales_quantitycov#52, as_store_returns_quantitycount#53, as_store_returns_quantityave#54, as_store_returns_quantitystdev#55, store_returns_quantitycov#56, catalog_sales_quantitycount#57, catalog_sales_quantityave#58, catalog_sales_quantitystdev#59, catalog_sales_quantitycov#60]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q18/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q18/explain.txt
index 29e12f97b..f04ca8727 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q18/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q18/explain.txt
@@ -240,7 +240,7 @@ Functions [7]: [avg(cast(cs_quantity#4 as decimal(12,2))), avg(cast(cs_list_pric
 
 (42) CometTakeOrderedAndProject
 Input [11]: [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#50, agg2#51, agg3#52, agg4#53, agg5#54, agg6#55, agg7#56]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_country#32 ASC NULLS FIRST,ca_state#33 ASC NULLS FIRST,ca_county#34 ASC NULLS FIRST,i_item_id#31 ASC NULLS FIRST], output=[i_item_id#31,ca_country#32,ca_state#33,ca_county#34,agg1#50,agg2#51,agg3#52,agg4#53,agg5#54,agg6#55,agg7#56]), [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#50, agg2#51, agg3#52, agg4#53, agg5#54, agg6#55, agg7#56], 100, [ca_country#32 ASC NULLS FIRST, ca_state#33 ASC NULLS FIRST, ca_county#34 AS [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_country#32 ASC NULLS FIRST,ca_state#33 ASC NULLS FIRST,ca_county#34 ASC NULLS FIRST,i_item_id#31 ASC NULLS FIRST], output=[i_item_id#31,ca_country#32,ca_state#33,ca_county#34,agg1#50,agg2#51,agg3#52,agg4#53,agg5#54,agg6#55,agg7#56]), [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#50, agg2#51, agg3#52, agg4#53, agg5#54, agg6#55, agg7#56], 100, 0, [ca_country#32 ASC NULLS FIRST, ca_state#33 ASC NULLS FIRST, ca_county#34 [...]
 
 (43) CometColumnarToRow [codegen id : 1]
 Input [11]: [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#50, agg2#51, agg3#52, agg4#53, agg5#54, agg6#55, agg7#56]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q19/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q19/explain.txt
index 11c0339bb..9c7a334ef 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q19/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q19/explain.txt
@@ -201,7 +201,7 @@ Functions [1]: [sum(UnscaledValue(ss_ext_sales_price#7))]
 
 (35) CometTakeOrderedAndProject
 Input [5]: [brand_id#26, brand#27, i_manufact_id#12, i_manufact#16, ext_price#28]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ext_price#28 DESC NULLS LAST,brand#27 ASC NULLS FIRST,brand_id#26 ASC NULLS FIRST,i_manufact_id#12 ASC NULLS FIRST,i_manufact#16 ASC NULLS FIRST], output=[brand_id#26,brand#27,i_manufact_id#12,i_manufact#16,ext_price#28]), [brand_id#26, brand#27, i_manufact_id#12, i_manufact#16, ext_price#28], 100, [ext_price#28 DESC NULLS LAST, brand#27 ASC NULLS FIRST, brand_id#26 ASC NULLS FIRST, i_manufact_id#12 ASC NULLS FIRST, i_manufact#16 ASC N [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ext_price#28 DESC NULLS LAST,brand#27 ASC NULLS FIRST,brand_id#26 ASC NULLS FIRST,i_manufact_id#12 ASC NULLS FIRST,i_manufact#16 ASC NULLS FIRST], output=[brand_id#26,brand#27,i_manufact_id#12,i_manufact#16,ext_price#28]), [brand_id#26, brand#27, i_manufact_id#12, i_manufact#16, ext_price#28], 100, 0, [ext_price#28 DESC NULLS LAST, brand#27 ASC NULLS FIRST, brand_id#26 ASC NULLS FIRST, i_manufact_id#12 ASC NULLS FIRST, i_manufact#16 AS [...]
 
 (36) CometColumnarToRow [codegen id : 1]
 Input [5]: [brand_id#26, brand#27, i_manufact_id#12, i_manufact#16, ext_price#28]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q21/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q21/explain.txt
index f575a19a9..8f4413b65 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q21/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q21/explain.txt
@@ -133,7 +133,7 @@ Condition : (CASE WHEN (inv_before#16 > 0) THEN (knownfloatingpointnormalized(no
 
 (23) CometTakeOrderedAndProject
 Input [4]: [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_warehouse_name#7 ASC NULLS FIRST,i_item_id#11 ASC NULLS FIRST], output=[w_warehouse_name#7,i_item_id#11,inv_before#16,inv_after#17]), [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17], 100, [w_warehouse_name#7 ASC NULLS FIRST, i_item_id#11 ASC NULLS FIRST], [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_warehouse_name#7 ASC NULLS FIRST,i_item_id#11 ASC NULLS FIRST], output=[w_warehouse_name#7,i_item_id#11,inv_before#16,inv_after#17]), [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17], 100, 0, [w_warehouse_name#7 ASC NULLS FIRST, i_item_id#11 ASC NULLS FIRST], [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17]
 
 (24) CometColumnarToRow [codegen id : 1]
 Input [4]: [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q22/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q22/explain.txt
index 2b0bf616f..20dd5e20b 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q22/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q22/explain.txt
@@ -138,7 +138,7 @@ Functions [1]: [avg(inv_quantity_on_hand#3)]
 
 (24) CometTakeOrderedAndProject
 Input [5]: [i_product_name#18, i_brand#19, i_class#20, i_category#21, qoh#25]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[qoh#25 ASC NULLS FIRST,i_product_name#18 ASC NULLS FIRST,i_brand#19 ASC NULLS FIRST,i_class#20 ASC NULLS FIRST,i_category#21 ASC NULLS FIRST], output=[i_product_name#18,i_brand#19,i_class#20,i_category#21,qoh#25]), [i_product_name#18, i_brand#19, i_class#20, i_category#21, qoh#25], 100, [qoh#25 ASC NULLS FIRST, i_product_name#18 ASC NULLS FIRST, i_brand#19 ASC NULLS FIRST, i_class#20 ASC NULLS FIRST, i_category#21 ASC NULLS FIRST], [i_ [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[qoh#25 ASC NULLS FIRST,i_product_name#18 ASC NULLS FIRST,i_brand#19 ASC NULLS FIRST,i_class#20 ASC NULLS FIRST,i_category#21 ASC NULLS FIRST], output=[i_product_name#18,i_brand#19,i_class#20,i_category#21,qoh#25]), [i_product_name#18, i_brand#19, i_class#20, i_category#21, qoh#25], 100, 0, [qoh#25 ASC NULLS FIRST, i_product_name#18 ASC NULLS FIRST, i_brand#19 ASC NULLS FIRST, i_class#20 ASC NULLS FIRST, i_category#21 ASC NULLS FIRST],  [...]
 
 (25) CometColumnarToRow [codegen id : 1]
 Input [5]: [i_product_name#18, i_brand#19, i_class#20, i_category#21, qoh#25]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q23b/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q23b/explain.txt
index 994066e37..82f22aaee 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q23b/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q23b/explain.txt
@@ -482,7 +482,7 @@ Child 1 Input [3]: [c_last_name#54, c_first_name#53, sales#59]
 
 (87) CometTakeOrderedAndProject
 Input [3]: [c_last_name#33, c_first_name#32, sales#58]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#33 ASC NULLS FIRST,c_first_name#32 ASC NULLS FIRST,sales#58 ASC NULLS FIRST], output=[c_last_name#33,c_first_name#32,sales#58]), [c_last_name#33, c_first_name#32, sales#58], 100, [c_last_name#33 ASC NULLS FIRST, c_first_name#32 ASC NULLS FIRST, sales#58 ASC NULLS FIRST], [c_last_name#33, c_first_name#32, sales#58]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#33 ASC NULLS FIRST,c_first_name#32 ASC NULLS FIRST,sales#58 ASC NULLS FIRST], output=[c_last_name#33,c_first_name#32,sales#58]), [c_last_name#33, c_first_name#32, sales#58], 100, 0, [c_last_name#33 ASC NULLS FIRST, c_first_name#32 ASC NULLS FIRST, sales#58 ASC NULLS FIRST], [c_last_name#33, c_first_name#32, sales#58]
 
 (88) CometColumnarToRow [codegen id : 1]
 Input [3]: [c_last_name#33, c_first_name#32, sales#58]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q25/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q25/explain.txt
index e63dc7818..a284abb21 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q25/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q25/explain.txt
@@ -247,7 +247,7 @@ Functions [3]: [sum(UnscaledValue(ss_net_profit#5)), sum(UnscaledValue(sr_net_lo
 
 (43) CometTakeOrderedAndProject
 Input [7]: [i_item_id#33, i_item_desc#32, s_store_id#29, s_store_name#28, store_sales_profit#37, store_returns_loss#38, catalog_sales_profit#39]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#33 ASC NULLS FIRST,i_item_desc#32 ASC NULLS FIRST,s_store_id#29 ASC NULLS FIRST,s_store_name#28 ASC NULLS FIRST], output=[i_item_id#33,i_item_desc#32,s_store_id#29,s_store_name#28,store_sales_profit#37,store_returns_loss#38,catalog_sales_profit#39]), [i_item_id#33, i_item_desc#32, s_store_id#29, s_store_name#28, store_sales_profit#37, store_returns_loss#38, catalog_sales_profit#39], 100, [i_item_id#33 ASC NULLS FIRST, i_item_ [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#33 ASC NULLS FIRST,i_item_desc#32 ASC NULLS FIRST,s_store_id#29 ASC NULLS FIRST,s_store_name#28 ASC NULLS FIRST], output=[i_item_id#33,i_item_desc#32,s_store_id#29,s_store_name#28,store_sales_profit#37,store_returns_loss#38,catalog_sales_profit#39]), [i_item_id#33, i_item_desc#32, s_store_id#29, s_store_name#28, store_sales_profit#37, store_returns_loss#38, catalog_sales_profit#39], 100, 0, [i_item_id#33 ASC NULLS FIRST, i_it [...]
 
 (44) CometColumnarToRow [codegen id : 1]
 Input [7]: [i_item_id#33, i_item_desc#32, s_store_id#29, s_store_name#28, store_sales_profit#37, store_returns_loss#38, catalog_sales_profit#39]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q26/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q26/explain.txt
index a065e1234..bf78c49fd 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q26/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q26/explain.txt
@@ -172,7 +172,7 @@ Functions [4]: [avg(cs_quantity#4), avg(UnscaledValue(cs_list_price#5)), avg(Uns
 
 (30) CometTakeOrderedAndProject
 Input [5]: [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#18 ASC NULLS FIRST], output=[i_item_id#18,agg1#30,agg2#31,agg3#32,agg4#33]), [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33], 100, [i_item_id#18 ASC NULLS FIRST], [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#18 ASC NULLS FIRST], output=[i_item_id#18,agg1#30,agg2#31,agg3#32,agg4#33]), [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33], 100, 0, [i_item_id#18 ASC NULLS FIRST], [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
 
 (31) CometColumnarToRow [codegen id : 1]
 Input [5]: [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q27/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q27/explain.txt
index 65443cbc1..6873f4828 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q27/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q27/explain.txt
@@ -177,7 +177,7 @@ Functions [4]: [avg(ss_quantity#4), avg(UnscaledValue(ss_list_price#5)), avg(Uns
 
 (31) CometTakeOrderedAndProject
 Input [7]: [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#22 ASC NULLS FIRST,s_state#23 ASC NULLS FIRST], output=[i_item_id#22,s_state#23,g_state#33,agg1#34,agg2#35,agg3#36,agg4#37]), [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37], 100, [i_item_id#22 ASC NULLS FIRST, s_state#23 ASC NULLS FIRST], [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#22 ASC NULLS FIRST,s_state#23 ASC NULLS FIRST], output=[i_item_id#22,s_state#23,g_state#33,agg1#34,agg2#35,agg3#36,agg4#37]), [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37], 100, 0, [i_item_id#22 ASC NULLS FIRST, s_state#23 ASC NULLS FIRST], [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37]
 
 (32) CometColumnarToRow [codegen id : 1]
 Input [7]: [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q29/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q29/explain.txt
index 16d5abf00..65169e693 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q29/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q29/explain.txt
@@ -266,7 +266,7 @@ Functions [3]: [sum(ss_quantity#5), sum(sr_return_quantity#11), sum(cs_quantity#
 
 (46) CometTakeOrderedAndProject
 Input [7]: [i_item_id#34, i_item_desc#33, s_store_id#30, s_store_name#29, store_sales_quantity#38, store_returns_quantity#39, catalog_sales_quantity#40]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#34 ASC NULLS FIRST,i_item_desc#33 ASC NULLS FIRST,s_store_id#30 ASC NULLS FIRST,s_store_name#29 ASC NULLS FIRST], output=[i_item_id#34,i_item_desc#33,s_store_id#30,s_store_name#29,store_sales_quantity#38,store_returns_quantity#39,catalog_sales_quantity#40]), [i_item_id#34, i_item_desc#33, s_store_id#30, s_store_name#29, store_sales_quantity#38, store_returns_quantity#39, catalog_sales_quantity#40], 100, [i_item_id#34 ASC NULL [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#34 ASC NULLS FIRST,i_item_desc#33 ASC NULLS FIRST,s_store_id#30 ASC NULLS FIRST,s_store_name#29 ASC NULLS FIRST], output=[i_item_id#34,i_item_desc#33,s_store_id#30,s_store_name#29,store_sales_quantity#38,store_returns_quantity#39,catalog_sales_quantity#40]), [i_item_id#34, i_item_desc#33, s_store_id#30, s_store_name#29, store_sales_quantity#38, store_returns_quantity#39, catalog_sales_quantity#40], 100, 0, [i_item_id#34 ASC N [...]
 
 (47) CometColumnarToRow [codegen id : 1]
 Input [7]: [i_item_id#34, i_item_desc#33, s_store_id#30, s_store_name#29, store_sales_quantity#38, store_returns_quantity#39, catalog_sales_quantity#40]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q3/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q3/explain.txt
index 56f0aa3fc..ebd80da9c 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q3/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q3/explain.txt
@@ -104,7 +104,7 @@ Functions [1]: [sum(UnscaledValue(ss_ext_sales_price#5))]
 
 (18) CometTakeOrderedAndProject
 Input [4]: [d_year#2, brand_id#13, brand#14, sum_agg#15]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[d_year#2 ASC NULLS FIRST,sum_agg#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[d_year#2,brand_id#13,brand#14,sum_agg#15]), [d_year#2, brand_id#13, brand#14, sum_agg#15], 100, [d_year#2 ASC NULLS FIRST, sum_agg#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [d_year#2, brand_id#13, brand#14, sum_agg#15]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[d_year#2 ASC NULLS FIRST,sum_agg#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[d_year#2,brand_id#13,brand#14,sum_agg#15]), [d_year#2, brand_id#13, brand#14, sum_agg#15], 100, 0, [d_year#2 ASC NULLS FIRST, sum_agg#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [d_year#2, brand_id#13, brand#14, sum_agg#15]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [4]: [d_year#2, brand_id#13, brand#14, sum_agg#15]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q30/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q30/explain.txt
index 2094cfc0c..63b297678 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q30/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q30/explain.txt
@@ -276,7 +276,7 @@ Arguments: [c_customer_id#42, c_salutation#43, c_first_name#44, c_last_name#45,
 
 (49) CometTakeOrderedAndProject
 Input [13]: [c_customer_id#42, c_salutation#43, c_first_name#44, c_last_name#45, c_preferred_cust_flag#46, c_birth_day#35, c_birth_month#36, c_birth_year#37, c_birth_country#38, c_login#47, c_email_address#48, c_last_review_date#41, ctr_total_return#14]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#42 ASC NULLS FIRST,c_salutation#43 ASC NULLS FIRST,c_first_name#44 ASC NULLS FIRST,c_last_name#45 ASC NULLS FIRST,c_preferred_cust_flag#46 ASC NULLS FIRST,c_birth_day#35 ASC NULLS FIRST,c_birth_month#36 ASC NULLS FIRST,c_birth_year#37 ASC NULLS FIRST,c_birth_country#38 ASC NULLS FIRST,c_login#47 ASC NULLS FIRST,c_email_address#48 ASC NULLS FIRST,c_last_review_date#41 ASC NULLS FIRST,ctr_total_return#14 ASC NULLS FIRST], o [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#42 ASC NULLS FIRST,c_salutation#43 ASC NULLS FIRST,c_first_name#44 ASC NULLS FIRST,c_last_name#45 ASC NULLS FIRST,c_preferred_cust_flag#46 ASC NULLS FIRST,c_birth_day#35 ASC NULLS FIRST,c_birth_month#36 ASC NULLS FIRST,c_birth_year#37 ASC NULLS FIRST,c_birth_country#38 ASC NULLS FIRST,c_login#47 ASC NULLS FIRST,c_email_address#48 ASC NULLS FIRST,c_last_review_date#41 ASC NULLS FIRST,ctr_total_return#14 ASC NULLS FIRST], o [...]
 
 (50) CometColumnarToRow [codegen id : 1]
 Input [13]: [c_customer_id#42, c_salutation#43, c_first_name#44, c_last_name#45, c_preferred_cust_flag#46, c_birth_day#35, c_birth_month#36, c_birth_year#37, c_birth_country#38, c_login#47, c_email_address#48, c_last_review_date#41, ctr_total_return#14]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q33/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q33/explain.txt
index ba336095e..a2204820d 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q33/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q33/explain.txt
@@ -336,7 +336,7 @@ Functions [1]: [sum(total_sales#36)]
 
 (60) CometTakeOrderedAndProject
 Input [2]: [i_manufact_id#12, total_sales#41]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_sales#41 ASC NULLS FIRST], output=[i_manufact_id#12,total_sales#41]), [i_manufact_id#12, total_sales#41], 100, [total_sales#41 ASC NULLS FIRST], [i_manufact_id#12, total_sales#41]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_sales#41 ASC NULLS FIRST], output=[i_manufact_id#12,total_sales#41]), [i_manufact_id#12, total_sales#41], 100, 0, [total_sales#41 ASC NULLS FIRST], [i_manufact_id#12, total_sales#41]
 
 (61) CometColumnarToRow [codegen id : 1]
 Input [2]: [i_manufact_id#12, total_sales#41]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q37/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q37/explain.txt
index 3471befec..830dbbb9f 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q37/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q37/explain.txt
@@ -143,7 +143,7 @@ Functions: []
 
 (25) CometTakeOrderedAndProject
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, 0, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
 
 (26) CometColumnarToRow [codegen id : 1]
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q4/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q4/explain.txt
index b0b57f84d..7e2e253e1 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q4/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q4/explain.txt
@@ -603,7 +603,7 @@ Arguments: [customer_id#47, customer_first_name#48, customer_last_name#49, custo
 
 (106) CometTakeOrderedAndProject
 Input [7]: [customer_id#47, customer_first_name#48, customer_last_name#49, customer_preferred_cust_flag#50, customer_birth_country#51, customer_login#52, customer_email_address#53]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#47 ASC NULLS FIRST,customer_first_name#48 ASC NULLS FIRST,customer_last_name#49 ASC NULLS FIRST,customer_preferred_cust_flag#50 ASC NULLS FIRST,customer_birth_country#51 ASC NULLS FIRST,customer_login#52 ASC NULLS FIRST,customer_email_address#53 ASC NULLS FIRST], output=[customer_id#47,customer_first_name#48,customer_last_name#49,customer_preferred_cust_flag#50,customer_birth_country#51,customer_login#52,customer_email_addr [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#47 ASC NULLS FIRST,customer_first_name#48 ASC NULLS FIRST,customer_last_name#49 ASC NULLS FIRST,customer_preferred_cust_flag#50 ASC NULLS FIRST,customer_birth_country#51 ASC NULLS FIRST,customer_login#52 ASC NULLS FIRST,customer_email_address#53 ASC NULLS FIRST], output=[customer_id#47,customer_first_name#48,customer_last_name#49,customer_preferred_cust_flag#50,customer_birth_country#51,customer_login#52,customer_email_addr [...]
 
 (107) CometColumnarToRow [codegen id : 1]
 Input [7]: [customer_id#47, customer_first_name#48, customer_last_name#49, customer_preferred_cust_flag#50, customer_birth_country#51, customer_login#52, customer_email_address#53]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q40/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q40/explain.txt
index 3007e144e..15a833372 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q40/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q40/explain.txt
@@ -182,7 +182,7 @@ Functions [2]: [sum(CASE WHEN (d_date#19 < 2000-03-11) THEN (cs_sales_price#4 -
 
 (32) CometTakeOrderedAndProject
 Input [4]: [w_state#13, i_item_id#17, sales_before#24, sales_after#25]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_state#13 ASC NULLS FIRST,i_item_id#17 ASC NULLS FIRST], output=[w_state#13,i_item_id#17,sales_before#24,sales_after#25]), [w_state#13, i_item_id#17, sales_before#24, sales_after#25], 100, [w_state#13 ASC NULLS FIRST, i_item_id#17 ASC NULLS FIRST], [w_state#13, i_item_id#17, sales_before#24, sales_after#25]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_state#13 ASC NULLS FIRST,i_item_id#17 ASC NULLS FIRST], output=[w_state#13,i_item_id#17,sales_before#24,sales_after#25]), [w_state#13, i_item_id#17, sales_before#24, sales_after#25], 100, 0, [w_state#13 ASC NULLS FIRST, i_item_id#17 ASC NULLS FIRST], [w_state#13, i_item_id#17, sales_before#24, sales_after#25]
 
 (33) CometColumnarToRow [codegen id : 1]
 Input [4]: [w_state#13, i_item_id#17, sales_before#24, sales_after#25]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q41/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q41/explain.txt
index 1c46adf59..5ee3e8968 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q41/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q41/explain.txt
@@ -100,7 +100,7 @@ Functions: []
 
 (18) CometTakeOrderedAndProject
 Input [1]: [i_product_name#12]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_product_name#12 ASC NULLS FIRST], output=[i_product_name#12]), [i_product_name#12], 100, [i_product_name#12 ASC NULLS FIRST], [i_product_name#12]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_product_name#12 ASC NULLS FIRST], output=[i_product_name#12]), [i_product_name#12], 100, 0, [i_product_name#12 ASC NULLS FIRST], [i_product_name#12]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [1]: [i_product_name#12]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q42/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q42/explain.txt
index b00bd88f0..4f1acd777 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q42/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q42/explain.txt
@@ -104,7 +104,7 @@ Functions [1]: [sum(UnscaledValue(ss_ext_sales_price#5))]
 
 (18) CometTakeOrderedAndProject
 Input [4]: [d_year#2, i_category_id#8, i_category#11, sum(ss_ext_sales_price)#13]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[sum(ss_ext_sales_price)#13 DESC NULLS LAST,d_year#2 ASC NULLS FIRST,i_category_id#8 ASC NULLS FIRST,i_category#11 ASC NULLS FIRST], output=[d_year#2,i_category_id#8,i_category#11,sum(ss_ext_sales_price)#13]), [d_year#2, i_category_id#8, i_category#11, sum(ss_ext_sales_price)#13], 100, [sum(ss_ext_sales_price)#13 DESC NULLS LAST, d_year#2 ASC NULLS FIRST, i_category_id#8 ASC NULLS FIRST, i_category#11 ASC NULLS FIRST], [d_year#2, i_cate [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[sum(ss_ext_sales_price)#13 DESC NULLS LAST,d_year#2 ASC NULLS FIRST,i_category_id#8 ASC NULLS FIRST,i_category#11 ASC NULLS FIRST], output=[d_year#2,i_category_id#8,i_category#11,sum(ss_ext_sales_price)#13]), [d_year#2, i_category_id#8, i_category#11, sum(ss_ext_sales_price)#13], 100, 0, [sum(ss_ext_sales_price)#13 DESC NULLS LAST, d_year#2 ASC NULLS FIRST, i_category_id#8 ASC NULLS FIRST, i_category#11 ASC NULLS FIRST], [d_year#2, i_c [...]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [4]: [d_year#2, i_category_id#8, i_category#11, sum(ss_ext_sales_price)#13]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q43/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q43/explain.txt
index b37b49c38..8364c89c7 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q43/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q43/explain.txt
@@ -104,7 +104,7 @@ Functions [7]: [sum(UnscaledValue(CASE WHEN (d_day_name#4 = Sunday   ) THEN ss_s
 
 (18) CometTakeOrderedAndProject
 Input [9]: [s_store_name#10, s_store_id#12, sun_sales#20, mon_sales#21, tue_sales#22, wed_sales#23, thu_sales#24, fri_sales#25, sat_sales#26]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#10 ASC NULLS FIRST,s_store_id#12 ASC NULLS FIRST,sun_sales#20 ASC NULLS FIRST,mon_sales#21 ASC NULLS FIRST,tue_sales#22 ASC NULLS FIRST,wed_sales#23 ASC NULLS FIRST,thu_sales#24 ASC NULLS FIRST,fri_sales#25 ASC NULLS FIRST,sat_sales#26 ASC NULLS FIRST], output=[s_store_name#10,s_store_id#12,sun_sales#20,mon_sales#21,tue_sales#22,wed_sales#23,thu_sales#24,fri_sales#25,sat_sales#26]), [s_store_name#10, s_store_id#12, sun_sal [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#10 ASC NULLS FIRST,s_store_id#12 ASC NULLS FIRST,sun_sales#20 ASC NULLS FIRST,mon_sales#21 ASC NULLS FIRST,tue_sales#22 ASC NULLS FIRST,wed_sales#23 ASC NULLS FIRST,thu_sales#24 ASC NULLS FIRST,fri_sales#25 ASC NULLS FIRST,sat_sales#26 ASC NULLS FIRST], output=[s_store_name#10,s_store_id#12,sun_sales#20,mon_sales#21,tue_sales#22,wed_sales#23,thu_sales#24,fri_sales#25,sat_sales#26]), [s_store_name#10, s_store_id#12, sun_sal [...]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [9]: [s_store_name#10, s_store_id#12, sun_sales#20, mon_sales#21, tue_sales#22, wed_sales#23, thu_sales#24, fri_sales#25, sat_sales#26]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q46/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q46/explain.txt
index 0675d9dc2..448854607 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q46/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q46/explain.txt
@@ -216,7 +216,7 @@ Arguments: [c_last_name#27, c_first_name#26, ca_city#32, bought_city#28, ss_tick
 
 (38) CometTakeOrderedAndProject
 Input [7]: [c_last_name#27, c_first_name#26, ca_city#32, bought_city#28, ss_ticket_number#5, amt#29, profit#30]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#27 ASC NULLS FIRST,c_first_name#26 ASC NULLS FIRST,ca_city#32 ASC NULLS FIRST,bought_city#28 ASC NULLS FIRST,ss_ticket_number#5 ASC NULLS FIRST], output=[c_last_name#27,c_first_name#26,ca_city#32,bought_city#28,ss_ticket_number#5,amt#29,profit#30]), [c_last_name#27, c_first_name#26, ca_city#32, bought_city#28, ss_ticket_number#5, amt#29, profit#30], 100, [c_last_name#27 ASC NULLS FIRST, c_first_name#26 ASC NULLS FIRST, ca_c [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#27 ASC NULLS FIRST,c_first_name#26 ASC NULLS FIRST,ca_city#32 ASC NULLS FIRST,bought_city#28 ASC NULLS FIRST,ss_ticket_number#5 ASC NULLS FIRST], output=[c_last_name#27,c_first_name#26,ca_city#32,bought_city#28,ss_ticket_number#5,amt#29,profit#30]), [c_last_name#27, c_first_name#26, ca_city#32, bought_city#28, ss_ticket_number#5, amt#29, profit#30], 100, 0, [c_last_name#27 ASC NULLS FIRST, c_first_name#26 ASC NULLS FIRST, c [...]
 
 (39) CometColumnarToRow [codegen id : 1]
 Input [7]: [c_last_name#27, c_first_name#26, ca_city#32, bought_city#28, ss_ticket_number#5, amt#29, profit#30]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q49/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q49/explain.txt
index 041046c4a..deca8f9f2 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q49/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q49/explain.txt
@@ -418,7 +418,7 @@ Functions: []
 
 (77) CometTakeOrderedAndProject
 Input [5]: [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#27 ASC NULLS FIRST,return_rank#25 ASC NULLS FIRST,currency_rank#26 ASC NULLS FIRST], output=[channel#27,item#22,return_ratio#23,return_rank#25,currency_rank#26]), [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26], 100, [channel#27 ASC NULLS FIRST, return_rank#25 ASC NULLS FIRST, currency_rank#26 ASC NULLS FIRST], [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#27 ASC NULLS FIRST,return_rank#25 ASC NULLS FIRST,currency_rank#26 ASC NULLS FIRST], output=[channel#27,item#22,return_ratio#23,return_rank#25,currency_rank#26]), [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26], 100, 0, [channel#27 ASC NULLS FIRST, return_rank#25 ASC NULLS FIRST, currency_rank#26 ASC NULLS FIRST], [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
 
 (78) CometColumnarToRow [codegen id : 11]
 Input [5]: [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q50/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q50/explain.txt
index 00741ade9..3f23166e3 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q50/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q50/explain.txt
@@ -163,7 +163,7 @@ Functions [5]: [sum(CASE WHEN ((sr_returned_date_sk#9 - ss_sold_date_sk#5) <= 30
 
 (28) CometTakeOrderedAndProject
 Input [15]: [s_store_name#12, s_company_id#13, s_street_number#14, s_street_name#15, s_street_type#22, s_suite_number#23, s_city#18, s_county#19, s_state#24, s_zip#25, 30 days #35, 31 - 60 days #36, 61 - 90 days #37, 91 - 120 days #38, >120 days #39]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#12 ASC NULLS FIRST,s_company_id#13 ASC NULLS FIRST,s_street_number#14 ASC NULLS FIRST,s_street_name#15 ASC NULLS FIRST,s_street_type#22 ASC NULLS FIRST,s_suite_number#23 ASC NULLS FIRST,s_city#18 ASC NULLS FIRST,s_county#19 ASC NULLS FIRST,s_state#24 ASC NULLS FIRST,s_zip#25 ASC NULLS FIRST], output=[s_store_name#12,s_company_id#13,s_street_number#14,s_street_name#15,s_street_type#22,s_suite_number#23,s_city#18,s_county#19 [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#12 ASC NULLS FIRST,s_company_id#13 ASC NULLS FIRST,s_street_number#14 ASC NULLS FIRST,s_street_name#15 ASC NULLS FIRST,s_street_type#22 ASC NULLS FIRST,s_suite_number#23 ASC NULLS FIRST,s_city#18 ASC NULLS FIRST,s_county#19 ASC NULLS FIRST,s_state#24 ASC NULLS FIRST,s_zip#25 ASC NULLS FIRST], output=[s_store_name#12,s_company_id#13,s_street_number#14,s_street_name#15,s_street_type#22,s_suite_number#23,s_city#18,s_county#19 [...]
 
 (29) CometColumnarToRow [codegen id : 1]
 Input [15]: [s_store_name#12, s_company_id#13, s_street_number#14, s_street_name#15, s_street_type#22, s_suite_number#23, s_city#18, s_county#19, s_state#24, s_zip#25, 30 days #35, 31 - 60 days #36, 61 - 90 days #37, 91 - 120 days #38, >120 days #39]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q52/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q52/explain.txt
index 7f8528d85..e38f69fcb 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q52/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q52/explain.txt
@@ -104,7 +104,7 @@ Functions [1]: [sum(UnscaledValue(ss_ext_sales_price#5))]
 
 (18) CometTakeOrderedAndProject
 Input [4]: [d_year#2, brand_id#13, brand#14, ext_price#15]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[d_year#2 ASC NULLS FIRST,ext_price#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[d_year#2,brand_id#13,brand#14,ext_price#15]), [d_year#2, brand_id#13, brand#14, ext_price#15], 100, [d_year#2 ASC NULLS FIRST, ext_price#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [d_year#2, brand_id#13, brand#14, ext_price#15]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[d_year#2 ASC NULLS FIRST,ext_price#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[d_year#2,brand_id#13,brand#14,ext_price#15]), [d_year#2, brand_id#13, brand#14, ext_price#15], 100, 0, [d_year#2 ASC NULLS FIRST, ext_price#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [d_year#2, brand_id#13, brand#14, ext_price#15]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [4]: [d_year#2, brand_id#13, brand#14, ext_price#15]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q54/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q54/explain.txt
index 32eed7671..766b38a48 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q54/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q54/explain.txt
@@ -328,7 +328,7 @@ Functions [1]: [count(1)]
 
 (57) CometTakeOrderedAndProject
 Input [3]: [segment#40, num_customers#42, segment_base#43]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[segment#40 ASC NULLS FIRST,num_customers#42 ASC NULLS FIRST], output=[segment#40,num_customers#42,segment_base#43]), [segment#40, num_customers#42, segment_base#43], 100, [segment#40 ASC NULLS FIRST, num_customers#42 ASC NULLS FIRST], [segment#40, num_customers#42, segment_base#43]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[segment#40 ASC NULLS FIRST,num_customers#42 ASC NULLS FIRST], output=[segment#40,num_customers#42,segment_base#43]), [segment#40, num_customers#42, segment_base#43], 100, 0, [segment#40 ASC NULLS FIRST, num_customers#42 ASC NULLS FIRST], [segment#40, num_customers#42, segment_base#43]
 
 (58) CometColumnarToRow [codegen id : 1]
 Input [3]: [segment#40, num_customers#42, segment_base#43]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q55/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q55/explain.txt
index 543566c87..2b06aab6d 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q55/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q55/explain.txt
@@ -104,7 +104,7 @@ Functions [1]: [sum(UnscaledValue(ss_ext_sales_price#5))]
 
 (18) CometTakeOrderedAndProject
 Input [3]: [brand_id#13, brand#14, ext_price#15]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ext_price#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[brand_id#13,brand#14,ext_price#15]), [brand_id#13, brand#14, ext_price#15], 100, [ext_price#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [brand_id#13, brand#14, ext_price#15]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ext_price#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[brand_id#13,brand#14,ext_price#15]), [brand_id#13, brand#14, ext_price#15], 100, 0, [ext_price#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [brand_id#13, brand#14, ext_price#15]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [3]: [brand_id#13, brand#14, ext_price#15]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q56/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q56/explain.txt
index c78ae4305..8582e706d 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q56/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q56/explain.txt
@@ -341,7 +341,7 @@ Functions [1]: [sum(total_sales#39)]
 
 (61) CometTakeOrderedAndProject
 Input [2]: [i_item_id#38, total_sales#44]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_sales#44 ASC NULLS FIRST], output=[i_item_id#38,total_sales#44]), [i_item_id#38, total_sales#44], 100, [total_sales#44 ASC NULLS FIRST], [i_item_id#38, total_sales#44]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_sales#44 ASC NULLS FIRST], output=[i_item_id#38,total_sales#44]), [i_item_id#38, total_sales#44], 100, 0, [total_sales#44 ASC NULLS FIRST], [i_item_id#38, total_sales#44]
 
 (62) CometColumnarToRow [codegen id : 1]
 Input [2]: [i_item_id#38, total_sales#44]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q58/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q58/explain.txt
index b93ac3c45..10eb2ef5b 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q58/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q58/explain.txt
@@ -283,7 +283,7 @@ Arguments: [item_id#12, ss_item_rev#13, ss_dev#34, cs_item_rev#23, cs_dev#35, ws
 
 (51) CometTakeOrderedAndProject
 Input [8]: [item_id#12, ss_item_rev#13, ss_dev#34, cs_item_rev#23, cs_dev#35, ws_item_rev#33, ws_dev#36, average#37]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[item_id#12 ASC NULLS FIRST,ss_item_rev#13 ASC NULLS FIRST], output=[item_id#12,ss_item_rev#13,ss_dev#34,cs_item_rev#23,cs_dev#35,ws_item_rev#33,ws_dev#36,average#37]), [item_id#12, ss_item_rev#13, ss_dev#34, cs_item_rev#23, cs_dev#35, ws_item_rev#33, ws_dev#36, average#37], 100, [item_id#12 ASC NULLS FIRST, ss_item_rev#13 ASC NULLS FIRST], [item_id#12, ss_item_rev#13, ss_dev#34, cs_item_rev#23, cs_dev#35, ws_item_rev#33, ws_dev#36, ave [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[item_id#12 ASC NULLS FIRST,ss_item_rev#13 ASC NULLS FIRST], output=[item_id#12,ss_item_rev#13,ss_dev#34,cs_item_rev#23,cs_dev#35,ws_item_rev#33,ws_dev#36,average#37]), [item_id#12, ss_item_rev#13, ss_dev#34, cs_item_rev#23, cs_dev#35, ws_item_rev#33, ws_dev#36, average#37], 100, 0, [item_id#12 ASC NULLS FIRST, ss_item_rev#13 ASC NULLS FIRST], [item_id#12, ss_item_rev#13, ss_dev#34, cs_item_rev#23, cs_dev#35, ws_item_rev#33, ws_dev#36,  [...]
 
 (52) CometColumnarToRow [codegen id : 1]
 Input [8]: [item_id#12, ss_item_rev#13, ss_dev#34, cs_item_rev#23, cs_dev#35, ws_item_rev#33, ws_dev#36, average#37]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q59/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q59/explain.txt
index d972f5cc4..32edb2f9b 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q59/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q59/explain.txt
@@ -232,7 +232,7 @@ Arguments: [s_store_name1#28, s_store_id1#30, d_week_seq1#29, (sun_sales1 / sun_
 
 (41) CometTakeOrderedAndProject
 Input [10]: [s_store_name1#28, s_store_id1#30, d_week_seq1#29, (sun_sales1 / sun_sales2)#69, (mon_sales1 / mon_sales2)#70, (tue_sales1 / tue_sales2)#71, (wed_sales1 / wed_sales2)#72, (thu_sales1 / thu_sales2)#73, (fri_sales1 / fri_sales2)#74, (sat_sales1 / sat_sales2)#75]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name1#28 ASC NULLS FIRST,s_store_id1#30 ASC NULLS FIRST,d_week_seq1#29 ASC NULLS FIRST], output=[s_store_name1#28,s_store_id1#30,d_week_seq1#29,(sun_sales1 / sun_sales2)#69,(mon_sales1 / mon_sales2)#70,(tue_sales1 / tue_sales2)#71,(wed_sales1 / wed_sales2)#72,(thu_sales1 / thu_sales2)#73,(fri_sales1 / fri_sales2)#74,(sat_sales1 / sat_sales2)#75]), [s_store_name1#28, s_store_id1#30, d_week_seq1#29, (sun_sales1 / sun_sales2)#69,  [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name1#28 ASC NULLS FIRST,s_store_id1#30 ASC NULLS FIRST,d_week_seq1#29 ASC NULLS FIRST], output=[s_store_name1#28,s_store_id1#30,d_week_seq1#29,(sun_sales1 / sun_sales2)#69,(mon_sales1 / mon_sales2)#70,(tue_sales1 / tue_sales2)#71,(wed_sales1 / wed_sales2)#72,(thu_sales1 / thu_sales2)#73,(fri_sales1 / fri_sales2)#74,(sat_sales1 / sat_sales2)#75]), [s_store_name1#28, s_store_id1#30, d_week_seq1#29, (sun_sales1 / sun_sales2)#69,  [...]
 
 (42) CometColumnarToRow [codegen id : 1]
 Input [10]: [s_store_name1#28, s_store_id1#30, d_week_seq1#29, (sun_sales1 / sun_sales2)#69, (mon_sales1 / mon_sales2)#70, (tue_sales1 / tue_sales2)#71, (wed_sales1 / wed_sales2)#72, (thu_sales1 / thu_sales2)#73, (fri_sales1 / fri_sales2)#74, (sat_sales1 / sat_sales2)#75]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q6/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q6/explain.txt
index 3ff5d0b90..696ff9eb1 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q6/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q6/explain.txt
@@ -222,7 +222,7 @@ Condition : (cnt#25 >= 10)
 
 (39) CometTakeOrderedAndProject
 Input [2]: [state#24, cnt#25]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[cnt#25 ASC NULLS FIRST], output=[state#24,cnt#25]), [state#24, cnt#25], 100, [cnt#25 ASC NULLS FIRST], [state#24, cnt#25]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[cnt#25 ASC NULLS FIRST], output=[state#24,cnt#25]), [state#24, cnt#25], 100, 0, [cnt#25 ASC NULLS FIRST], [state#24, cnt#25]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [2]: [state#24, cnt#25]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q60/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q60/explain.txt
index aa8dce50c..d74ac5224 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q60/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q60/explain.txt
@@ -341,7 +341,7 @@ Functions [1]: [sum(total_sales#39)]
 
 (61) CometTakeOrderedAndProject
 Input [2]: [i_item_id#38, total_sales#44]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#38 ASC NULLS FIRST,total_sales#44 ASC NULLS FIRST], output=[i_item_id#38,total_sales#44]), [i_item_id#38, total_sales#44], 100, [i_item_id#38 ASC NULLS FIRST, total_sales#44 ASC NULLS FIRST], [i_item_id#38, total_sales#44]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#38 ASC NULLS FIRST,total_sales#44 ASC NULLS FIRST], output=[i_item_id#38,total_sales#44]), [i_item_id#38, total_sales#44], 100, 0, [i_item_id#38 ASC NULLS FIRST, total_sales#44 ASC NULLS FIRST], [i_item_id#38, total_sales#44]
 
 (62) CometColumnarToRow [codegen id : 1]
 Input [2]: [i_item_id#38, total_sales#44]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q62/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q62/explain.txt
index c317d6b24..102de64aa 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q62/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q62/explain.txt
@@ -161,7 +161,7 @@ Functions [5]: [sum(CASE WHEN ((ws_ship_date_sk#1 - ws_sold_date_sk#5) <= 30) TH
 
 (28) CometTakeOrderedAndProject
 Input [8]: [substr(w_warehouse_name, 1, 20)#21, sm_type#10, web_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(w_warehouse_name, 1, 20)#21 ASC NULLS FIRST,sm_type#10 ASC NULLS FIRST,web_name#12 ASC NULLS FIRST], output=[substr(w_warehouse_name, 1, 20)#21,sm_type#10,web_name#12,30 days #22,31 - 60 days #23,61 - 90 days #24,91 - 120 days #25,>120 days #26]), [substr(w_warehouse_name, 1, 20)#21, sm_type#10, web_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26], 100, [substr(w_warehouse_name, 1, 20)# [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(w_warehouse_name, 1, 20)#21 ASC NULLS FIRST,sm_type#10 ASC NULLS FIRST,web_name#12 ASC NULLS FIRST], output=[substr(w_warehouse_name, 1, 20)#21,sm_type#10,web_name#12,30 days #22,31 - 60 days #23,61 - 90 days #24,91 - 120 days #25,>120 days #26]), [substr(w_warehouse_name, 1, 20)#21, sm_type#10, web_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26], 100, 0, [substr(w_warehouse_name, 1, 2 [...]
 
 (29) CometColumnarToRow [codegen id : 1]
 Input [8]: [substr(w_warehouse_name, 1, 20)#21, sm_type#10, web_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q65/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q65/explain.txt
index f12e2604d..4cad0df46 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q65/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q65/explain.txt
@@ -222,7 +222,7 @@ Arguments: [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wh
 
 (39) CometTakeOrderedAndProject
 Input [6]: [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#2 ASC NULLS FIRST,i_item_desc#13 ASC NULLS FIRST], output=[s_store_name#2,i_item_desc#13,revenue#11,i_current_price#14,i_wholesale_cost#15,i_brand#17]), [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17], 100, [s_store_name#2 ASC NULLS FIRST, i_item_desc#13 ASC NULLS FIRST], [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#2 ASC NULLS FIRST,i_item_desc#13 ASC NULLS FIRST], output=[s_store_name#2,i_item_desc#13,revenue#11,i_current_price#14,i_wholesale_cost#15,i_brand#17]), [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17], 100, 0, [s_store_name#2 ASC NULLS FIRST, i_item_desc#13 ASC NULLS FIRST], [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [6]: [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q66/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q66/explain.txt
index 1ed8aa1c8..036484391 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q66/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q66/explain.txt
@@ -280,7 +280,7 @@ Functions [36]: [sum(jan_sales#142), sum(feb_sales#143), sum(mar_sales#144), sum
 
 (50) CometTakeOrderedAndProject
 Input [44]: [w_warehouse_name#10, w_warehouse_sq_ft#11, w_city#12, w_county#13, w_state#16, w_country#15, ship_carriers#140, year#141, jan_sales#264, feb_sales#265, mar_sales#266, apr_sales#267, may_sales#268, jun_sales#269, jul_sales#270, aug_sales#271, sep_sales#272, oct_sales#273, nov_sales#274, dec_sales#275, jan_sales_per_sq_foot#276, feb_sales_per_sq_foot#277, mar_sales_per_sq_foot#278, apr_sales_per_sq_foot#279, may_sales_per_sq_foot#280, jun_sales_per_sq_foot#281, jul_sales_per_s [...]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_warehouse_name#10 ASC NULLS FIRST], output=[w_warehouse_name#10,w_warehouse_sq_ft#11,w_city#12,w_county#13,w_state#16,w_country#15,ship_carriers#140,year#141,jan_sales#264,feb_sales#265,mar_sales#266,apr_sales#267,may_sales#268,jun_sales#269,jul_sales#270,aug_sales#271,sep_sales#272,oct_sales#273,nov_sales#274,dec_sales#275,jan_sales_per_sq_foot#276,feb_sales_per_sq_foot#277,mar_sales_per_sq_foot#278,apr_sales_per_sq_foot#279,may_sal [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_warehouse_name#10 ASC NULLS FIRST], output=[w_warehouse_name#10,w_warehouse_sq_ft#11,w_city#12,w_county#13,w_state#16,w_country#15,ship_carriers#140,year#141,jan_sales#264,feb_sales#265,mar_sales#266,apr_sales#267,may_sales#268,jun_sales#269,jul_sales#270,aug_sales#271,sep_sales#272,oct_sales#273,nov_sales#274,dec_sales#275,jan_sales_per_sq_foot#276,feb_sales_per_sq_foot#277,mar_sales_per_sq_foot#278,apr_sales_per_sq_foot#279,may_sal [...]
 
 (51) CometColumnarToRow [codegen id : 1]
 Input [44]: [w_warehouse_name#10, w_warehouse_sq_ft#11, w_city#12, w_county#13, w_state#16, w_country#15, ship_carriers#140, year#141, jan_sales#264, feb_sales#265, mar_sales#266, apr_sales#267, may_sales#268, jun_sales#269, jul_sales#270, aug_sales#271, sep_sales#272, oct_sales#273, nov_sales#274, dec_sales#275, jan_sales_per_sq_foot#276, feb_sales_per_sq_foot#277, mar_sales_per_sq_foot#278, apr_sales_per_sq_foot#279, may_sales_per_sq_foot#280, jun_sales_per_sq_foot#281, jul_sales_per_s [...]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q68/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q68/explain.txt
index 63198dc37..b1044659e 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q68/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q68/explain.txt
@@ -216,7 +216,7 @@ Arguments: [c_last_name#29, c_first_name#28, ca_city#35, bought_city#30, ss_tick
 
 (38) CometTakeOrderedAndProject
 Input [8]: [c_last_name#29, c_first_name#28, ca_city#35, bought_city#30, ss_ticket_number#5, extended_price#31, extended_tax#33, list_price#32]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#29 ASC NULLS FIRST,ss_ticket_number#5 ASC NULLS FIRST], output=[c_last_name#29,c_first_name#28,ca_city#35,bought_city#30,ss_ticket_number#5,extended_price#31,extended_tax#33,list_price#32]), [c_last_name#29, c_first_name#28, ca_city#35, bought_city#30, ss_ticket_number#5, extended_price#31, extended_tax#33, list_price#32], 100, [c_last_name#29 ASC NULLS FIRST, ss_ticket_number#5 ASC NULLS FIRST], [c_last_name#29, c_first_na [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#29 ASC NULLS FIRST,ss_ticket_number#5 ASC NULLS FIRST], output=[c_last_name#29,c_first_name#28,ca_city#35,bought_city#30,ss_ticket_number#5,extended_price#31,extended_tax#33,list_price#32]), [c_last_name#29, c_first_name#28, ca_city#35, bought_city#30, ss_ticket_number#5, extended_price#31, extended_tax#33, list_price#32], 100, 0, [c_last_name#29 ASC NULLS FIRST, ss_ticket_number#5 ASC NULLS FIRST], [c_last_name#29, c_first [...]
 
 (39) CometColumnarToRow [codegen id : 1]
 Input [8]: [c_last_name#29, c_first_name#28, ca_city#35, bought_city#30, ss_ticket_number#5, extended_price#31, extended_tax#33, list_price#32]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q7/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q7/explain.txt
index edab63c11..e82907b63 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q7/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q7/explain.txt
@@ -172,7 +172,7 @@ Functions [4]: [avg(ss_quantity#4), avg(UnscaledValue(ss_list_price#5)), avg(Uns
 
 (30) CometTakeOrderedAndProject
 Input [5]: [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#18 ASC NULLS FIRST], output=[i_item_id#18,agg1#30,agg2#31,agg3#32,agg4#33]), [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33], 100, [i_item_id#18 ASC NULLS FIRST], [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#18 ASC NULLS FIRST], output=[i_item_id#18,agg1#30,agg2#31,agg3#32,agg4#33]), [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33], 100, 0, [i_item_id#18 ASC NULLS FIRST], [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
 
 (31) CometColumnarToRow [codegen id : 1]
 Input [5]: [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q72/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q72/explain.txt
index 1aa31ec60..d7f9c7921 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q72/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q72/explain.txt
@@ -362,7 +362,7 @@ Functions [1]: [count(1)]
 
 (63) CometTakeOrderedAndProject
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC NUL [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, 0, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC  [...]
 
 (64) CometColumnarToRow [codegen id : 1]
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q74/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q74/explain.txt
index 15826f3da..f48543205 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q74/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q74/explain.txt
@@ -406,7 +406,7 @@ Arguments: [customer_id#28, customer_first_name#29, customer_last_name#30], [cus
 
 (71) CometTakeOrderedAndProject
 Input [3]: [customer_id#28, customer_first_name#29, customer_last_name#30]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#28 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST], output=[customer_id#28,customer_first_name#29,customer_last_name#30]), [customer_id#28, customer_first_name#29, customer_last_name#30], 100, [customer_id#28 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST], [customer_id#28, customer_first_name#29, customer_last_name#30]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#28 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST], output=[customer_id#28,customer_first_name#29,customer_last_name#30]), [customer_id#28, customer_first_name#29, customer_last_name#30], 100, 0, [customer_id#28 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST], [customer_id#28, customer_first_name#29, customer_last_name#30]
 
 (72) CometColumnarToRow [codegen id : 1]
 Input [3]: [customer_id#28, customer_first_name#29, customer_last_name#30]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q75/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q75/explain.txt
index cecd130fd..cfdda944d 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q75/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q75/explain.txt
@@ -674,7 +674,7 @@ Arguments: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#1
 
 (123) CometTakeOrderedAndProject
 Input [10]: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#124 ASC NULLS FIRST], output=[prev_year#120,year#121,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#122,curr_yr_cnt#123,sales_cnt_diff#124,sales_amt_diff#125]), [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125], 100, [sales_cnt_diff#124 ASC NULLS FIRST], [prev_year#120, year#121, i_br [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#124 ASC NULLS FIRST], output=[prev_year#120,year#121,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#122,curr_yr_cnt#123,sales_cnt_diff#124,sales_amt_diff#125]), [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125], 100, 0, [sales_cnt_diff#124 ASC NULLS FIRST], [prev_year#120, year#121, i [...]
 
 (124) CometColumnarToRow [codegen id : 1]
 Input [10]: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q76/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q76/explain.txt
index 64b75ea0d..3083e79d2 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q76/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q76/explain.txt
@@ -193,7 +193,7 @@ Functions [2]: [count(1), sum(UnscaledValue(ext_sales_price#13))]
 
 (34) CometTakeOrderedAndProject
 Input [7]: [channel#11, col_name#12, d_year#9, d_qoy#10, i_category#7, sales_cnt#40, sales_amt#41]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#11 ASC NULLS FIRST,col_name#12 ASC NULLS FIRST,d_year#9 ASC NULLS FIRST,d_qoy#10 ASC NULLS FIRST,i_category#7 ASC NULLS FIRST], output=[channel#11,col_name#12,d_year#9,d_qoy#10,i_category#7,sales_cnt#40,sales_amt#41]), [channel#11, col_name#12, d_year#9, d_qoy#10, i_category#7, sales_cnt#40, sales_amt#41], 100, [channel#11 ASC NULLS FIRST, col_name#12 ASC NULLS FIRST, d_year#9 ASC NULLS FIRST, d_qoy#10 ASC NULLS FIRST, i_catego [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#11 ASC NULLS FIRST,col_name#12 ASC NULLS FIRST,d_year#9 ASC NULLS FIRST,d_qoy#10 ASC NULLS FIRST,i_category#7 ASC NULLS FIRST], output=[channel#11,col_name#12,d_year#9,d_qoy#10,i_category#7,sales_cnt#40,sales_amt#41]), [channel#11, col_name#12, d_year#9, d_qoy#10, i_category#7, sales_cnt#40, sales_amt#41], 100, 0, [channel#11 ASC NULLS FIRST, col_name#12 ASC NULLS FIRST, d_year#9 ASC NULLS FIRST, d_qoy#10 ASC NULLS FIRST, i_cat [...]
 
 (35) CometColumnarToRow [codegen id : 1]
 Input [7]: [channel#11, col_name#12, d_year#9, d_qoy#10, i_category#7, sales_cnt#40, sales_amt#41]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q79/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q79/explain.txt
index 1f026356f..e7b144406 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q79/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q79/explain.txt
@@ -172,7 +172,7 @@ Arguments: [c_last_name#25, c_first_name#24, substr(s_city, 1, 30)#28, ss_ticket
 
 (30) CometTakeOrderedAndProject
 Input [7]: [c_last_name#25, c_first_name#24, substr(s_city, 1, 30)#28, ss_ticket_number#5, amt#26, profit#27, s_city#15]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#25 ASC NULLS FIRST,c_first_name#24 ASC NULLS FIRST,substr(s_city#15, 1, 30) ASC NULLS FIRST,profit#27 ASC NULLS FIRST], output=[c_last_name#25,c_first_name#24,substr(s_city, 1, 30)#28,ss_ticket_number#5,amt#26,profit#27]), [c_last_name#25, c_first_name#24, substr(s_city, 1, 30)#28, ss_ticket_number#5, amt#26, profit#27], 100, [c_last_name#25 ASC NULLS FIRST, c_first_name#24 ASC NULLS FIRST, substr(s_city#15, 1, 30) ASC NULL [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#25 ASC NULLS FIRST,c_first_name#24 ASC NULLS FIRST,substr(s_city#15, 1, 30) ASC NULLS FIRST,profit#27 ASC NULLS FIRST], output=[c_last_name#25,c_first_name#24,substr(s_city, 1, 30)#28,ss_ticket_number#5,amt#26,profit#27]), [c_last_name#25, c_first_name#24, substr(s_city, 1, 30)#28, ss_ticket_number#5, amt#26, profit#27], 100, 0, [c_last_name#25 ASC NULLS FIRST, c_first_name#24 ASC NULLS FIRST, substr(s_city#15, 1, 30) ASC N [...]
 
 (31) CometColumnarToRow [codegen id : 1]
 Input [6]: [c_last_name#25, c_first_name#24, substr(s_city, 1, 30)#28, ss_ticket_number#5, amt#26, profit#27]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q8/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q8/explain.txt
index cc47e512f..eee3c4c57 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q8/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q8/explain.txt
@@ -244,7 +244,7 @@ Functions [1]: [sum(UnscaledValue(ss_net_profit#2))]
 
 (43) CometTakeOrderedAndProject
 Input [2]: [s_store_name#9, sum(ss_net_profit)#23]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#9 ASC NULLS FIRST], output=[s_store_name#9,sum(ss_net_profit)#23]), [s_store_name#9, sum(ss_net_profit)#23], 100, [s_store_name#9 ASC NULLS FIRST], [s_store_name#9, sum(ss_net_profit)#23]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#9 ASC NULLS FIRST], output=[s_store_name#9,sum(ss_net_profit)#23]), [s_store_name#9, sum(ss_net_profit)#23], 100, 0, [s_store_name#9 ASC NULLS FIRST], [s_store_name#9, sum(ss_net_profit)#23]
 
 (44) CometColumnarToRow [codegen id : 1]
 Input [2]: [s_store_name#9, sum(ss_net_profit)#23]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q81/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q81/explain.txt
index 7dbb8133d..83841fb78 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q81/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q81/explain.txt
@@ -276,7 +276,7 @@ Arguments: [c_customer_id#34, c_salutation#35, c_first_name#36, c_last_name#37,
 
 (49) CometTakeOrderedAndProject
 Input [16]: [c_customer_id#34, c_salutation#35, c_first_name#36, c_last_name#37, ca_street_number#50, ca_street_name#40, ca_street_type#51, ca_suite_number#52, ca_city#43, ca_county#44, ca_state#53, ca_zip#54, ca_country#47, ca_gmt_offset#48, ca_location_type#55, ctr_total_return#14]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#34 ASC NULLS FIRST,c_salutation#35 ASC NULLS FIRST,c_first_name#36 ASC NULLS FIRST,c_last_name#37 ASC NULLS FIRST,ca_street_number#50 ASC NULLS FIRST,ca_street_name#40 ASC NULLS FIRST,ca_street_type#51 ASC NULLS FIRST,ca_suite_number#52 ASC NULLS FIRST,ca_city#43 ASC NULLS FIRST,ca_county#44 ASC NULLS FIRST,ca_state#53 ASC NULLS FIRST,ca_zip#54 ASC NULLS FIRST,ca_country#47 ASC NULLS FIRST,ca_gmt_offset#48 ASC NULLS FIRST [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#34 ASC NULLS FIRST,c_salutation#35 ASC NULLS FIRST,c_first_name#36 ASC NULLS FIRST,c_last_name#37 ASC NULLS FIRST,ca_street_number#50 ASC NULLS FIRST,ca_street_name#40 ASC NULLS FIRST,ca_street_type#51 ASC NULLS FIRST,ca_suite_number#52 ASC NULLS FIRST,ca_city#43 ASC NULLS FIRST,ca_county#44 ASC NULLS FIRST,ca_state#53 ASC NULLS FIRST,ca_zip#54 ASC NULLS FIRST,ca_country#47 ASC NULLS FIRST,ca_gmt_offset#48 ASC NULLS FIRST [...]
 
 (50) CometColumnarToRow [codegen id : 1]
 Input [16]: [c_customer_id#34, c_salutation#35, c_first_name#36, c_last_name#37, ca_street_number#50, ca_street_name#40, ca_street_type#51, ca_suite_number#52, ca_city#43, ca_county#44, ca_state#53, ca_zip#54, ca_country#47, ca_gmt_offset#48, ca_location_type#55, ctr_total_return#14]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q82/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q82/explain.txt
index 6b35c3253..7e7acf323 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q82/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q82/explain.txt
@@ -143,7 +143,7 @@ Functions: []
 
 (25) CometTakeOrderedAndProject
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, 0, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
 
 (26) CometColumnarToRow [codegen id : 1]
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q83/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q83/explain.txt
index de99c0edc..79262dba0 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q83/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q83/explain.txt
@@ -268,7 +268,7 @@ Arguments: [item_id#22, sr_item_qty#23, sr_dev#34, cr_item_qty#21, cr_dev#35, wr
 
 (48) CometTakeOrderedAndProject
 Input [8]: [item_id#22, sr_item_qty#23, sr_dev#34, cr_item_qty#21, cr_dev#35, wr_item_qty#33, wr_dev#36, average#37]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[item_id#22 ASC NULLS FIRST,sr_item_qty#23 ASC NULLS FIRST], output=[item_id#22,sr_item_qty#23,sr_dev#34,cr_item_qty#21,cr_dev#35,wr_item_qty#33,wr_dev#36,average#37]), [item_id#22, sr_item_qty#23, sr_dev#34, cr_item_qty#21, cr_dev#35, wr_item_qty#33, wr_dev#36, average#37], 100, [item_id#22 ASC NULLS FIRST, sr_item_qty#23 ASC NULLS FIRST], [item_id#22, sr_item_qty#23, sr_dev#34, cr_item_qty#21, cr_dev#35, wr_item_qty#33, wr_dev#36, ave [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[item_id#22 ASC NULLS FIRST,sr_item_qty#23 ASC NULLS FIRST], output=[item_id#22,sr_item_qty#23,sr_dev#34,cr_item_qty#21,cr_dev#35,wr_item_qty#33,wr_dev#36,average#37]), [item_id#22, sr_item_qty#23, sr_dev#34, cr_item_qty#21, cr_dev#35, wr_item_qty#33, wr_dev#36, average#37], 100, 0, [item_id#22 ASC NULLS FIRST, sr_item_qty#23 ASC NULLS FIRST], [item_id#22, sr_item_qty#23, sr_dev#34, cr_item_qty#21, cr_dev#35, wr_item_qty#33, wr_dev#36,  [...]
 
 (49) CometColumnarToRow [codegen id : 1]
 Input [8]: [item_id#22, sr_item_qty#23, sr_dev#34, cr_item_qty#21, cr_dev#35, wr_item_qty#33, wr_dev#36, average#37]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q85/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q85/explain.txt
index a6ec6332a..5a3f67946 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q85/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q85/explain.txt
@@ -269,7 +269,7 @@ Functions [3]: [avg(ws_quantity#4), avg(UnscaledValue(wr_refunded_cash#16)), avg
 
 (47) CometTakeOrderedAndProject
 Input [4]: [substr(r_reason_desc, 1, 20)#44, avg(ws_quantity)#45, avg(wr_refunded_cash)#46, avg(wr_fee)#47]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(r_reason_desc, 1, 20)#44 ASC NULLS FIRST,avg(ws_quantity)#45 ASC NULLS FIRST,avg(wr_refunded_cash)#46 ASC NULLS FIRST,avg(wr_fee)#47 ASC NULLS FIRST], output=[substr(r_reason_desc, 1, 20)#44,avg(ws_quantity)#45,avg(wr_refunded_cash)#46,avg(wr_fee)#47]), [substr(r_reason_desc, 1, 20)#44, avg(ws_quantity)#45, avg(wr_refunded_cash)#46, avg(wr_fee)#47], 100, [substr(r_reason_desc, 1, 20)#44 ASC NULLS FIRST, avg(ws_quantity)#45 ASC N [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(r_reason_desc, 1, 20)#44 ASC NULLS FIRST,avg(ws_quantity)#45 ASC NULLS FIRST,avg(wr_refunded_cash)#46 ASC NULLS FIRST,avg(wr_fee)#47 ASC NULLS FIRST], output=[substr(r_reason_desc, 1, 20)#44,avg(ws_quantity)#45,avg(wr_refunded_cash)#46,avg(wr_fee)#47]), [substr(r_reason_desc, 1, 20)#44, avg(ws_quantity)#45, avg(wr_refunded_cash)#46, avg(wr_fee)#47], 100, 0, [substr(r_reason_desc, 1, 20)#44 ASC NULLS FIRST, avg(ws_quantity)#45 AS [...]
 
 (48) CometColumnarToRow [codegen id : 1]
 Input [4]: [substr(r_reason_desc, 1, 20)#44, avg(ws_quantity)#45, avg(wr_refunded_cash)#46, avg(wr_fee)#47]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q93/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q93/explain.txt
index 7498a020a..4577461e1 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q93/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q93/explain.txt
@@ -117,7 +117,7 @@ Functions [1]: [sum(act_sales#14)]
 
 (21) CometTakeOrderedAndProject
 Input [2]: [ss_customer_sk#2, sumsales#17]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[sumsales#17 ASC NULLS FIRST,ss_customer_sk#2 ASC NULLS FIRST], output=[ss_customer_sk#2,sumsales#17]), [ss_customer_sk#2, sumsales#17], 100, [sumsales#17 ASC NULLS FIRST, ss_customer_sk#2 ASC NULLS FIRST], [ss_customer_sk#2, sumsales#17]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[sumsales#17 ASC NULLS FIRST,ss_customer_sk#2 ASC NULLS FIRST], output=[ss_customer_sk#2,sumsales#17]), [ss_customer_sk#2, sumsales#17], 100, 0, [sumsales#17 ASC NULLS FIRST, ss_customer_sk#2 ASC NULLS FIRST], [ss_customer_sk#2, sumsales#17]
 
 (22) CometColumnarToRow [codegen id : 1]
 Input [2]: [ss_customer_sk#2, sumsales#17]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q99/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q99/explain.txt
index e96362854..42b007b23 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q99/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark3_5/q99/explain.txt
@@ -161,7 +161,7 @@ Functions [5]: [sum(CASE WHEN ((cs_ship_date_sk#1 - cs_sold_date_sk#5) <= 30) TH
 
 (28) CometTakeOrderedAndProject
 Input [8]: [substr(w_warehouse_name, 1, 20)#21, sm_type#10, cc_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(w_warehouse_name, 1, 20)#21 ASC NULLS FIRST,sm_type#10 ASC NULLS FIRST,cc_name#12 ASC NULLS FIRST], output=[substr(w_warehouse_name, 1, 20)#21,sm_type#10,cc_name#12,30 days #22,31 - 60 days #23,61 - 90 days #24,91 - 120 days #25,>120 days #26]), [substr(w_warehouse_name, 1, 20)#21, sm_type#10, cc_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26], 100, [substr(w_warehouse_name, 1, 20)#21  [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(w_warehouse_name, 1, 20)#21 ASC NULLS FIRST,sm_type#10 ASC NULLS FIRST,cc_name#12 ASC NULLS FIRST], output=[substr(w_warehouse_name, 1, 20)#21,sm_type#10,cc_name#12,30 days #22,31 - 60 days #23,61 - 90 days #24,91 - 120 days #25,>120 days #26]), [substr(w_warehouse_name, 1, 20)#21, sm_type#10, cc_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26], 100, 0, [substr(w_warehouse_name, 1, 20)# [...]
 
 (29) CometColumnarToRow [codegen id : 1]
 Input [8]: [substr(w_warehouse_name, 1, 20)#21, sm_type#10, cc_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q37/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q37/explain.txt
index 3b5a2111e..131b1c0a6 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q37/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q37/explain.txt
@@ -143,7 +143,7 @@ Functions: []
 
 (25) CometTakeOrderedAndProject
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, 0, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
 
 (26) CometColumnarToRow [codegen id : 1]
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q41/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q41/explain.txt
index 022c10e9b..147f3ad47 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q41/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q41/explain.txt
@@ -100,7 +100,7 @@ Functions: []
 
 (18) CometTakeOrderedAndProject
 Input [1]: [i_product_name#12]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_product_name#12 ASC NULLS FIRST], output=[i_product_name#12]), [i_product_name#12], 100, [i_product_name#12 ASC NULLS FIRST], [i_product_name#12]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_product_name#12 ASC NULLS FIRST], output=[i_product_name#12]), [i_product_name#12], 100, 0, [i_product_name#12 ASC NULLS FIRST], [i_product_name#12]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [1]: [i_product_name#12]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q44/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q44/explain.txt
index 8b2d63190..80c88cea0 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q44/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q44/explain.txt
@@ -246,7 +246,7 @@ Arguments: [rnk#14, best_performing#28, worst_performing#29], [rnk#14, i_product
 
 (47) CometTakeOrderedAndProject
 Input [3]: [rnk#14, best_performing#28, worst_performing#29]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[rnk#14 ASC NULLS FIRST], output=[rnk#14,best_performing#28,worst_performing#29]), [rnk#14, best_performing#28, worst_performing#29], 100, [rnk#14 ASC NULLS FIRST], [rnk#14, best_performing#28, worst_performing#29]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[rnk#14 ASC NULLS FIRST], output=[rnk#14,best_performing#28,worst_performing#29]), [rnk#14, best_performing#28, worst_performing#29], 100, 0, [rnk#14 ASC NULLS FIRST], [rnk#14, best_performing#28, worst_performing#29]
 
 (48) CometColumnarToRow [codegen id : 9]
 Input [3]: [rnk#14, best_performing#28, worst_performing#29]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q49/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q49/explain.txt
index aa3d6bdae..411bf90c7 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q49/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q49/explain.txt
@@ -454,7 +454,7 @@ Functions: []
 
 (83) CometTakeOrderedAndProject
 Input [5]: [channel#37, item#32, return_ratio#33, return_rank#35, currency_rank#36]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#37 ASC NULLS FIRST,return_rank#35 ASC NULLS FIRST,currency_rank#36 ASC NULLS FIRST], output=[channel#37,item#32,return_ratio#33,return_rank#35,currency_rank#36]), [channel#37, item#32, return_ratio#33, return_rank#35, currency_rank#36], 100, [channel#37 ASC NULLS FIRST, return_rank#35 ASC NULLS FIRST, currency_rank#36 ASC NULLS FIRST], [channel#37, item#32, return_ratio#33, return_rank#35, currency_rank#36]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#37 ASC NULLS FIRST,return_rank#35 ASC NULLS FIRST,currency_rank#36 ASC NULLS FIRST], output=[channel#37,item#32,return_ratio#33,return_rank#35,currency_rank#36]), [channel#37, item#32, return_ratio#33, return_rank#35, currency_rank#36], 100, 0, [channel#37 ASC NULLS FIRST, return_rank#35 ASC NULLS FIRST, currency_rank#36 ASC NULLS FIRST], [channel#37, item#32, return_ratio#33, return_rank#35, currency_rank#36]
 
 (84) CometColumnarToRow [codegen id : 17]
 Input [5]: [channel#37, item#32, return_ratio#33, return_rank#35, currency_rank#36]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q72/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q72/explain.txt
index f7cfd53f2..6941ea9c9 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q72/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q72/explain.txt
@@ -362,7 +362,7 @@ Functions [1]: [count(1)]
 
 (63) CometTakeOrderedAndProject
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC NUL [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, 0, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC  [...]
 
 (64) CometColumnarToRow [codegen id : 1]
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q75/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q75/explain.txt
index cf2ed414b..56b1d02d7 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q75/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q75/explain.txt
@@ -698,7 +698,7 @@ Arguments: [prev_year#133, year#134, i_brand_id#8, i_class_id#9, i_category_id#1
 
 (127) CometTakeOrderedAndProject
 Input [10]: [prev_year#133, year#134, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#135, curr_yr_cnt#136, sales_cnt_diff#137, sales_amt_diff#138]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#137 ASC NULLS FIRST], output=[prev_year#133,year#134,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#135,curr_yr_cnt#136,sales_cnt_diff#137,sales_amt_diff#138]), [prev_year#133, year#134, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#135, curr_yr_cnt#136, sales_cnt_diff#137, sales_amt_diff#138], 100, [sales_cnt_diff#137 ASC NULLS FIRST], [prev_year#133, year#134, i_br [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#137 ASC NULLS FIRST], output=[prev_year#133,year#134,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#135,curr_yr_cnt#136,sales_cnt_diff#137,sales_amt_diff#138]), [prev_year#133, year#134, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#135, curr_yr_cnt#136, sales_cnt_diff#137, sales_amt_diff#138], 100, 0, [sales_cnt_diff#137 ASC NULLS FIRST], [prev_year#133, year#134, i [...]
 
 (128) CometColumnarToRow [codegen id : 5]
 Input [10]: [prev_year#133, year#134, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#135, curr_yr_cnt#136, sales_cnt_diff#137, sales_amt_diff#138]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q82/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q82/explain.txt
index 1c6f1071a..b5ea6fc0e 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q82/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4-spark4_0/q82/explain.txt
@@ -143,7 +143,7 @@ Functions: []
 
 (25) CometTakeOrderedAndProject
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, 0, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
 
 (26) CometColumnarToRow [codegen id : 1]
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q1/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q1/explain.txt
index ae43e0dc5..e6ddc35a0 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q1/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q1/explain.txt
@@ -227,7 +227,7 @@ Arguments: [c_customer_id#22], [c_customer_id#22]
 
 (40) CometTakeOrderedAndProject
 Input [1]: [c_customer_id#22]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#22 ASC NULLS FIRST], output=[c_customer_id#22]), [c_customer_id#22], 100, [c_customer_id#22 ASC NULLS FIRST], [c_customer_id#22]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#22 ASC NULLS FIRST], output=[c_customer_id#22]), [c_customer_id#22], 100, 0, [c_customer_id#22 ASC NULLS FIRST], [c_customer_id#22]
 
 (41) CometColumnarToRow [codegen id : 1]
 Input [1]: [c_customer_id#22]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q11/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q11/explain.txt
index f2cee5ac3..4ff78694c 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q11/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q11/explain.txt
@@ -411,7 +411,7 @@ Arguments: [customer_preferred_cust_flag#42], [customer_preferred_cust_flag#42]
 
 (72) CometTakeOrderedAndProject
 Input [1]: [customer_preferred_cust_flag#42]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_preferred_cust_flag#42 ASC NULLS FIRST], output=[customer_preferred_cust_flag#42]), [customer_preferred_cust_flag#42], 100, [customer_preferred_cust_flag#42 ASC NULLS FIRST], [customer_preferred_cust_flag#42]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_preferred_cust_flag#42 ASC NULLS FIRST], output=[customer_preferred_cust_flag#42]), [customer_preferred_cust_flag#42], 100, 0, [customer_preferred_cust_flag#42 ASC NULLS FIRST], [customer_preferred_cust_flag#42]
 
 (73) CometColumnarToRow [codegen id : 1]
 Input [1]: [customer_preferred_cust_flag#42]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q14a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q14a/explain.txt
index 868da4cd9..471272f3f 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q14a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q14a/explain.txt
@@ -567,7 +567,7 @@ Functions [2]: [sum(sales#49), sum(number_sales#50)]
 
 (101) CometTakeOrderedAndProject
 Input [6]: [channel#89, i_brand_id#90, i_class_id#91, i_category_id#92, sum(sales)#97, sum(number_sales)#98]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#89 ASC NULLS FIRST,i_brand_id#90 ASC NULLS FIRST,i_class_id#91 ASC NULLS FIRST,i_category_id#92 ASC NULLS FIRST], output=[channel#89,i_brand_id#90,i_class_id#91,i_category_id#92,sum(sales)#97,sum(number_sales)#98]), [channel#89, i_brand_id#90, i_class_id#91, i_category_id#92, sum(sales)#97, sum(number_sales)#98], 100, [channel#89 ASC NULLS FIRST, i_brand_id#90 ASC NULLS FIRST, i_class_id#91 ASC NULLS FIRST, i_category_id#92 ASC [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#89 ASC NULLS FIRST,i_brand_id#90 ASC NULLS FIRST,i_class_id#91 ASC NULLS FIRST,i_category_id#92 ASC NULLS FIRST], output=[channel#89,i_brand_id#90,i_class_id#91,i_category_id#92,sum(sales)#97,sum(number_sales)#98]), [channel#89, i_brand_id#90, i_class_id#91, i_category_id#92, sum(sales)#97, sum(number_sales)#98], 100, 0, [channel#89 ASC NULLS FIRST, i_brand_id#90 ASC NULLS FIRST, i_class_id#91 ASC NULLS FIRST, i_category_id#92  [...]
 
 (102) CometColumnarToRow [codegen id : 1]
 Input [6]: [channel#89, i_brand_id#90, i_class_id#91, i_category_id#92, sum(sales)#97, sum(number_sales)#98]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q14b/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q14b/explain.txt
index 17a4737b2..29ec33d64 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q14b/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q14b/explain.txt
@@ -478,7 +478,7 @@ Arguments: [i_brand_id#40, i_class_id#41, i_category_id#42], [i_brand_id#61, i_c
 
 (84) CometTakeOrderedAndProject
 Input [12]: [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#71, i_brand_id#61, i_class_id#62, i_category_id#63, sales#72, number_sales#73]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#50,i_brand_id#40,i_class_id#41,i_category_id#42,sales#51,number_sales#52,channel#71,i_brand_id#61,i_class_id#62,i_category_id#63,sales#72,number_sales#73]), [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#71, i_brand_id#61, i_class_id#62, i_category_id#63, sales#72, number_sales# [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#50,i_brand_id#40,i_class_id#41,i_category_id#42,sales#51,number_sales#52,channel#71,i_brand_id#61,i_class_id#62,i_category_id#63,sales#72,number_sales#73]), [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#71, i_brand_id#61, i_class_id#62, i_category_id#63, sales#72, number_sales# [...]
 
 (85) CometColumnarToRow [codegen id : 1]
 Input [12]: [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#71, i_brand_id#61, i_class_id#62, i_category_id#63, sales#72, number_sales#73]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q15/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q15/explain.txt
index a56066b83..9abb6a939 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q15/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q15/explain.txt
@@ -133,7 +133,7 @@ Functions [1]: [sum(UnscaledValue(cs_sales_price#2))]
 
 (23) CometTakeOrderedAndProject
 Input [2]: [ca_zip#11, sum(cs_sales_price)#16]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_zip#11 ASC NULLS FIRST], output=[ca_zip#11,sum(cs_sales_price)#16]), [ca_zip#11, sum(cs_sales_price)#16], 100, [ca_zip#11 ASC NULLS FIRST], [ca_zip#11, sum(cs_sales_price)#16]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_zip#11 ASC NULLS FIRST], output=[ca_zip#11,sum(cs_sales_price)#16]), [ca_zip#11, sum(cs_sales_price)#16], 100, 0, [ca_zip#11 ASC NULLS FIRST], [ca_zip#11, sum(cs_sales_price)#16]
 
 (24) CometColumnarToRow [codegen id : 1]
 Input [2]: [ca_zip#11, sum(cs_sales_price)#16]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q17/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q17/explain.txt
index ab58eb37e..ecd1fec3f 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q17/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q17/explain.txt
@@ -247,7 +247,7 @@ Functions [9]: [count(ss_quantity#5), avg(ss_quantity#5), stddev_samp(cast(ss_qu
 
 (43) CometTakeOrderedAndProject
 Input [15]: [i_item_id#30, i_item_desc#29, s_state#26, store_sales_quantitycount#49, store_sales_quantityave#50, store_sales_quantitystdev#51, store_sales_quantitycov#52, as_store_returns_quantitycount#53, as_store_returns_quantityave#54, as_store_returns_quantitystdev#55, store_returns_quantitycov#56, catalog_sales_quantitycount#57, catalog_sales_quantityave#58, catalog_sales_quantitystdev#59, catalog_sales_quantitycov#60]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#30 ASC NULLS FIRST,i_item_desc#29 ASC NULLS FIRST,s_state#26 ASC NULLS FIRST], output=[i_item_id#30,i_item_desc#29,s_state#26,store_sales_quantitycount#49,store_sales_quantityave#50,store_sales_quantitystdev#51,store_sales_quantitycov#52,as_store_returns_quantitycount#53,as_store_returns_quantityave#54,as_store_returns_quantitystdev#55,store_returns_quantitycov#56,catalog_sales_quantitycount#57,catalog_sales_quantityave#58,ca [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#30 ASC NULLS FIRST,i_item_desc#29 ASC NULLS FIRST,s_state#26 ASC NULLS FIRST], output=[i_item_id#30,i_item_desc#29,s_state#26,store_sales_quantitycount#49,store_sales_quantityave#50,store_sales_quantitystdev#51,store_sales_quantitycov#52,as_store_returns_quantitycount#53,as_store_returns_quantityave#54,as_store_returns_quantitystdev#55,store_returns_quantitycov#56,catalog_sales_quantitycount#57,catalog_sales_quantityave#58,ca [...]
 
 (44) CometColumnarToRow [codegen id : 1]
 Input [15]: [i_item_id#30, i_item_desc#29, s_state#26, store_sales_quantitycount#49, store_sales_quantityave#50, store_sales_quantitystdev#51, store_sales_quantitycov#52, as_store_returns_quantitycount#53, as_store_returns_quantityave#54, as_store_returns_quantitystdev#55, store_returns_quantitycov#56, catalog_sales_quantitycount#57, catalog_sales_quantityave#58, catalog_sales_quantitystdev#59, catalog_sales_quantitycov#60]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q18/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q18/explain.txt
index 29e12f97b..f04ca8727 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q18/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q18/explain.txt
@@ -240,7 +240,7 @@ Functions [7]: [avg(cast(cs_quantity#4 as decimal(12,2))), avg(cast(cs_list_pric
 
 (42) CometTakeOrderedAndProject
 Input [11]: [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#50, agg2#51, agg3#52, agg4#53, agg5#54, agg6#55, agg7#56]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_country#32 ASC NULLS FIRST,ca_state#33 ASC NULLS FIRST,ca_county#34 ASC NULLS FIRST,i_item_id#31 ASC NULLS FIRST], output=[i_item_id#31,ca_country#32,ca_state#33,ca_county#34,agg1#50,agg2#51,agg3#52,agg4#53,agg5#54,agg6#55,agg7#56]), [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#50, agg2#51, agg3#52, agg4#53, agg5#54, agg6#55, agg7#56], 100, [ca_country#32 ASC NULLS FIRST, ca_state#33 ASC NULLS FIRST, ca_county#34 AS [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_country#32 ASC NULLS FIRST,ca_state#33 ASC NULLS FIRST,ca_county#34 ASC NULLS FIRST,i_item_id#31 ASC NULLS FIRST], output=[i_item_id#31,ca_country#32,ca_state#33,ca_county#34,agg1#50,agg2#51,agg3#52,agg4#53,agg5#54,agg6#55,agg7#56]), [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#50, agg2#51, agg3#52, agg4#53, agg5#54, agg6#55, agg7#56], 100, 0, [ca_country#32 ASC NULLS FIRST, ca_state#33 ASC NULLS FIRST, ca_county#34 [...]
 
 (43) CometColumnarToRow [codegen id : 1]
 Input [11]: [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#50, agg2#51, agg3#52, agg4#53, agg5#54, agg6#55, agg7#56]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q19/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q19/explain.txt
index 11c0339bb..9c7a334ef 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q19/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q19/explain.txt
@@ -201,7 +201,7 @@ Functions [1]: [sum(UnscaledValue(ss_ext_sales_price#7))]
 
 (35) CometTakeOrderedAndProject
 Input [5]: [brand_id#26, brand#27, i_manufact_id#12, i_manufact#16, ext_price#28]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ext_price#28 DESC NULLS LAST,brand#27 ASC NULLS FIRST,brand_id#26 ASC NULLS FIRST,i_manufact_id#12 ASC NULLS FIRST,i_manufact#16 ASC NULLS FIRST], output=[brand_id#26,brand#27,i_manufact_id#12,i_manufact#16,ext_price#28]), [brand_id#26, brand#27, i_manufact_id#12, i_manufact#16, ext_price#28], 100, [ext_price#28 DESC NULLS LAST, brand#27 ASC NULLS FIRST, brand_id#26 ASC NULLS FIRST, i_manufact_id#12 ASC NULLS FIRST, i_manufact#16 ASC N [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ext_price#28 DESC NULLS LAST,brand#27 ASC NULLS FIRST,brand_id#26 ASC NULLS FIRST,i_manufact_id#12 ASC NULLS FIRST,i_manufact#16 ASC NULLS FIRST], output=[brand_id#26,brand#27,i_manufact_id#12,i_manufact#16,ext_price#28]), [brand_id#26, brand#27, i_manufact_id#12, i_manufact#16, ext_price#28], 100, 0, [ext_price#28 DESC NULLS LAST, brand#27 ASC NULLS FIRST, brand_id#26 ASC NULLS FIRST, i_manufact_id#12 ASC NULLS FIRST, i_manufact#16 AS [...]
 
 (36) CometColumnarToRow [codegen id : 1]
 Input [5]: [brand_id#26, brand#27, i_manufact_id#12, i_manufact#16, ext_price#28]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q21/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q21/explain.txt
index f575a19a9..8f4413b65 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q21/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q21/explain.txt
@@ -133,7 +133,7 @@ Condition : (CASE WHEN (inv_before#16 > 0) THEN (knownfloatingpointnormalized(no
 
 (23) CometTakeOrderedAndProject
 Input [4]: [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_warehouse_name#7 ASC NULLS FIRST,i_item_id#11 ASC NULLS FIRST], output=[w_warehouse_name#7,i_item_id#11,inv_before#16,inv_after#17]), [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17], 100, [w_warehouse_name#7 ASC NULLS FIRST, i_item_id#11 ASC NULLS FIRST], [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_warehouse_name#7 ASC NULLS FIRST,i_item_id#11 ASC NULLS FIRST], output=[w_warehouse_name#7,i_item_id#11,inv_before#16,inv_after#17]), [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17], 100, 0, [w_warehouse_name#7 ASC NULLS FIRST, i_item_id#11 ASC NULLS FIRST], [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17]
 
 (24) CometColumnarToRow [codegen id : 1]
 Input [4]: [w_warehouse_name#7, i_item_id#11, inv_before#16, inv_after#17]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q22/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q22/explain.txt
index 2b0bf616f..20dd5e20b 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q22/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q22/explain.txt
@@ -138,7 +138,7 @@ Functions [1]: [avg(inv_quantity_on_hand#3)]
 
 (24) CometTakeOrderedAndProject
 Input [5]: [i_product_name#18, i_brand#19, i_class#20, i_category#21, qoh#25]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[qoh#25 ASC NULLS FIRST,i_product_name#18 ASC NULLS FIRST,i_brand#19 ASC NULLS FIRST,i_class#20 ASC NULLS FIRST,i_category#21 ASC NULLS FIRST], output=[i_product_name#18,i_brand#19,i_class#20,i_category#21,qoh#25]), [i_product_name#18, i_brand#19, i_class#20, i_category#21, qoh#25], 100, [qoh#25 ASC NULLS FIRST, i_product_name#18 ASC NULLS FIRST, i_brand#19 ASC NULLS FIRST, i_class#20 ASC NULLS FIRST, i_category#21 ASC NULLS FIRST], [i_ [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[qoh#25 ASC NULLS FIRST,i_product_name#18 ASC NULLS FIRST,i_brand#19 ASC NULLS FIRST,i_class#20 ASC NULLS FIRST,i_category#21 ASC NULLS FIRST], output=[i_product_name#18,i_brand#19,i_class#20,i_category#21,qoh#25]), [i_product_name#18, i_brand#19, i_class#20, i_category#21, qoh#25], 100, 0, [qoh#25 ASC NULLS FIRST, i_product_name#18 ASC NULLS FIRST, i_brand#19 ASC NULLS FIRST, i_class#20 ASC NULLS FIRST, i_category#21 ASC NULLS FIRST],  [...]
 
 (25) CometColumnarToRow [codegen id : 1]
 Input [5]: [i_product_name#18, i_brand#19, i_class#20, i_category#21, qoh#25]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q23b/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q23b/explain.txt
index 2fe963e11..52a0eb4e6 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q23b/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q23b/explain.txt
@@ -482,7 +482,7 @@ Child 1 Input [3]: [c_last_name#47, c_first_name#46, sales#52]
 
 (87) CometTakeOrderedAndProject
 Input [3]: [c_last_name#33, c_first_name#32, sales#51]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#33 ASC NULLS FIRST,c_first_name#32 ASC NULLS FIRST,sales#51 ASC NULLS FIRST], output=[c_last_name#33,c_first_name#32,sales#51]), [c_last_name#33, c_first_name#32, sales#51], 100, [c_last_name#33 ASC NULLS FIRST, c_first_name#32 ASC NULLS FIRST, sales#51 ASC NULLS FIRST], [c_last_name#33, c_first_name#32, sales#51]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#33 ASC NULLS FIRST,c_first_name#32 ASC NULLS FIRST,sales#51 ASC NULLS FIRST], output=[c_last_name#33,c_first_name#32,sales#51]), [c_last_name#33, c_first_name#32, sales#51], 100, 0, [c_last_name#33 ASC NULLS FIRST, c_first_name#32 ASC NULLS FIRST, sales#51 ASC NULLS FIRST], [c_last_name#33, c_first_name#32, sales#51]
 
 (88) CometColumnarToRow [codegen id : 1]
 Input [3]: [c_last_name#33, c_first_name#32, sales#51]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q25/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q25/explain.txt
index e63dc7818..a284abb21 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q25/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q25/explain.txt
@@ -247,7 +247,7 @@ Functions [3]: [sum(UnscaledValue(ss_net_profit#5)), sum(UnscaledValue(sr_net_lo
 
 (43) CometTakeOrderedAndProject
 Input [7]: [i_item_id#33, i_item_desc#32, s_store_id#29, s_store_name#28, store_sales_profit#37, store_returns_loss#38, catalog_sales_profit#39]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#33 ASC NULLS FIRST,i_item_desc#32 ASC NULLS FIRST,s_store_id#29 ASC NULLS FIRST,s_store_name#28 ASC NULLS FIRST], output=[i_item_id#33,i_item_desc#32,s_store_id#29,s_store_name#28,store_sales_profit#37,store_returns_loss#38,catalog_sales_profit#39]), [i_item_id#33, i_item_desc#32, s_store_id#29, s_store_name#28, store_sales_profit#37, store_returns_loss#38, catalog_sales_profit#39], 100, [i_item_id#33 ASC NULLS FIRST, i_item_ [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#33 ASC NULLS FIRST,i_item_desc#32 ASC NULLS FIRST,s_store_id#29 ASC NULLS FIRST,s_store_name#28 ASC NULLS FIRST], output=[i_item_id#33,i_item_desc#32,s_store_id#29,s_store_name#28,store_sales_profit#37,store_returns_loss#38,catalog_sales_profit#39]), [i_item_id#33, i_item_desc#32, s_store_id#29, s_store_name#28, store_sales_profit#37, store_returns_loss#38, catalog_sales_profit#39], 100, 0, [i_item_id#33 ASC NULLS FIRST, i_it [...]
 
 (44) CometColumnarToRow [codegen id : 1]
 Input [7]: [i_item_id#33, i_item_desc#32, s_store_id#29, s_store_name#28, store_sales_profit#37, store_returns_loss#38, catalog_sales_profit#39]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q26/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q26/explain.txt
index a065e1234..bf78c49fd 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q26/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q26/explain.txt
@@ -172,7 +172,7 @@ Functions [4]: [avg(cs_quantity#4), avg(UnscaledValue(cs_list_price#5)), avg(Uns
 
 (30) CometTakeOrderedAndProject
 Input [5]: [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#18 ASC NULLS FIRST], output=[i_item_id#18,agg1#30,agg2#31,agg3#32,agg4#33]), [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33], 100, [i_item_id#18 ASC NULLS FIRST], [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#18 ASC NULLS FIRST], output=[i_item_id#18,agg1#30,agg2#31,agg3#32,agg4#33]), [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33], 100, 0, [i_item_id#18 ASC NULLS FIRST], [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
 
 (31) CometColumnarToRow [codegen id : 1]
 Input [5]: [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q27/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q27/explain.txt
index 65443cbc1..6873f4828 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q27/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q27/explain.txt
@@ -177,7 +177,7 @@ Functions [4]: [avg(ss_quantity#4), avg(UnscaledValue(ss_list_price#5)), avg(Uns
 
 (31) CometTakeOrderedAndProject
 Input [7]: [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#22 ASC NULLS FIRST,s_state#23 ASC NULLS FIRST], output=[i_item_id#22,s_state#23,g_state#33,agg1#34,agg2#35,agg3#36,agg4#37]), [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37], 100, [i_item_id#22 ASC NULLS FIRST, s_state#23 ASC NULLS FIRST], [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#22 ASC NULLS FIRST,s_state#23 ASC NULLS FIRST], output=[i_item_id#22,s_state#23,g_state#33,agg1#34,agg2#35,agg3#36,agg4#37]), [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37], 100, 0, [i_item_id#22 ASC NULLS FIRST, s_state#23 ASC NULLS FIRST], [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37]
 
 (32) CometColumnarToRow [codegen id : 1]
 Input [7]: [i_item_id#22, s_state#23, g_state#33, agg1#34, agg2#35, agg3#36, agg4#37]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q29/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q29/explain.txt
index 16d5abf00..65169e693 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q29/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q29/explain.txt
@@ -266,7 +266,7 @@ Functions [3]: [sum(ss_quantity#5), sum(sr_return_quantity#11), sum(cs_quantity#
 
 (46) CometTakeOrderedAndProject
 Input [7]: [i_item_id#34, i_item_desc#33, s_store_id#30, s_store_name#29, store_sales_quantity#38, store_returns_quantity#39, catalog_sales_quantity#40]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#34 ASC NULLS FIRST,i_item_desc#33 ASC NULLS FIRST,s_store_id#30 ASC NULLS FIRST,s_store_name#29 ASC NULLS FIRST], output=[i_item_id#34,i_item_desc#33,s_store_id#30,s_store_name#29,store_sales_quantity#38,store_returns_quantity#39,catalog_sales_quantity#40]), [i_item_id#34, i_item_desc#33, s_store_id#30, s_store_name#29, store_sales_quantity#38, store_returns_quantity#39, catalog_sales_quantity#40], 100, [i_item_id#34 ASC NULL [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#34 ASC NULLS FIRST,i_item_desc#33 ASC NULLS FIRST,s_store_id#30 ASC NULLS FIRST,s_store_name#29 ASC NULLS FIRST], output=[i_item_id#34,i_item_desc#33,s_store_id#30,s_store_name#29,store_sales_quantity#38,store_returns_quantity#39,catalog_sales_quantity#40]), [i_item_id#34, i_item_desc#33, s_store_id#30, s_store_name#29, store_sales_quantity#38, store_returns_quantity#39, catalog_sales_quantity#40], 100, 0, [i_item_id#34 ASC N [...]
 
 (47) CometColumnarToRow [codegen id : 1]
 Input [7]: [i_item_id#34, i_item_desc#33, s_store_id#30, s_store_name#29, store_sales_quantity#38, store_returns_quantity#39, catalog_sales_quantity#40]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q3/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q3/explain.txt
index 56f0aa3fc..ebd80da9c 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q3/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q3/explain.txt
@@ -104,7 +104,7 @@ Functions [1]: [sum(UnscaledValue(ss_ext_sales_price#5))]
 
 (18) CometTakeOrderedAndProject
 Input [4]: [d_year#2, brand_id#13, brand#14, sum_agg#15]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[d_year#2 ASC NULLS FIRST,sum_agg#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[d_year#2,brand_id#13,brand#14,sum_agg#15]), [d_year#2, brand_id#13, brand#14, sum_agg#15], 100, [d_year#2 ASC NULLS FIRST, sum_agg#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [d_year#2, brand_id#13, brand#14, sum_agg#15]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[d_year#2 ASC NULLS FIRST,sum_agg#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[d_year#2,brand_id#13,brand#14,sum_agg#15]), [d_year#2, brand_id#13, brand#14, sum_agg#15], 100, 0, [d_year#2 ASC NULLS FIRST, sum_agg#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [d_year#2, brand_id#13, brand#14, sum_agg#15]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [4]: [d_year#2, brand_id#13, brand#14, sum_agg#15]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q30/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q30/explain.txt
index 7f1d96fa0..054d184d8 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q30/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q30/explain.txt
@@ -276,7 +276,7 @@ Arguments: [c_customer_id#35, c_salutation#36, c_first_name#37, c_last_name#38,
 
 (49) CometTakeOrderedAndProject
 Input [13]: [c_customer_id#35, c_salutation#36, c_first_name#37, c_last_name#38, c_preferred_cust_flag#39, c_birth_day#28, c_birth_month#29, c_birth_year#30, c_birth_country#31, c_login#40, c_email_address#41, c_last_review_date#34, ctr_total_return#14]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#35 ASC NULLS FIRST,c_salutation#36 ASC NULLS FIRST,c_first_name#37 ASC NULLS FIRST,c_last_name#38 ASC NULLS FIRST,c_preferred_cust_flag#39 ASC NULLS FIRST,c_birth_day#28 ASC NULLS FIRST,c_birth_month#29 ASC NULLS FIRST,c_birth_year#30 ASC NULLS FIRST,c_birth_country#31 ASC NULLS FIRST,c_login#40 ASC NULLS FIRST,c_email_address#41 ASC NULLS FIRST,c_last_review_date#34 ASC NULLS FIRST,ctr_total_return#14 ASC NULLS FIRST], o [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#35 ASC NULLS FIRST,c_salutation#36 ASC NULLS FIRST,c_first_name#37 ASC NULLS FIRST,c_last_name#38 ASC NULLS FIRST,c_preferred_cust_flag#39 ASC NULLS FIRST,c_birth_day#28 ASC NULLS FIRST,c_birth_month#29 ASC NULLS FIRST,c_birth_year#30 ASC NULLS FIRST,c_birth_country#31 ASC NULLS FIRST,c_login#40 ASC NULLS FIRST,c_email_address#41 ASC NULLS FIRST,c_last_review_date#34 ASC NULLS FIRST,ctr_total_return#14 ASC NULLS FIRST], o [...]
 
 (50) CometColumnarToRow [codegen id : 1]
 Input [13]: [c_customer_id#35, c_salutation#36, c_first_name#37, c_last_name#38, c_preferred_cust_flag#39, c_birth_day#28, c_birth_month#29, c_birth_year#30, c_birth_country#31, c_login#40, c_email_address#41, c_last_review_date#34, ctr_total_return#14]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q33/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q33/explain.txt
index c393d11e6..5068d38ba 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q33/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q33/explain.txt
@@ -378,7 +378,7 @@ Functions [1]: [sum(total_sales#36)]
 
 (67) CometTakeOrderedAndProject
 Input [2]: [i_manufact_id#12, total_sales#41]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_sales#41 ASC NULLS FIRST], output=[i_manufact_id#12,total_sales#41]), [i_manufact_id#12, total_sales#41], 100, [total_sales#41 ASC NULLS FIRST], [i_manufact_id#12, total_sales#41]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_sales#41 ASC NULLS FIRST], output=[i_manufact_id#12,total_sales#41]), [i_manufact_id#12, total_sales#41], 100, 0, [total_sales#41 ASC NULLS FIRST], [i_manufact_id#12, total_sales#41]
 
 (68) CometColumnarToRow [codegen id : 1]
 Input [2]: [i_manufact_id#12, total_sales#41]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q37/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q37/explain.txt
index 3471befec..830dbbb9f 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q37/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q37/explain.txt
@@ -143,7 +143,7 @@ Functions: []
 
 (25) CometTakeOrderedAndProject
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, 0, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
 
 (26) CometColumnarToRow [codegen id : 1]
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q4/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q4/explain.txt
index b0b57f84d..7e2e253e1 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q4/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q4/explain.txt
@@ -603,7 +603,7 @@ Arguments: [customer_id#47, customer_first_name#48, customer_last_name#49, custo
 
 (106) CometTakeOrderedAndProject
 Input [7]: [customer_id#47, customer_first_name#48, customer_last_name#49, customer_preferred_cust_flag#50, customer_birth_country#51, customer_login#52, customer_email_address#53]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#47 ASC NULLS FIRST,customer_first_name#48 ASC NULLS FIRST,customer_last_name#49 ASC NULLS FIRST,customer_preferred_cust_flag#50 ASC NULLS FIRST,customer_birth_country#51 ASC NULLS FIRST,customer_login#52 ASC NULLS FIRST,customer_email_address#53 ASC NULLS FIRST], output=[customer_id#47,customer_first_name#48,customer_last_name#49,customer_preferred_cust_flag#50,customer_birth_country#51,customer_login#52,customer_email_addr [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#47 ASC NULLS FIRST,customer_first_name#48 ASC NULLS FIRST,customer_last_name#49 ASC NULLS FIRST,customer_preferred_cust_flag#50 ASC NULLS FIRST,customer_birth_country#51 ASC NULLS FIRST,customer_login#52 ASC NULLS FIRST,customer_email_address#53 ASC NULLS FIRST], output=[customer_id#47,customer_first_name#48,customer_last_name#49,customer_preferred_cust_flag#50,customer_birth_country#51,customer_login#52,customer_email_addr [...]
 
 (107) CometColumnarToRow [codegen id : 1]
 Input [7]: [customer_id#47, customer_first_name#48, customer_last_name#49, customer_preferred_cust_flag#50, customer_birth_country#51, customer_login#52, customer_email_address#53]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q40/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q40/explain.txt
index 3007e144e..15a833372 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q40/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q40/explain.txt
@@ -182,7 +182,7 @@ Functions [2]: [sum(CASE WHEN (d_date#19 < 2000-03-11) THEN (cs_sales_price#4 -
 
 (32) CometTakeOrderedAndProject
 Input [4]: [w_state#13, i_item_id#17, sales_before#24, sales_after#25]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_state#13 ASC NULLS FIRST,i_item_id#17 ASC NULLS FIRST], output=[w_state#13,i_item_id#17,sales_before#24,sales_after#25]), [w_state#13, i_item_id#17, sales_before#24, sales_after#25], 100, [w_state#13 ASC NULLS FIRST, i_item_id#17 ASC NULLS FIRST], [w_state#13, i_item_id#17, sales_before#24, sales_after#25]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_state#13 ASC NULLS FIRST,i_item_id#17 ASC NULLS FIRST], output=[w_state#13,i_item_id#17,sales_before#24,sales_after#25]), [w_state#13, i_item_id#17, sales_before#24, sales_after#25], 100, 0, [w_state#13 ASC NULLS FIRST, i_item_id#17 ASC NULLS FIRST], [w_state#13, i_item_id#17, sales_before#24, sales_after#25]
 
 (33) CometColumnarToRow [codegen id : 1]
 Input [4]: [w_state#13, i_item_id#17, sales_before#24, sales_after#25]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q41/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q41/explain.txt
index 5c1d2f58b..b31887a02 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q41/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q41/explain.txt
@@ -100,7 +100,7 @@ Functions: []
 
 (18) CometTakeOrderedAndProject
 Input [1]: [i_product_name#11]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_product_name#11 ASC NULLS FIRST], output=[i_product_name#11]), [i_product_name#11], 100, [i_product_name#11 ASC NULLS FIRST], [i_product_name#11]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_product_name#11 ASC NULLS FIRST], output=[i_product_name#11]), [i_product_name#11], 100, 0, [i_product_name#11 ASC NULLS FIRST], [i_product_name#11]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [1]: [i_product_name#11]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q42/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q42/explain.txt
index b00bd88f0..4f1acd777 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q42/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q42/explain.txt
@@ -104,7 +104,7 @@ Functions [1]: [sum(UnscaledValue(ss_ext_sales_price#5))]
 
 (18) CometTakeOrderedAndProject
 Input [4]: [d_year#2, i_category_id#8, i_category#11, sum(ss_ext_sales_price)#13]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[sum(ss_ext_sales_price)#13 DESC NULLS LAST,d_year#2 ASC NULLS FIRST,i_category_id#8 ASC NULLS FIRST,i_category#11 ASC NULLS FIRST], output=[d_year#2,i_category_id#8,i_category#11,sum(ss_ext_sales_price)#13]), [d_year#2, i_category_id#8, i_category#11, sum(ss_ext_sales_price)#13], 100, [sum(ss_ext_sales_price)#13 DESC NULLS LAST, d_year#2 ASC NULLS FIRST, i_category_id#8 ASC NULLS FIRST, i_category#11 ASC NULLS FIRST], [d_year#2, i_cate [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[sum(ss_ext_sales_price)#13 DESC NULLS LAST,d_year#2 ASC NULLS FIRST,i_category_id#8 ASC NULLS FIRST,i_category#11 ASC NULLS FIRST], output=[d_year#2,i_category_id#8,i_category#11,sum(ss_ext_sales_price)#13]), [d_year#2, i_category_id#8, i_category#11, sum(ss_ext_sales_price)#13], 100, 0, [sum(ss_ext_sales_price)#13 DESC NULLS LAST, d_year#2 ASC NULLS FIRST, i_category_id#8 ASC NULLS FIRST, i_category#11 ASC NULLS FIRST], [d_year#2, i_c [...]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [4]: [d_year#2, i_category_id#8, i_category#11, sum(ss_ext_sales_price)#13]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q43/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q43/explain.txt
index b37b49c38..8364c89c7 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q43/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q43/explain.txt
@@ -104,7 +104,7 @@ Functions [7]: [sum(UnscaledValue(CASE WHEN (d_day_name#4 = Sunday   ) THEN ss_s
 
 (18) CometTakeOrderedAndProject
 Input [9]: [s_store_name#10, s_store_id#12, sun_sales#20, mon_sales#21, tue_sales#22, wed_sales#23, thu_sales#24, fri_sales#25, sat_sales#26]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#10 ASC NULLS FIRST,s_store_id#12 ASC NULLS FIRST,sun_sales#20 ASC NULLS FIRST,mon_sales#21 ASC NULLS FIRST,tue_sales#22 ASC NULLS FIRST,wed_sales#23 ASC NULLS FIRST,thu_sales#24 ASC NULLS FIRST,fri_sales#25 ASC NULLS FIRST,sat_sales#26 ASC NULLS FIRST], output=[s_store_name#10,s_store_id#12,sun_sales#20,mon_sales#21,tue_sales#22,wed_sales#23,thu_sales#24,fri_sales#25,sat_sales#26]), [s_store_name#10, s_store_id#12, sun_sal [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#10 ASC NULLS FIRST,s_store_id#12 ASC NULLS FIRST,sun_sales#20 ASC NULLS FIRST,mon_sales#21 ASC NULLS FIRST,tue_sales#22 ASC NULLS FIRST,wed_sales#23 ASC NULLS FIRST,thu_sales#24 ASC NULLS FIRST,fri_sales#25 ASC NULLS FIRST,sat_sales#26 ASC NULLS FIRST], output=[s_store_name#10,s_store_id#12,sun_sales#20,mon_sales#21,tue_sales#22,wed_sales#23,thu_sales#24,fri_sales#25,sat_sales#26]), [s_store_name#10, s_store_id#12, sun_sal [...]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [9]: [s_store_name#10, s_store_id#12, sun_sales#20, mon_sales#21, tue_sales#22, wed_sales#23, thu_sales#24, fri_sales#25, sat_sales#26]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q46/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q46/explain.txt
index 0675d9dc2..448854607 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q46/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q46/explain.txt
@@ -216,7 +216,7 @@ Arguments: [c_last_name#27, c_first_name#26, ca_city#32, bought_city#28, ss_tick
 
 (38) CometTakeOrderedAndProject
 Input [7]: [c_last_name#27, c_first_name#26, ca_city#32, bought_city#28, ss_ticket_number#5, amt#29, profit#30]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#27 ASC NULLS FIRST,c_first_name#26 ASC NULLS FIRST,ca_city#32 ASC NULLS FIRST,bought_city#28 ASC NULLS FIRST,ss_ticket_number#5 ASC NULLS FIRST], output=[c_last_name#27,c_first_name#26,ca_city#32,bought_city#28,ss_ticket_number#5,amt#29,profit#30]), [c_last_name#27, c_first_name#26, ca_city#32, bought_city#28, ss_ticket_number#5, amt#29, profit#30], 100, [c_last_name#27 ASC NULLS FIRST, c_first_name#26 ASC NULLS FIRST, ca_c [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#27 ASC NULLS FIRST,c_first_name#26 ASC NULLS FIRST,ca_city#32 ASC NULLS FIRST,bought_city#28 ASC NULLS FIRST,ss_ticket_number#5 ASC NULLS FIRST], output=[c_last_name#27,c_first_name#26,ca_city#32,bought_city#28,ss_ticket_number#5,amt#29,profit#30]), [c_last_name#27, c_first_name#26, ca_city#32, bought_city#28, ss_ticket_number#5, amt#29, profit#30], 100, 0, [c_last_name#27 ASC NULLS FIRST, c_first_name#26 ASC NULLS FIRST, c [...]
 
 (39) CometColumnarToRow [codegen id : 1]
 Input [7]: [c_last_name#27, c_first_name#26, ca_city#32, bought_city#28, ss_ticket_number#5, amt#29, profit#30]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q49/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q49/explain.txt
index 041046c4a..deca8f9f2 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q49/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q49/explain.txt
@@ -418,7 +418,7 @@ Functions: []
 
 (77) CometTakeOrderedAndProject
 Input [5]: [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#27 ASC NULLS FIRST,return_rank#25 ASC NULLS FIRST,currency_rank#26 ASC NULLS FIRST], output=[channel#27,item#22,return_ratio#23,return_rank#25,currency_rank#26]), [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26], 100, [channel#27 ASC NULLS FIRST, return_rank#25 ASC NULLS FIRST, currency_rank#26 ASC NULLS FIRST], [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#27 ASC NULLS FIRST,return_rank#25 ASC NULLS FIRST,currency_rank#26 ASC NULLS FIRST], output=[channel#27,item#22,return_ratio#23,return_rank#25,currency_rank#26]), [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26], 100, 0, [channel#27 ASC NULLS FIRST, return_rank#25 ASC NULLS FIRST, currency_rank#26 ASC NULLS FIRST], [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
 
 (78) CometColumnarToRow [codegen id : 11]
 Input [5]: [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q50/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q50/explain.txt
index 00741ade9..3f23166e3 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q50/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q50/explain.txt
@@ -163,7 +163,7 @@ Functions [5]: [sum(CASE WHEN ((sr_returned_date_sk#9 - ss_sold_date_sk#5) <= 30
 
 (28) CometTakeOrderedAndProject
 Input [15]: [s_store_name#12, s_company_id#13, s_street_number#14, s_street_name#15, s_street_type#22, s_suite_number#23, s_city#18, s_county#19, s_state#24, s_zip#25, 30 days #35, 31 - 60 days #36, 61 - 90 days #37, 91 - 120 days #38, >120 days #39]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#12 ASC NULLS FIRST,s_company_id#13 ASC NULLS FIRST,s_street_number#14 ASC NULLS FIRST,s_street_name#15 ASC NULLS FIRST,s_street_type#22 ASC NULLS FIRST,s_suite_number#23 ASC NULLS FIRST,s_city#18 ASC NULLS FIRST,s_county#19 ASC NULLS FIRST,s_state#24 ASC NULLS FIRST,s_zip#25 ASC NULLS FIRST], output=[s_store_name#12,s_company_id#13,s_street_number#14,s_street_name#15,s_street_type#22,s_suite_number#23,s_city#18,s_county#19 [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#12 ASC NULLS FIRST,s_company_id#13 ASC NULLS FIRST,s_street_number#14 ASC NULLS FIRST,s_street_name#15 ASC NULLS FIRST,s_street_type#22 ASC NULLS FIRST,s_suite_number#23 ASC NULLS FIRST,s_city#18 ASC NULLS FIRST,s_county#19 ASC NULLS FIRST,s_state#24 ASC NULLS FIRST,s_zip#25 ASC NULLS FIRST], output=[s_store_name#12,s_company_id#13,s_street_number#14,s_street_name#15,s_street_type#22,s_suite_number#23,s_city#18,s_county#19 [...]
 
 (29) CometColumnarToRow [codegen id : 1]
 Input [15]: [s_store_name#12, s_company_id#13, s_street_number#14, s_street_name#15, s_street_type#22, s_suite_number#23, s_city#18, s_county#19, s_state#24, s_zip#25, 30 days #35, 31 - 60 days #36, 61 - 90 days #37, 91 - 120 days #38, >120 days #39]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q52/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q52/explain.txt
index 7f8528d85..e38f69fcb 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q52/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q52/explain.txt
@@ -104,7 +104,7 @@ Functions [1]: [sum(UnscaledValue(ss_ext_sales_price#5))]
 
 (18) CometTakeOrderedAndProject
 Input [4]: [d_year#2, brand_id#13, brand#14, ext_price#15]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[d_year#2 ASC NULLS FIRST,ext_price#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[d_year#2,brand_id#13,brand#14,ext_price#15]), [d_year#2, brand_id#13, brand#14, ext_price#15], 100, [d_year#2 ASC NULLS FIRST, ext_price#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [d_year#2, brand_id#13, brand#14, ext_price#15]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[d_year#2 ASC NULLS FIRST,ext_price#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[d_year#2,brand_id#13,brand#14,ext_price#15]), [d_year#2, brand_id#13, brand#14, ext_price#15], 100, 0, [d_year#2 ASC NULLS FIRST, ext_price#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [d_year#2, brand_id#13, brand#14, ext_price#15]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [4]: [d_year#2, brand_id#13, brand#14, ext_price#15]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q54/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q54/explain.txt
index e35eebbcd..d23dbf3de 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q54/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q54/explain.txt
@@ -328,7 +328,7 @@ Functions [1]: [count(1)]
 
 (57) CometTakeOrderedAndProject
 Input [3]: [segment#40, num_customers#42, segment_base#43]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[segment#40 ASC NULLS FIRST,num_customers#42 ASC NULLS FIRST], output=[segment#40,num_customers#42,segment_base#43]), [segment#40, num_customers#42, segment_base#43], 100, [segment#40 ASC NULLS FIRST, num_customers#42 ASC NULLS FIRST], [segment#40, num_customers#42, segment_base#43]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[segment#40 ASC NULLS FIRST,num_customers#42 ASC NULLS FIRST], output=[segment#40,num_customers#42,segment_base#43]), [segment#40, num_customers#42, segment_base#43], 100, 0, [segment#40 ASC NULLS FIRST, num_customers#42 ASC NULLS FIRST], [segment#40, num_customers#42, segment_base#43]
 
 (58) CometColumnarToRow [codegen id : 1]
 Input [3]: [segment#40, num_customers#42, segment_base#43]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q55/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q55/explain.txt
index 543566c87..2b06aab6d 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q55/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q55/explain.txt
@@ -104,7 +104,7 @@ Functions [1]: [sum(UnscaledValue(ss_ext_sales_price#5))]
 
 (18) CometTakeOrderedAndProject
 Input [3]: [brand_id#13, brand#14, ext_price#15]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ext_price#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[brand_id#13,brand#14,ext_price#15]), [brand_id#13, brand#14, ext_price#15], 100, [ext_price#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [brand_id#13, brand#14, ext_price#15]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ext_price#15 DESC NULLS LAST,brand_id#13 ASC NULLS FIRST], output=[brand_id#13,brand#14,ext_price#15]), [brand_id#13, brand#14, ext_price#15], 100, 0, [ext_price#15 DESC NULLS LAST, brand_id#13 ASC NULLS FIRST], [brand_id#13, brand#14, ext_price#15]
 
 (19) CometColumnarToRow [codegen id : 1]
 Input [3]: [brand_id#13, brand#14, ext_price#15]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q56/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q56/explain.txt
index c78ae4305..8582e706d 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q56/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q56/explain.txt
@@ -341,7 +341,7 @@ Functions [1]: [sum(total_sales#39)]
 
 (61) CometTakeOrderedAndProject
 Input [2]: [i_item_id#38, total_sales#44]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_sales#44 ASC NULLS FIRST], output=[i_item_id#38,total_sales#44]), [i_item_id#38, total_sales#44], 100, [total_sales#44 ASC NULLS FIRST], [i_item_id#38, total_sales#44]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_sales#44 ASC NULLS FIRST], output=[i_item_id#38,total_sales#44]), [i_item_id#38, total_sales#44], 100, 0, [total_sales#44 ASC NULLS FIRST], [i_item_id#38, total_sales#44]
 
 (62) CometColumnarToRow [codegen id : 1]
 Input [2]: [i_item_id#38, total_sales#44]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q58/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q58/explain.txt
index f2fa5fe42..f2e395e65 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q58/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q58/explain.txt
@@ -312,7 +312,7 @@ Arguments: [item_id#12, ss_item_rev#13, ss_dev#35, cs_item_rev#24, cs_dev#36, ws
 
 (56) CometTakeOrderedAndProject
 Input [8]: [item_id#12, ss_item_rev#13, ss_dev#35, cs_item_rev#24, cs_dev#36, ws_item_rev#34, ws_dev#37, average#38]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[item_id#12 ASC NULLS FIRST,ss_item_rev#13 ASC NULLS FIRST], output=[item_id#12,ss_item_rev#13,ss_dev#35,cs_item_rev#24,cs_dev#36,ws_item_rev#34,ws_dev#37,average#38]), [item_id#12, ss_item_rev#13, ss_dev#35, cs_item_rev#24, cs_dev#36, ws_item_rev#34, ws_dev#37, average#38], 100, [item_id#12 ASC NULLS FIRST, ss_item_rev#13 ASC NULLS FIRST], [item_id#12, ss_item_rev#13, ss_dev#35, cs_item_rev#24, cs_dev#36, ws_item_rev#34, ws_dev#37, ave [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[item_id#12 ASC NULLS FIRST,ss_item_rev#13 ASC NULLS FIRST], output=[item_id#12,ss_item_rev#13,ss_dev#35,cs_item_rev#24,cs_dev#36,ws_item_rev#34,ws_dev#37,average#38]), [item_id#12, ss_item_rev#13, ss_dev#35, cs_item_rev#24, cs_dev#36, ws_item_rev#34, ws_dev#37, average#38], 100, 0, [item_id#12 ASC NULLS FIRST, ss_item_rev#13 ASC NULLS FIRST], [item_id#12, ss_item_rev#13, ss_dev#35, cs_item_rev#24, cs_dev#36, ws_item_rev#34, ws_dev#37,  [...]
 
 (57) CometColumnarToRow [codegen id : 1]
 Input [8]: [item_id#12, ss_item_rev#13, ss_dev#35, cs_item_rev#24, cs_dev#36, ws_item_rev#34, ws_dev#37, average#38]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q59/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q59/explain.txt
index b302160f0..0531ee4e9 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q59/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q59/explain.txt
@@ -232,7 +232,7 @@ Arguments: [s_store_name1#28, s_store_id1#30, d_week_seq1#29, (sun_sales1 / sun_
 
 (41) CometTakeOrderedAndProject
 Input [10]: [s_store_name1#28, s_store_id1#30, d_week_seq1#29, (sun_sales1 / sun_sales2)#59, (mon_sales1 / mon_sales2)#60, (tue_sales1 / tue_sales2)#61, (wed_sales1 / wed_sales2)#62, (thu_sales1 / thu_sales2)#63, (fri_sales1 / fri_sales2)#64, (sat_sales1 / sat_sales2)#65]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name1#28 ASC NULLS FIRST,s_store_id1#30 ASC NULLS FIRST,d_week_seq1#29 ASC NULLS FIRST], output=[s_store_name1#28,s_store_id1#30,d_week_seq1#29,(sun_sales1 / sun_sales2)#59,(mon_sales1 / mon_sales2)#60,(tue_sales1 / tue_sales2)#61,(wed_sales1 / wed_sales2)#62,(thu_sales1 / thu_sales2)#63,(fri_sales1 / fri_sales2)#64,(sat_sales1 / sat_sales2)#65]), [s_store_name1#28, s_store_id1#30, d_week_seq1#29, (sun_sales1 / sun_sales2)#59,  [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name1#28 ASC NULLS FIRST,s_store_id1#30 ASC NULLS FIRST,d_week_seq1#29 ASC NULLS FIRST], output=[s_store_name1#28,s_store_id1#30,d_week_seq1#29,(sun_sales1 / sun_sales2)#59,(mon_sales1 / mon_sales2)#60,(tue_sales1 / tue_sales2)#61,(wed_sales1 / wed_sales2)#62,(thu_sales1 / thu_sales2)#63,(fri_sales1 / fri_sales2)#64,(sat_sales1 / sat_sales2)#65]), [s_store_name1#28, s_store_id1#30, d_week_seq1#29, (sun_sales1 / sun_sales2)#59,  [...]
 
 (42) CometColumnarToRow [codegen id : 1]
 Input [10]: [s_store_name1#28, s_store_id1#30, d_week_seq1#29, (sun_sales1 / sun_sales2)#59, (mon_sales1 / mon_sales2)#60, (tue_sales1 / tue_sales2)#61, (wed_sales1 / wed_sales2)#62, (thu_sales1 / thu_sales2)#63, (fri_sales1 / fri_sales2)#64, (sat_sales1 / sat_sales2)#65]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q6/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q6/explain.txt
index fb16c6732..8dcf4d565 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q6/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q6/explain.txt
@@ -222,7 +222,7 @@ Condition : (cnt#23 >= 10)
 
 (39) CometTakeOrderedAndProject
 Input [2]: [state#22, cnt#23]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[cnt#23 ASC NULLS FIRST], output=[state#22,cnt#23]), [state#22, cnt#23], 100, [cnt#23 ASC NULLS FIRST], [state#22, cnt#23]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[cnt#23 ASC NULLS FIRST], output=[state#22,cnt#23]), [state#22, cnt#23], 100, 0, [cnt#23 ASC NULLS FIRST], [state#22, cnt#23]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [2]: [state#22, cnt#23]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q60/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q60/explain.txt
index aa8dce50c..d74ac5224 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q60/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q60/explain.txt
@@ -341,7 +341,7 @@ Functions [1]: [sum(total_sales#39)]
 
 (61) CometTakeOrderedAndProject
 Input [2]: [i_item_id#38, total_sales#44]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#38 ASC NULLS FIRST,total_sales#44 ASC NULLS FIRST], output=[i_item_id#38,total_sales#44]), [i_item_id#38, total_sales#44], 100, [i_item_id#38 ASC NULLS FIRST, total_sales#44 ASC NULLS FIRST], [i_item_id#38, total_sales#44]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#38 ASC NULLS FIRST,total_sales#44 ASC NULLS FIRST], output=[i_item_id#38,total_sales#44]), [i_item_id#38, total_sales#44], 100, 0, [i_item_id#38 ASC NULLS FIRST, total_sales#44 ASC NULLS FIRST], [i_item_id#38, total_sales#44]
 
 (62) CometColumnarToRow [codegen id : 1]
 Input [2]: [i_item_id#38, total_sales#44]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q62/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q62/explain.txt
index c317d6b24..102de64aa 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q62/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q62/explain.txt
@@ -161,7 +161,7 @@ Functions [5]: [sum(CASE WHEN ((ws_ship_date_sk#1 - ws_sold_date_sk#5) <= 30) TH
 
 (28) CometTakeOrderedAndProject
 Input [8]: [substr(w_warehouse_name, 1, 20)#21, sm_type#10, web_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(w_warehouse_name, 1, 20)#21 ASC NULLS FIRST,sm_type#10 ASC NULLS FIRST,web_name#12 ASC NULLS FIRST], output=[substr(w_warehouse_name, 1, 20)#21,sm_type#10,web_name#12,30 days #22,31 - 60 days #23,61 - 90 days #24,91 - 120 days #25,>120 days #26]), [substr(w_warehouse_name, 1, 20)#21, sm_type#10, web_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26], 100, [substr(w_warehouse_name, 1, 20)# [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(w_warehouse_name, 1, 20)#21 ASC NULLS FIRST,sm_type#10 ASC NULLS FIRST,web_name#12 ASC NULLS FIRST], output=[substr(w_warehouse_name, 1, 20)#21,sm_type#10,web_name#12,30 days #22,31 - 60 days #23,61 - 90 days #24,91 - 120 days #25,>120 days #26]), [substr(w_warehouse_name, 1, 20)#21, sm_type#10, web_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26], 100, 0, [substr(w_warehouse_name, 1, 2 [...]
 
 (29) CometColumnarToRow [codegen id : 1]
 Input [8]: [substr(w_warehouse_name, 1, 20)#21, sm_type#10, web_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q65/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q65/explain.txt
index f12e2604d..4cad0df46 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q65/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q65/explain.txt
@@ -222,7 +222,7 @@ Arguments: [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wh
 
 (39) CometTakeOrderedAndProject
 Input [6]: [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#2 ASC NULLS FIRST,i_item_desc#13 ASC NULLS FIRST], output=[s_store_name#2,i_item_desc#13,revenue#11,i_current_price#14,i_wholesale_cost#15,i_brand#17]), [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17], 100, [s_store_name#2 ASC NULLS FIRST, i_item_desc#13 ASC NULLS FIRST], [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#2 ASC NULLS FIRST,i_item_desc#13 ASC NULLS FIRST], output=[s_store_name#2,i_item_desc#13,revenue#11,i_current_price#14,i_wholesale_cost#15,i_brand#17]), [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17], 100, 0, [s_store_name#2 ASC NULLS FIRST, i_item_desc#13 ASC NULLS FIRST], [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [6]: [s_store_name#2, i_item_desc#13, revenue#11, i_current_price#14, i_wholesale_cost#15, i_brand#17]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q66/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q66/explain.txt
index 1ed8aa1c8..036484391 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q66/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q66/explain.txt
@@ -280,7 +280,7 @@ Functions [36]: [sum(jan_sales#142), sum(feb_sales#143), sum(mar_sales#144), sum
 
 (50) CometTakeOrderedAndProject
 Input [44]: [w_warehouse_name#10, w_warehouse_sq_ft#11, w_city#12, w_county#13, w_state#16, w_country#15, ship_carriers#140, year#141, jan_sales#264, feb_sales#265, mar_sales#266, apr_sales#267, may_sales#268, jun_sales#269, jul_sales#270, aug_sales#271, sep_sales#272, oct_sales#273, nov_sales#274, dec_sales#275, jan_sales_per_sq_foot#276, feb_sales_per_sq_foot#277, mar_sales_per_sq_foot#278, apr_sales_per_sq_foot#279, may_sales_per_sq_foot#280, jun_sales_per_sq_foot#281, jul_sales_per_s [...]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_warehouse_name#10 ASC NULLS FIRST], output=[w_warehouse_name#10,w_warehouse_sq_ft#11,w_city#12,w_county#13,w_state#16,w_country#15,ship_carriers#140,year#141,jan_sales#264,feb_sales#265,mar_sales#266,apr_sales#267,may_sales#268,jun_sales#269,jul_sales#270,aug_sales#271,sep_sales#272,oct_sales#273,nov_sales#274,dec_sales#275,jan_sales_per_sq_foot#276,feb_sales_per_sq_foot#277,mar_sales_per_sq_foot#278,apr_sales_per_sq_foot#279,may_sal [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[w_warehouse_name#10 ASC NULLS FIRST], output=[w_warehouse_name#10,w_warehouse_sq_ft#11,w_city#12,w_county#13,w_state#16,w_country#15,ship_carriers#140,year#141,jan_sales#264,feb_sales#265,mar_sales#266,apr_sales#267,may_sales#268,jun_sales#269,jul_sales#270,aug_sales#271,sep_sales#272,oct_sales#273,nov_sales#274,dec_sales#275,jan_sales_per_sq_foot#276,feb_sales_per_sq_foot#277,mar_sales_per_sq_foot#278,apr_sales_per_sq_foot#279,may_sal [...]
 
 (51) CometColumnarToRow [codegen id : 1]
 Input [44]: [w_warehouse_name#10, w_warehouse_sq_ft#11, w_city#12, w_county#13, w_state#16, w_country#15, ship_carriers#140, year#141, jan_sales#264, feb_sales#265, mar_sales#266, apr_sales#267, may_sales#268, jun_sales#269, jul_sales#270, aug_sales#271, sep_sales#272, oct_sales#273, nov_sales#274, dec_sales#275, jan_sales_per_sq_foot#276, feb_sales_per_sq_foot#277, mar_sales_per_sq_foot#278, apr_sales_per_sq_foot#279, may_sales_per_sq_foot#280, jun_sales_per_sq_foot#281, jul_sales_per_s [...]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q68/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q68/explain.txt
index 63198dc37..b1044659e 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q68/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q68/explain.txt
@@ -216,7 +216,7 @@ Arguments: [c_last_name#29, c_first_name#28, ca_city#35, bought_city#30, ss_tick
 
 (38) CometTakeOrderedAndProject
 Input [8]: [c_last_name#29, c_first_name#28, ca_city#35, bought_city#30, ss_ticket_number#5, extended_price#31, extended_tax#33, list_price#32]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#29 ASC NULLS FIRST,ss_ticket_number#5 ASC NULLS FIRST], output=[c_last_name#29,c_first_name#28,ca_city#35,bought_city#30,ss_ticket_number#5,extended_price#31,extended_tax#33,list_price#32]), [c_last_name#29, c_first_name#28, ca_city#35, bought_city#30, ss_ticket_number#5, extended_price#31, extended_tax#33, list_price#32], 100, [c_last_name#29 ASC NULLS FIRST, ss_ticket_number#5 ASC NULLS FIRST], [c_last_name#29, c_first_na [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#29 ASC NULLS FIRST,ss_ticket_number#5 ASC NULLS FIRST], output=[c_last_name#29,c_first_name#28,ca_city#35,bought_city#30,ss_ticket_number#5,extended_price#31,extended_tax#33,list_price#32]), [c_last_name#29, c_first_name#28, ca_city#35, bought_city#30, ss_ticket_number#5, extended_price#31, extended_tax#33, list_price#32], 100, 0, [c_last_name#29 ASC NULLS FIRST, ss_ticket_number#5 ASC NULLS FIRST], [c_last_name#29, c_first [...]
 
 (39) CometColumnarToRow [codegen id : 1]
 Input [8]: [c_last_name#29, c_first_name#28, ca_city#35, bought_city#30, ss_ticket_number#5, extended_price#31, extended_tax#33, list_price#32]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q7/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q7/explain.txt
index edab63c11..e82907b63 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q7/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q7/explain.txt
@@ -172,7 +172,7 @@ Functions [4]: [avg(ss_quantity#4), avg(UnscaledValue(ss_list_price#5)), avg(Uns
 
 (30) CometTakeOrderedAndProject
 Input [5]: [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#18 ASC NULLS FIRST], output=[i_item_id#18,agg1#30,agg2#31,agg3#32,agg4#33]), [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33], 100, [i_item_id#18 ASC NULLS FIRST], [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#18 ASC NULLS FIRST], output=[i_item_id#18,agg1#30,agg2#31,agg3#32,agg4#33]), [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33], 100, 0, [i_item_id#18 ASC NULLS FIRST], [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
 
 (31) CometColumnarToRow [codegen id : 1]
 Input [5]: [i_item_id#18, agg1#30, agg2#31, agg3#32, agg4#33]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q72/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q72/explain.txt
index 1aa31ec60..d7f9c7921 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q72/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q72/explain.txt
@@ -362,7 +362,7 @@ Functions [1]: [count(1)]
 
 (63) CometTakeOrderedAndProject
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC NUL [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, 0, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC  [...]
 
 (64) CometColumnarToRow [codegen id : 1]
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q74/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q74/explain.txt
index 15826f3da..f48543205 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q74/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q74/explain.txt
@@ -406,7 +406,7 @@ Arguments: [customer_id#28, customer_first_name#29, customer_last_name#30], [cus
 
 (71) CometTakeOrderedAndProject
 Input [3]: [customer_id#28, customer_first_name#29, customer_last_name#30]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#28 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST], output=[customer_id#28,customer_first_name#29,customer_last_name#30]), [customer_id#28, customer_first_name#29, customer_last_name#30], 100, [customer_id#28 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST], [customer_id#28, customer_first_name#29, customer_last_name#30]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#28 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST], output=[customer_id#28,customer_first_name#29,customer_last_name#30]), [customer_id#28, customer_first_name#29, customer_last_name#30], 100, 0, [customer_id#28 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST], [customer_id#28, customer_first_name#29, customer_last_name#30]
 
 (72) CometColumnarToRow [codegen id : 1]
 Input [3]: [customer_id#28, customer_first_name#29, customer_last_name#30]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q75/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q75/explain.txt
index cecd130fd..cfdda944d 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q75/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q75/explain.txt
@@ -674,7 +674,7 @@ Arguments: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#1
 
 (123) CometTakeOrderedAndProject
 Input [10]: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#124 ASC NULLS FIRST], output=[prev_year#120,year#121,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#122,curr_yr_cnt#123,sales_cnt_diff#124,sales_amt_diff#125]), [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125], 100, [sales_cnt_diff#124 ASC NULLS FIRST], [prev_year#120, year#121, i_br [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#124 ASC NULLS FIRST], output=[prev_year#120,year#121,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#122,curr_yr_cnt#123,sales_cnt_diff#124,sales_amt_diff#125]), [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125], 100, 0, [sales_cnt_diff#124 ASC NULLS FIRST], [prev_year#120, year#121, i [...]
 
 (124) CometColumnarToRow [codegen id : 1]
 Input [10]: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q76/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q76/explain.txt
index 64b75ea0d..3083e79d2 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q76/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q76/explain.txt
@@ -193,7 +193,7 @@ Functions [2]: [count(1), sum(UnscaledValue(ext_sales_price#13))]
 
 (34) CometTakeOrderedAndProject
 Input [7]: [channel#11, col_name#12, d_year#9, d_qoy#10, i_category#7, sales_cnt#40, sales_amt#41]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#11 ASC NULLS FIRST,col_name#12 ASC NULLS FIRST,d_year#9 ASC NULLS FIRST,d_qoy#10 ASC NULLS FIRST,i_category#7 ASC NULLS FIRST], output=[channel#11,col_name#12,d_year#9,d_qoy#10,i_category#7,sales_cnt#40,sales_amt#41]), [channel#11, col_name#12, d_year#9, d_qoy#10, i_category#7, sales_cnt#40, sales_amt#41], 100, [channel#11 ASC NULLS FIRST, col_name#12 ASC NULLS FIRST, d_year#9 ASC NULLS FIRST, d_qoy#10 ASC NULLS FIRST, i_catego [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#11 ASC NULLS FIRST,col_name#12 ASC NULLS FIRST,d_year#9 ASC NULLS FIRST,d_qoy#10 ASC NULLS FIRST,i_category#7 ASC NULLS FIRST], output=[channel#11,col_name#12,d_year#9,d_qoy#10,i_category#7,sales_cnt#40,sales_amt#41]), [channel#11, col_name#12, d_year#9, d_qoy#10, i_category#7, sales_cnt#40, sales_amt#41], 100, 0, [channel#11 ASC NULLS FIRST, col_name#12 ASC NULLS FIRST, d_year#9 ASC NULLS FIRST, d_qoy#10 ASC NULLS FIRST, i_cat [...]
 
 (35) CometColumnarToRow [codegen id : 1]
 Input [7]: [channel#11, col_name#12, d_year#9, d_qoy#10, i_category#7, sales_cnt#40, sales_amt#41]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q79/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q79/explain.txt
index 1f026356f..e7b144406 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q79/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q79/explain.txt
@@ -172,7 +172,7 @@ Arguments: [c_last_name#25, c_first_name#24, substr(s_city, 1, 30)#28, ss_ticket
 
 (30) CometTakeOrderedAndProject
 Input [7]: [c_last_name#25, c_first_name#24, substr(s_city, 1, 30)#28, ss_ticket_number#5, amt#26, profit#27, s_city#15]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#25 ASC NULLS FIRST,c_first_name#24 ASC NULLS FIRST,substr(s_city#15, 1, 30) ASC NULLS FIRST,profit#27 ASC NULLS FIRST], output=[c_last_name#25,c_first_name#24,substr(s_city, 1, 30)#28,ss_ticket_number#5,amt#26,profit#27]), [c_last_name#25, c_first_name#24, substr(s_city, 1, 30)#28, ss_ticket_number#5, amt#26, profit#27], 100, [c_last_name#25 ASC NULLS FIRST, c_first_name#24 ASC NULLS FIRST, substr(s_city#15, 1, 30) ASC NULL [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_last_name#25 ASC NULLS FIRST,c_first_name#24 ASC NULLS FIRST,substr(s_city#15, 1, 30) ASC NULLS FIRST,profit#27 ASC NULLS FIRST], output=[c_last_name#25,c_first_name#24,substr(s_city, 1, 30)#28,ss_ticket_number#5,amt#26,profit#27]), [c_last_name#25, c_first_name#24, substr(s_city, 1, 30)#28, ss_ticket_number#5, amt#26, profit#27], 100, 0, [c_last_name#25 ASC NULLS FIRST, c_first_name#24 ASC NULLS FIRST, substr(s_city#15, 1, 30) ASC N [...]
 
 (31) CometColumnarToRow [codegen id : 1]
 Input [6]: [c_last_name#25, c_first_name#24, substr(s_city, 1, 30)#28, ss_ticket_number#5, amt#26, profit#27]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q8/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q8/explain.txt
index cc47e512f..eee3c4c57 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q8/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q8/explain.txt
@@ -244,7 +244,7 @@ Functions [1]: [sum(UnscaledValue(ss_net_profit#2))]
 
 (43) CometTakeOrderedAndProject
 Input [2]: [s_store_name#9, sum(ss_net_profit)#23]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#9 ASC NULLS FIRST], output=[s_store_name#9,sum(ss_net_profit)#23]), [s_store_name#9, sum(ss_net_profit)#23], 100, [s_store_name#9 ASC NULLS FIRST], [s_store_name#9, sum(ss_net_profit)#23]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[s_store_name#9 ASC NULLS FIRST], output=[s_store_name#9,sum(ss_net_profit)#23]), [s_store_name#9, sum(ss_net_profit)#23], 100, 0, [s_store_name#9 ASC NULLS FIRST], [s_store_name#9, sum(ss_net_profit)#23]
 
 (44) CometColumnarToRow [codegen id : 1]
 Input [2]: [s_store_name#9, sum(ss_net_profit)#23]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q81/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q81/explain.txt
index 82b9bd626..bd5999598 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q81/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q81/explain.txt
@@ -276,7 +276,7 @@ Arguments: [c_customer_id#27, c_salutation#28, c_first_name#29, c_last_name#30,
 
 (49) CometTakeOrderedAndProject
 Input [16]: [c_customer_id#27, c_salutation#28, c_first_name#29, c_last_name#30, ca_street_number#43, ca_street_name#33, ca_street_type#44, ca_suite_number#45, ca_city#36, ca_county#37, ca_state#46, ca_zip#47, ca_country#40, ca_gmt_offset#41, ca_location_type#48, ctr_total_return#14]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#27 ASC NULLS FIRST,c_salutation#28 ASC NULLS FIRST,c_first_name#29 ASC NULLS FIRST,c_last_name#30 ASC NULLS FIRST,ca_street_number#43 ASC NULLS FIRST,ca_street_name#33 ASC NULLS FIRST,ca_street_type#44 ASC NULLS FIRST,ca_suite_number#45 ASC NULLS FIRST,ca_city#36 ASC NULLS FIRST,ca_county#37 ASC NULLS FIRST,ca_state#46 ASC NULLS FIRST,ca_zip#47 ASC NULLS FIRST,ca_country#40 ASC NULLS FIRST,ca_gmt_offset#41 ASC NULLS FIRST [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[c_customer_id#27 ASC NULLS FIRST,c_salutation#28 ASC NULLS FIRST,c_first_name#29 ASC NULLS FIRST,c_last_name#30 ASC NULLS FIRST,ca_street_number#43 ASC NULLS FIRST,ca_street_name#33 ASC NULLS FIRST,ca_street_type#44 ASC NULLS FIRST,ca_suite_number#45 ASC NULLS FIRST,ca_city#36 ASC NULLS FIRST,ca_county#37 ASC NULLS FIRST,ca_state#46 ASC NULLS FIRST,ca_zip#47 ASC NULLS FIRST,ca_country#40 ASC NULLS FIRST,ca_gmt_offset#41 ASC NULLS FIRST [...]
 
 (50) CometColumnarToRow [codegen id : 1]
 Input [16]: [c_customer_id#27, c_salutation#28, c_first_name#29, c_last_name#30, ca_street_number#43, ca_street_name#33, ca_street_type#44, ca_suite_number#45, ca_city#36, ca_county#37, ca_state#46, ca_zip#47, ca_country#40, ca_gmt_offset#41, ca_location_type#48, ctr_total_return#14]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q82/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q82/explain.txt
index 6b35c3253..7e7acf323 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q82/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q82/explain.txt
@@ -143,7 +143,7 @@ Functions: []
 
 (25) CometTakeOrderedAndProject
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#6 ASC NULLS FIRST], output=[i_item_id#6,i_item_desc#3,i_current_price#4]), [i_item_id#6, i_item_desc#3, i_current_price#4], 100, 0, [i_item_id#6 ASC NULLS FIRST], [i_item_id#6, i_item_desc#3, i_current_price#4]
 
 (26) CometColumnarToRow [codegen id : 1]
 Input [3]: [i_item_id#6, i_item_desc#3, i_current_price#4]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q83/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q83/explain.txt
index 0278cbf87..6814b2115 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q83/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q83/explain.txt
@@ -297,7 +297,7 @@ Arguments: [item_id#23, sr_item_qty#24, sr_dev#35, cr_item_qty#22, cr_dev#36, wr
 
 (53) CometTakeOrderedAndProject
 Input [8]: [item_id#23, sr_item_qty#24, sr_dev#35, cr_item_qty#22, cr_dev#36, wr_item_qty#34, wr_dev#37, average#38]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[item_id#23 ASC NULLS FIRST,sr_item_qty#24 ASC NULLS FIRST], output=[item_id#23,sr_item_qty#24,sr_dev#35,cr_item_qty#22,cr_dev#36,wr_item_qty#34,wr_dev#37,average#38]), [item_id#23, sr_item_qty#24, sr_dev#35, cr_item_qty#22, cr_dev#36, wr_item_qty#34, wr_dev#37, average#38], 100, [item_id#23 ASC NULLS FIRST, sr_item_qty#24 ASC NULLS FIRST], [item_id#23, sr_item_qty#24, sr_dev#35, cr_item_qty#22, cr_dev#36, wr_item_qty#34, wr_dev#37, ave [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[item_id#23 ASC NULLS FIRST,sr_item_qty#24 ASC NULLS FIRST], output=[item_id#23,sr_item_qty#24,sr_dev#35,cr_item_qty#22,cr_dev#36,wr_item_qty#34,wr_dev#37,average#38]), [item_id#23, sr_item_qty#24, sr_dev#35, cr_item_qty#22, cr_dev#36, wr_item_qty#34, wr_dev#37, average#38], 100, 0, [item_id#23 ASC NULLS FIRST, sr_item_qty#24 ASC NULLS FIRST], [item_id#23, sr_item_qty#24, sr_dev#35, cr_item_qty#22, cr_dev#36, wr_item_qty#34, wr_dev#37,  [...]
 
 (54) CometColumnarToRow [codegen id : 1]
 Input [8]: [item_id#23, sr_item_qty#24, sr_dev#35, cr_item_qty#22, cr_dev#36, wr_item_qty#34, wr_dev#37, average#38]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q85/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q85/explain.txt
index a6ec6332a..5a3f67946 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q85/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q85/explain.txt
@@ -269,7 +269,7 @@ Functions [3]: [avg(ws_quantity#4), avg(UnscaledValue(wr_refunded_cash#16)), avg
 
 (47) CometTakeOrderedAndProject
 Input [4]: [substr(r_reason_desc, 1, 20)#44, avg(ws_quantity)#45, avg(wr_refunded_cash)#46, avg(wr_fee)#47]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(r_reason_desc, 1, 20)#44 ASC NULLS FIRST,avg(ws_quantity)#45 ASC NULLS FIRST,avg(wr_refunded_cash)#46 ASC NULLS FIRST,avg(wr_fee)#47 ASC NULLS FIRST], output=[substr(r_reason_desc, 1, 20)#44,avg(ws_quantity)#45,avg(wr_refunded_cash)#46,avg(wr_fee)#47]), [substr(r_reason_desc, 1, 20)#44, avg(ws_quantity)#45, avg(wr_refunded_cash)#46, avg(wr_fee)#47], 100, [substr(r_reason_desc, 1, 20)#44 ASC NULLS FIRST, avg(ws_quantity)#45 ASC N [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(r_reason_desc, 1, 20)#44 ASC NULLS FIRST,avg(ws_quantity)#45 ASC NULLS FIRST,avg(wr_refunded_cash)#46 ASC NULLS FIRST,avg(wr_fee)#47 ASC NULLS FIRST], output=[substr(r_reason_desc, 1, 20)#44,avg(ws_quantity)#45,avg(wr_refunded_cash)#46,avg(wr_fee)#47]), [substr(r_reason_desc, 1, 20)#44, avg(ws_quantity)#45, avg(wr_refunded_cash)#46, avg(wr_fee)#47], 100, 0, [substr(r_reason_desc, 1, 20)#44 ASC NULLS FIRST, avg(ws_quantity)#45 AS [...]
 
 (48) CometColumnarToRow [codegen id : 1]
 Input [4]: [substr(r_reason_desc, 1, 20)#44, avg(ws_quantity)#45, avg(wr_refunded_cash)#46, avg(wr_fee)#47]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q93/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q93/explain.txt
index 7498a020a..4577461e1 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q93/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q93/explain.txt
@@ -117,7 +117,7 @@ Functions [1]: [sum(act_sales#14)]
 
 (21) CometTakeOrderedAndProject
 Input [2]: [ss_customer_sk#2, sumsales#17]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[sumsales#17 ASC NULLS FIRST,ss_customer_sk#2 ASC NULLS FIRST], output=[ss_customer_sk#2,sumsales#17]), [ss_customer_sk#2, sumsales#17], 100, [sumsales#17 ASC NULLS FIRST, ss_customer_sk#2 ASC NULLS FIRST], [ss_customer_sk#2, sumsales#17]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[sumsales#17 ASC NULLS FIRST,ss_customer_sk#2 ASC NULLS FIRST], output=[ss_customer_sk#2,sumsales#17]), [ss_customer_sk#2, sumsales#17], 100, 0, [sumsales#17 ASC NULLS FIRST, ss_customer_sk#2 ASC NULLS FIRST], [ss_customer_sk#2, sumsales#17]
 
 (22) CometColumnarToRow [codegen id : 1]
 Input [2]: [ss_customer_sk#2, sumsales#17]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q99/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q99/explain.txt
index e96362854..42b007b23 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q99/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q99/explain.txt
@@ -161,7 +161,7 @@ Functions [5]: [sum(CASE WHEN ((cs_ship_date_sk#1 - cs_sold_date_sk#5) <= 30) TH
 
 (28) CometTakeOrderedAndProject
 Input [8]: [substr(w_warehouse_name, 1, 20)#21, sm_type#10, cc_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(w_warehouse_name, 1, 20)#21 ASC NULLS FIRST,sm_type#10 ASC NULLS FIRST,cc_name#12 ASC NULLS FIRST], output=[substr(w_warehouse_name, 1, 20)#21,sm_type#10,cc_name#12,30 days #22,31 - 60 days #23,61 - 90 days #24,91 - 120 days #25,>120 days #26]), [substr(w_warehouse_name, 1, 20)#21, sm_type#10, cc_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26], 100, [substr(w_warehouse_name, 1, 20)#21  [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[substr(w_warehouse_name, 1, 20)#21 ASC NULLS FIRST,sm_type#10 ASC NULLS FIRST,cc_name#12 ASC NULLS FIRST], output=[substr(w_warehouse_name, 1, 20)#21,sm_type#10,cc_name#12,30 days #22,31 - 60 days #23,61 - 90 days #24,91 - 120 days #25,>120 days #26]), [substr(w_warehouse_name, 1, 20)#21, sm_type#10, cc_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26], 100, 0, [substr(w_warehouse_name, 1, 20)# [...]
 
 (29) CometColumnarToRow [codegen id : 1]
 Input [8]: [substr(w_warehouse_name, 1, 20)#21, sm_type#10, cc_name#12, 30 days #22, 31 - 60 days #23, 61 - 90 days #24, 91 - 120 days #25, >120 days #26]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q10a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q10a/explain.txt
index c39332672..4e31bd998 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q10a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q10a/explain.txt
@@ -223,7 +223,7 @@ Functions [1]: [count(1)]
 
 (39) CometTakeOrderedAndProject
 Input [14]: [cd_gender#31, cd_marital_status#32, cd_education_status#33, cnt1#36, cd_purchase_estimate#26, cnt2#37, cd_credit_rating#34, cnt3#38, cd_dep_count#28, cnt4#39, cd_dep_employed_count#29, cnt5#40, cd_dep_college_count#30, cnt6#41]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[cd_gender#31 ASC NULLS FIRST,cd_marital_status#32 ASC NULLS FIRST,cd_education_status#33 ASC NULLS FIRST,cd_purchase_estimate#26 ASC NULLS FIRST,cd_credit_rating#34 ASC NULLS FIRST,cd_dep_count#28 ASC NULLS FIRST,cd_dep_employed_count#29 ASC NULLS FIRST,cd_dep_college_count#30 ASC NULLS FIRST], output=[cd_gender#31,cd_marital_status#32,cd_education_status#33,cnt1#36,cd_purchase_estimate#26,cnt2#37,cd_credit_rating#34,cnt3#38,cd_dep_cou [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[cd_gender#31 ASC NULLS FIRST,cd_marital_status#32 ASC NULLS FIRST,cd_education_status#33 ASC NULLS FIRST,cd_purchase_estimate#26 ASC NULLS FIRST,cd_credit_rating#34 ASC NULLS FIRST,cd_dep_count#28 ASC NULLS FIRST,cd_dep_employed_count#29 ASC NULLS FIRST,cd_dep_college_count#30 ASC NULLS FIRST], output=[cd_gender#31,cd_marital_status#32,cd_education_status#33,cnt1#36,cd_purchase_estimate#26,cnt2#37,cd_credit_rating#34,cnt3#38,cd_dep_cou [...]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [14]: [cd_gender#31, cd_marital_status#32, cd_education_status#33, cnt1#36, cd_purchase_estimate#26, cnt2#37, cd_credit_rating#34, cnt3#38, cd_dep_count#28, cnt4#39, cd_dep_employed_count#29, cnt5#40, cd_dep_college_count#30, cnt6#41]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q11/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q11/explain.txt
index 90ffbe79d..acf432228 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q11/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q11/explain.txt
@@ -406,7 +406,7 @@ Arguments: [customer_id#41, customer_first_name#42, customer_last_name#43, custo
 
 (71) CometTakeOrderedAndProject
 Input [4]: [customer_id#41, customer_first_name#42, customer_last_name#43, customer_email_address#44]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#41 ASC NULLS FIRST,customer_first_name#42 ASC NULLS FIRST,customer_last_name#43 ASC NULLS FIRST,customer_email_address#44 ASC NULLS FIRST], output=[customer_id#41,customer_first_name#42,customer_last_name#43,customer_email_address#44]), [customer_id#41, customer_first_name#42, customer_last_name#43, customer_email_address#44], 100, [customer_id#41 ASC NULLS FIRST, customer_first_name#42 ASC NULLS FIRST, customer_last_name#4 [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#41 ASC NULLS FIRST,customer_first_name#42 ASC NULLS FIRST,customer_last_name#43 ASC NULLS FIRST,customer_email_address#44 ASC NULLS FIRST], output=[customer_id#41,customer_first_name#42,customer_last_name#43,customer_email_address#44]), [customer_id#41, customer_first_name#42, customer_last_name#43, customer_email_address#44], 100, 0, [customer_id#41 ASC NULLS FIRST, customer_first_name#42 ASC NULLS FIRST, customer_last_nam [...]
 
 (72) CometColumnarToRow [codegen id : 1]
 Input [4]: [customer_id#41, customer_first_name#42, customer_last_name#43, customer_email_address#44]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q14/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q14/explain.txt
index a315b8565..12f35041a 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q14/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q14/explain.txt
@@ -478,7 +478,7 @@ Arguments: [i_brand_id#40, i_class_id#41, i_category_id#42], [i_brand_id#62, i_c
 
 (84) CometTakeOrderedAndProject
 Input [12]: [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#72, i_brand_id#62, i_class_id#63, i_category_id#64, sales#73, number_sales#74]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#50,i_brand_id#40,i_class_id#41,i_category_id#42,sales#51,number_sales#52,channel#72,i_brand_id#62,i_class_id#63,i_category_id#64,sales#73,number_sales#74]), [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#72, i_brand_id#62, i_class_id#63, i_category_id#64, sales#73, number_sales# [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#50,i_brand_id#40,i_class_id#41,i_category_id#42,sales#51,number_sales#52,channel#72,i_brand_id#62,i_class_id#63,i_category_id#64,sales#73,number_sales#74]), [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#72, i_brand_id#62, i_class_id#63, i_category_id#64, sales#73, number_sales# [...]
 
 (85) CometColumnarToRow [codegen id : 1]
 Input [12]: [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#72, i_brand_id#62, i_class_id#63, i_category_id#64, sales#73, number_sales#74]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q14a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q14a/explain.txt
index 9dd52b68f..2cb3c7e4c 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q14a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q14a/explain.txt
@@ -680,7 +680,7 @@ Functions: []
 
 (121) CometTakeOrderedAndProject
 Input [6]: [channel#49, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#123, number_sales#124]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#49 ASC NULLS FIRST,i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#49,i_brand_id#40,i_class_id#41,i_category_id#42,sum_sales#123,number_sales#124]), [channel#49, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#123, number_sales#124], 100, [channel#49 ASC NULLS FIRST, i_brand_id#40 ASC NULLS FIRST, i_class_id#41 ASC NULLS FIRST, i_category_id#42 ASC NULLS F [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#49 ASC NULLS FIRST,i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#49,i_brand_id#40,i_class_id#41,i_category_id#42,sum_sales#123,number_sales#124]), [channel#49, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#123, number_sales#124], 100, 0, [channel#49 ASC NULLS FIRST, i_brand_id#40 ASC NULLS FIRST, i_class_id#41 ASC NULLS FIRST, i_category_id#42 ASC NULL [...]
 
 (122) CometColumnarToRow [codegen id : 1]
 Input [6]: [channel#49, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#123, number_sales#124]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q18a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q18a/explain.txt
index 50159ecca..3bfc6b85a 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q18a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q18a/explain.txt
@@ -798,7 +798,7 @@ Child 4 Input [11]: [i_item_id#259, ca_country#260, ca_state#261, county#262, ag
 
 (145) CometTakeOrderedAndProject
 Input [11]: [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#225, agg2#226, agg3#227, agg4#228, agg5#229, agg6#230, agg7#231]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_country#32 ASC NULLS FIRST,ca_state#33 ASC NULLS FIRST,ca_county#34 ASC NULLS FIRST,i_item_id#31 ASC NULLS FIRST], output=[i_item_id#31,ca_country#32,ca_state#33,ca_county#34,agg1#225,agg2#226,agg3#227,agg4#228,agg5#229,agg6#230,agg7#231]), [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#225, agg2#226, agg3#227, agg4#228, agg5#229, agg6#230, agg7#231], 100, [ca_country#32 ASC NULLS FIRST, ca_state#33 ASC NULLS FIRST, c [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_country#32 ASC NULLS FIRST,ca_state#33 ASC NULLS FIRST,ca_county#34 ASC NULLS FIRST,i_item_id#31 ASC NULLS FIRST], output=[i_item_id#31,ca_country#32,ca_state#33,ca_county#34,agg1#225,agg2#226,agg3#227,agg4#228,agg5#229,agg6#230,agg7#231]), [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#225, agg2#226, agg3#227, agg4#228, agg5#229, agg6#230, agg7#231], 100, 0, [ca_country#32 ASC NULLS FIRST, ca_state#33 ASC NULLS FIRST [...]
 
 (146) CometColumnarToRow [codegen id : 1]
 Input [11]: [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#225, agg2#226, agg3#227, agg4#228, agg5#229, agg6#230, agg7#231]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q22a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q22a/explain.txt
index 42c50df84..4ca3e201e 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q22a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q22a/explain.txt
@@ -261,7 +261,7 @@ Child 4 Input [5]: [i_product_name#61, i_brand#62, i_class#63, i_category#64, qo
 
 (46) CometTakeOrderedAndProject
 Input [5]: [i_product_name#20, i_brand#21, i_class#22, i_category#23, qoh#51]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[qoh#51 ASC NULLS FIRST,i_product_name#20 ASC NULLS FIRST,i_brand#21 ASC NULLS FIRST,i_class#22 ASC NULLS FIRST,i_category#23 ASC NULLS FIRST], output=[i_product_name#20,i_brand#21,i_class#22,i_category#23,qoh#51]), [i_product_name#20, i_brand#21, i_class#22, i_category#23, qoh#51], 100, [qoh#51 ASC NULLS FIRST, i_product_name#20 ASC NULLS FIRST, i_brand#21 ASC NULLS FIRST, i_class#22 ASC NULLS FIRST, i_category#23 ASC NULLS FIRST], [i_ [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[qoh#51 ASC NULLS FIRST,i_product_name#20 ASC NULLS FIRST,i_brand#21 ASC NULLS FIRST,i_class#22 ASC NULLS FIRST,i_category#23 ASC NULLS FIRST], output=[i_product_name#20,i_brand#21,i_class#22,i_category#23,qoh#51]), [i_product_name#20, i_brand#21, i_class#22, i_category#23, qoh#51], 100, 0, [qoh#51 ASC NULLS FIRST, i_product_name#20 ASC NULLS FIRST, i_brand#21 ASC NULLS FIRST, i_class#22 ASC NULLS FIRST, i_category#23 ASC NULLS FIRST],  [...]
 
 (47) CometColumnarToRow [codegen id : 1]
 Input [5]: [i_product_name#20, i_brand#21, i_class#22, i_category#23, qoh#51]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q27a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q27a/explain.txt
index 5d1e30ad3..cb9deebb3 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q27a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q27a/explain.txt
@@ -393,7 +393,7 @@ Child 2 Input [7]: [i_item_id#98, s_state#99, g_state#100, agg1#101, agg2#102, a
 
 (70) CometTakeOrderedAndProject
 Input [7]: [i_item_id#22, s_state#23, g_state#87, agg1#88, agg2#89, agg3#90, agg4#91]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#22 ASC NULLS FIRST,s_state#23 ASC NULLS FIRST], output=[i_item_id#22,s_state#23,g_state#87,agg1#88,agg2#89,agg3#90,agg4#91]), [i_item_id#22, s_state#23, g_state#87, agg1#88, agg2#89, agg3#90, agg4#91], 100, [i_item_id#22 ASC NULLS FIRST, s_state#23 ASC NULLS FIRST], [i_item_id#22, s_state#23, g_state#87, agg1#88, agg2#89, agg3#90, agg4#91]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#22 ASC NULLS FIRST,s_state#23 ASC NULLS FIRST], output=[i_item_id#22,s_state#23,g_state#87,agg1#88,agg2#89,agg3#90,agg4#91]), [i_item_id#22, s_state#23, g_state#87, agg1#88, agg2#89, agg3#90, agg4#91], 100, 0, [i_item_id#22 ASC NULLS FIRST, s_state#23 ASC NULLS FIRST], [i_item_id#22, s_state#23, g_state#87, agg1#88, agg2#89, agg3#90, agg4#91]
 
 (71) CometColumnarToRow [codegen id : 1]
 Input [7]: [i_item_id#22, s_state#23, g_state#87, agg1#88, agg2#89, agg3#90, agg4#91]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q35a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q35a/explain.txt
index f81ff1afa..908b73c1a 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q35a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q35a/explain.txt
@@ -223,7 +223,7 @@ Functions [10]: [count(1), avg(cd_dep_count#26), max(cd_dep_count#26), sum(cd_de
 
 (39) CometTakeOrderedAndProject
 Input [18]: [ca_state#22, cd_gender#29, cd_marital_status#30, cd_dep_count#26, cnt1#44, avg(cd_dep_count)#45, max(cd_dep_count)#46, sum(cd_dep_count)#47, cd_dep_employed_count#27, cnt2#48, avg(cd_dep_employed_count)#49, max(cd_dep_employed_count)#50, sum(cd_dep_employed_count)#51, cd_dep_college_count#28, cnt3#52, avg(cd_dep_college_count)#53, max(cd_dep_college_count)#54, sum(cd_dep_college_count)#55]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_state#22 ASC NULLS FIRST,cd_gender#29 ASC NULLS FIRST,cd_marital_status#30 ASC NULLS FIRST,cd_dep_count#26 ASC NULLS FIRST,cd_dep_employed_count#27 ASC NULLS FIRST,cd_dep_college_count#28 ASC NULLS FIRST], output=[ca_state#22,cd_gender#29,cd_marital_status#30,cd_dep_count#26,cnt1#44,avg(cd_dep_count)#45,max(cd_dep_count)#46,sum(cd_dep_count)#47,cd_dep_employed_count#27,cnt2#48,avg(cd_dep_employed_count)#49,max(cd_dep_employed_count) [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_state#22 ASC NULLS FIRST,cd_gender#29 ASC NULLS FIRST,cd_marital_status#30 ASC NULLS FIRST,cd_dep_count#26 ASC NULLS FIRST,cd_dep_employed_count#27 ASC NULLS FIRST,cd_dep_college_count#28 ASC NULLS FIRST], output=[ca_state#22,cd_gender#29,cd_marital_status#30,cd_dep_count#26,cnt1#44,avg(cd_dep_count)#45,max(cd_dep_count)#46,sum(cd_dep_count)#47,cd_dep_employed_count#27,cnt2#48,avg(cd_dep_employed_count)#49,max(cd_dep_employed_count) [...]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [18]: [ca_state#22, cd_gender#29, cd_marital_status#30, cd_dep_count#26, cnt1#44, avg(cd_dep_count)#45, max(cd_dep_count)#46, sum(cd_dep_count)#47, cd_dep_employed_count#27, cnt2#48, avg(cd_dep_employed_count)#49, max(cd_dep_employed_count)#50, sum(cd_dep_employed_count)#51, cd_dep_college_count#28, cnt3#52, avg(cd_dep_college_count)#53, max(cd_dep_college_count)#54, sum(cd_dep_college_count)#55]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q49/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q49/explain.txt
index 281d422ff..786c55693 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q49/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q49/explain.txt
@@ -418,7 +418,7 @@ Functions: []
 
 (77) CometTakeOrderedAndProject
 Input [5]: [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#27 ASC NULLS FIRST,return_rank#25 ASC NULLS FIRST,currency_rank#26 ASC NULLS FIRST,item#22 ASC NULLS FIRST], output=[channel#27,item#22,return_ratio#23,return_rank#25,currency_rank#26]), [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26], 100, [channel#27 ASC NULLS FIRST, return_rank#25 ASC NULLS FIRST, currency_rank#26 ASC NULLS FIRST, item#22 ASC NULLS FIRST], [channel#27, item#22, return_ratio#23, retur [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#27 ASC NULLS FIRST,return_rank#25 ASC NULLS FIRST,currency_rank#26 ASC NULLS FIRST,item#22 ASC NULLS FIRST], output=[channel#27,item#22,return_ratio#23,return_rank#25,currency_rank#26]), [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26], 100, 0, [channel#27 ASC NULLS FIRST, return_rank#25 ASC NULLS FIRST, currency_rank#26 ASC NULLS FIRST, item#22 ASC NULLS FIRST], [channel#27, item#22, return_ratio#23, re [...]
 
 (78) CometColumnarToRow [codegen id : 11]
 Input [5]: [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q5a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q5a/explain.txt
index 405cc6062..a16273461 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q5a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q5a/explain.txt
@@ -524,7 +524,7 @@ Functions: []
 
 (91) CometTakeOrderedAndProject
 Input [5]: [channel#35, id#36, sales#136, returns#137, profit#138]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#35 ASC NULLS FIRST,id#36 ASC NULLS FIRST], output=[channel#35,id#36,sales#136,returns#137,profit#138]), [channel#35, id#36, sales#136, returns#137, profit#138], 100, [channel#35 ASC NULLS FIRST, id#36 ASC NULLS FIRST], [channel#35, id#36, sales#136, returns#137, profit#138]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#35 ASC NULLS FIRST,id#36 ASC NULLS FIRST], output=[channel#35,id#36,sales#136,returns#137,profit#138]), [channel#35, id#36, sales#136, returns#137, profit#138], 100, 0, [channel#35 ASC NULLS FIRST, id#36 ASC NULLS FIRST], [channel#35, id#36, sales#136, returns#137, profit#138]
 
 (92) CometColumnarToRow [codegen id : 19]
 Input [5]: [channel#35, id#36, sales#136, returns#137, profit#138]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q6/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q6/explain.txt
index f57279991..91e94e94d 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q6/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q6/explain.txt
@@ -222,7 +222,7 @@ Condition : (cnt#25 >= 10)
 
 (39) CometTakeOrderedAndProject
 Input [3]: [state#24, cnt#25, ca_state#3]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[cnt#25 ASC NULLS FIRST,ca_state#3 ASC NULLS FIRST], output=[state#24,cnt#25]), [state#24, cnt#25], 100, [cnt#25 ASC NULLS FIRST, ca_state#3 ASC NULLS FIRST], [state#24, cnt#25]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[cnt#25 ASC NULLS FIRST,ca_state#3 ASC NULLS FIRST], output=[state#24,cnt#25]), [state#24, cnt#25], 100, 0, [cnt#25 ASC NULLS FIRST, ca_state#3 ASC NULLS FIRST], [state#24, cnt#25]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [2]: [state#24, cnt#25]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q72/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q72/explain.txt
index 86b9e9582..66cd5f1de 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q72/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q72/explain.txt
@@ -362,7 +362,7 @@ Functions [1]: [count(1)]
 
 (63) CometTakeOrderedAndProject
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC NUL [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, 0, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC  [...]
 
 (64) CometColumnarToRow [codegen id : 1]
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q74/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q74/explain.txt
index 8c35a7684..9f7765232 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q74/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q74/explain.txt
@@ -406,7 +406,7 @@ Arguments: [customer_id#28, customer_first_name#29, customer_last_name#30], [cus
 
 (71) CometTakeOrderedAndProject
 Input [3]: [customer_id#28, customer_first_name#29, customer_last_name#30]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_first_name#29 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST,customer_last_name#30 ASC NULLS FIRST], output=[customer_id#28,customer_first_name#29,customer_last_name#30]), [customer_id#28, customer_first_name#29, customer_last_name#30], 100, [customer_first_name#29 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST, customer_last_name#30 ASC NULLS FIRST], [customer_id#28, customer_first_name#29, customer_last_name#30]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_first_name#29 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST,customer_last_name#30 ASC NULLS FIRST], output=[customer_id#28,customer_first_name#29,customer_last_name#30]), [customer_id#28, customer_first_name#29, customer_last_name#30], 100, 0, [customer_first_name#29 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST, customer_last_name#30 ASC NULLS FIRST], [customer_id#28, customer_first_name#29, customer_last_name#30]
 
 (72) CometColumnarToRow [codegen id : 1]
 Input [3]: [customer_id#28, customer_first_name#29, customer_last_name#30]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q75/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q75/explain.txt
index 9eaf821bd..a7b7f7e06 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q75/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q75/explain.txt
@@ -674,7 +674,7 @@ Arguments: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#1
 
 (123) CometTakeOrderedAndProject
 Input [10]: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#124 ASC NULLS FIRST,sales_amt_diff#125 ASC NULLS FIRST], output=[prev_year#120,year#121,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#122,curr_yr_cnt#123,sales_cnt_diff#124,sales_amt_diff#125]), [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125], 100, [sales_cnt_diff#124 ASC NULLS FIR [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#124 ASC NULLS FIRST,sales_amt_diff#125 ASC NULLS FIRST], output=[prev_year#120,year#121,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#122,curr_yr_cnt#123,sales_cnt_diff#124,sales_amt_diff#125]), [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125], 100, 0, [sales_cnt_diff#124 ASC NULLS  [...]
 
 (124) CometColumnarToRow [codegen id : 1]
 Input [10]: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q77a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q77a/explain.txt
index ee012cfa9..dfd15758f 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q77a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q77a/explain.txt
@@ -571,7 +571,7 @@ Functions: []
 
 (102) CometTakeOrderedAndProject
 Input [5]: [channel#24, id#25, sales#91, returns#92, profit#93]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#24 ASC NULLS FIRST,id#25 ASC NULLS FIRST], output=[channel#24,id#25,sales#91,returns#92,profit#93]), [channel#24, id#25, sales#91, returns#92, profit#93], 100, [channel#24 ASC NULLS FIRST, id#25 ASC NULLS FIRST], [channel#24, id#25, sales#91, returns#92, profit#93]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#24 ASC NULLS FIRST,id#25 ASC NULLS FIRST], output=[channel#24,id#25,sales#91,returns#92,profit#93]), [channel#24, id#25, sales#91, returns#92, profit#93], 100, 0, [channel#24 ASC NULLS FIRST, id#25 ASC NULLS FIRST], [channel#24, id#25, sales#91, returns#92, profit#93]
 
 (103) CometColumnarToRow [codegen id : 22]
 Input [5]: [channel#24, id#25, sales#91, returns#92, profit#93]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q80a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q80a/explain.txt
index 4a815474e..5c8942f91 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q80a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark3_5/q80a/explain.txt
@@ -689,7 +689,7 @@ Functions: []
 
 (123) CometTakeOrderedAndProject
 Input [5]: [channel#31, id#32, sales#115, returns#116, profit#117]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#31 ASC NULLS FIRST,id#32 ASC NULLS FIRST], output=[channel#31,id#32,sales#115,returns#116,profit#117]), [channel#31, id#32, sales#115, returns#116, profit#117], 100, [channel#31 ASC NULLS FIRST, id#32 ASC NULLS FIRST], [channel#31, id#32, sales#115, returns#116, profit#117]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#31 ASC NULLS FIRST,id#32 ASC NULLS FIRST], output=[channel#31,id#32,sales#115,returns#116,profit#117]), [channel#31, id#32, sales#115, returns#116, profit#117], 100, 0, [channel#31 ASC NULLS FIRST, id#32 ASC NULLS FIRST], [channel#31, id#32, sales#115, returns#116, profit#117]
 
 (124) CometColumnarToRow [codegen id : 19]
 Input [5]: [channel#31, id#32, sales#115, returns#116, profit#117]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q10a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q10a/explain.txt
index 97eedb22a..3ac499da5 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q10a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q10a/explain.txt
@@ -223,7 +223,7 @@ Functions [1]: [count(1)]
 
 (39) CometTakeOrderedAndProject
 Input [14]: [cd_gender#31, cd_marital_status#32, cd_education_status#33, cnt1#36, cd_purchase_estimate#26, cnt2#37, cd_credit_rating#34, cnt3#38, cd_dep_count#28, cnt4#39, cd_dep_employed_count#29, cnt5#40, cd_dep_college_count#30, cnt6#41]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[cd_gender#31 ASC NULLS FIRST,cd_marital_status#32 ASC NULLS FIRST,cd_education_status#33 ASC NULLS FIRST,cd_purchase_estimate#26 ASC NULLS FIRST,cd_credit_rating#34 ASC NULLS FIRST,cd_dep_count#28 ASC NULLS FIRST,cd_dep_employed_count#29 ASC NULLS FIRST,cd_dep_college_count#30 ASC NULLS FIRST], output=[cd_gender#31,cd_marital_status#32,cd_education_status#33,cnt1#36,cd_purchase_estimate#26,cnt2#37,cd_credit_rating#34,cnt3#38,cd_dep_cou [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[cd_gender#31 ASC NULLS FIRST,cd_marital_status#32 ASC NULLS FIRST,cd_education_status#33 ASC NULLS FIRST,cd_purchase_estimate#26 ASC NULLS FIRST,cd_credit_rating#34 ASC NULLS FIRST,cd_dep_count#28 ASC NULLS FIRST,cd_dep_employed_count#29 ASC NULLS FIRST,cd_dep_college_count#30 ASC NULLS FIRST], output=[cd_gender#31,cd_marital_status#32,cd_education_status#33,cnt1#36,cd_purchase_estimate#26,cnt2#37,cd_credit_rating#34,cnt3#38,cd_dep_cou [...]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [14]: [cd_gender#31, cd_marital_status#32, cd_education_status#33, cnt1#36, cd_purchase_estimate#26, cnt2#37, cd_credit_rating#34, cnt3#38, cd_dep_count#28, cnt4#39, cd_dep_employed_count#29, cnt5#40, cd_dep_college_count#30, cnt6#41]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q14a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q14a/explain.txt
index 3e54b5ffd..d2bc43233 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q14a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q14a/explain.txt
@@ -774,7 +774,7 @@ Functions: []
 
 (136) CometTakeOrderedAndProject
 Input [6]: [channel#54, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#111, number_sales#112]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#54 ASC NULLS FIRST,i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#54,i_brand_id#40,i_class_id#41,i_category_id#42,sum_sales#111,number_sales#112]), [channel#54, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#111, number_sales#112], 100, [channel#54 ASC NULLS FIRST, i_brand_id#40 ASC NULLS FIRST, i_class_id#41 ASC NULLS FIRST, i_category_id#42 ASC NULLS F [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#54 ASC NULLS FIRST,i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#54,i_brand_id#40,i_class_id#41,i_category_id#42,sum_sales#111,number_sales#112]), [channel#54, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#111, number_sales#112], 100, 0, [channel#54 ASC NULLS FIRST, i_brand_id#40 ASC NULLS FIRST, i_class_id#41 ASC NULLS FIRST, i_category_id#42 ASC NULL [...]
 
 (137) CometColumnarToRow [codegen id : 46]
 Input [6]: [channel#54, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#111, number_sales#112]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q49/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q49/explain.txt
index 2fc63b2fe..13187e4c9 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q49/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q49/explain.txt
@@ -454,7 +454,7 @@ Functions: []
 
 (83) CometTakeOrderedAndProject
 Input [5]: [channel#37, item#32, return_ratio#33, return_rank#35, currency_rank#36]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#37 ASC NULLS FIRST,return_rank#35 ASC NULLS FIRST,currency_rank#36 ASC NULLS FIRST,item#32 ASC NULLS FIRST], output=[channel#37,item#32,return_ratio#33,return_rank#35,currency_rank#36]), [channel#37, item#32, return_ratio#33, return_rank#35, currency_rank#36], 100, [channel#37 ASC NULLS FIRST, return_rank#35 ASC NULLS FIRST, currency_rank#36 ASC NULLS FIRST, item#32 ASC NULLS FIRST], [channel#37, item#32, return_ratio#33, retur [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#37 ASC NULLS FIRST,return_rank#35 ASC NULLS FIRST,currency_rank#36 ASC NULLS FIRST,item#32 ASC NULLS FIRST], output=[channel#37,item#32,return_ratio#33,return_rank#35,currency_rank#36]), [channel#37, item#32, return_ratio#33, return_rank#35, currency_rank#36], 100, 0, [channel#37 ASC NULLS FIRST, return_rank#35 ASC NULLS FIRST, currency_rank#36 ASC NULLS FIRST, item#32 ASC NULLS FIRST], [channel#37, item#32, return_ratio#33, re [...]
 
 (84) CometColumnarToRow [codegen id : 17]
 Input [5]: [channel#37, item#32, return_ratio#33, return_rank#35, currency_rank#36]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q5a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q5a/explain.txt
index 50f6648b6..8ebe6f342 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q5a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q5a/explain.txt
@@ -542,7 +542,7 @@ Functions: []
 
 (94) CometTakeOrderedAndProject
 Input [5]: [channel#39, id#40, sales#148, returns#149, profit#150]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#39 ASC NULLS FIRST,id#40 ASC NULLS FIRST], output=[channel#39,id#40,sales#148,returns#149,profit#150]), [channel#39, id#40, sales#148, returns#149, profit#150], 100, [channel#39 ASC NULLS FIRST, id#40 ASC NULLS FIRST], [channel#39, id#40, sales#148, returns#149, profit#150]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#39 ASC NULLS FIRST,id#40 ASC NULLS FIRST], output=[channel#39,id#40,sales#148,returns#149,profit#150]), [channel#39, id#40, sales#148, returns#149, profit#150], 100, 0, [channel#39 ASC NULLS FIRST, id#40 ASC NULLS FIRST], [channel#39, id#40, sales#148, returns#149, profit#150]
 
 (95) CometColumnarToRow [codegen id : 28]
 Input [5]: [channel#39, id#40, sales#148, returns#149, profit#150]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q72/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q72/explain.txt
index 41346ec9a..9ab0039d8 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q72/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q72/explain.txt
@@ -362,7 +362,7 @@ Functions [1]: [count(1)]
 
 (63) CometTakeOrderedAndProject
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC NUL [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, 0, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC  [...]
 
 (64) CometColumnarToRow [codegen id : 1]
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q75/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q75/explain.txt
index 6c9dce67b..be32a81d2 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q75/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q75/explain.txt
@@ -698,7 +698,7 @@ Arguments: [prev_year#133, year#134, i_brand_id#8, i_class_id#9, i_category_id#1
 
 (127) CometTakeOrderedAndProject
 Input [10]: [prev_year#133, year#134, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#135, curr_yr_cnt#136, sales_cnt_diff#137, sales_amt_diff#138]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#137 ASC NULLS FIRST,sales_amt_diff#138 ASC NULLS FIRST], output=[prev_year#133,year#134,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#135,curr_yr_cnt#136,sales_cnt_diff#137,sales_amt_diff#138]), [prev_year#133, year#134, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#135, curr_yr_cnt#136, sales_cnt_diff#137, sales_amt_diff#138], 100, [sales_cnt_diff#137 ASC NULLS FIR [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#137 ASC NULLS FIRST,sales_amt_diff#138 ASC NULLS FIRST], output=[prev_year#133,year#134,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#135,curr_yr_cnt#136,sales_cnt_diff#137,sales_amt_diff#138]), [prev_year#133, year#134, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#135, curr_yr_cnt#136, sales_cnt_diff#137, sales_amt_diff#138], 100, 0, [sales_cnt_diff#137 ASC NULLS  [...]
 
 (128) CometColumnarToRow [codegen id : 5]
 Input [10]: [prev_year#133, year#134, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#135, curr_yr_cnt#136, sales_cnt_diff#137, sales_amt_diff#138]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q77a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q77a/explain.txt
index 9d1259441..e8d00edaf 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q77a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q77a/explain.txt
@@ -629,7 +629,7 @@ Functions: []
 
 (110) CometTakeOrderedAndProject
 Input [5]: [channel#32, id#33, sales#115, returns#116, profit#117]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#32 ASC NULLS FIRST,id#33 ASC NULLS FIRST], output=[channel#32,id#33,sales#115,returns#116,profit#117]), [channel#32, id#33, sales#115, returns#116, profit#117], 100, [channel#32 ASC NULLS FIRST, id#33 ASC NULLS FIRST], [channel#32, id#33, sales#115, returns#116, profit#117]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#32 ASC NULLS FIRST,id#33 ASC NULLS FIRST], output=[channel#32,id#33,sales#115,returns#116,profit#117]), [channel#32, id#33, sales#115, returns#116, profit#117], 100, 0, [channel#32 ASC NULLS FIRST, id#33 ASC NULLS FIRST], [channel#32, id#33, sales#115, returns#116, profit#117]
 
 (111) CometColumnarToRow [codegen id : 46]
 Input [5]: [channel#32, id#33, sales#115, returns#116, profit#117]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q80a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q80a/explain.txt
index b88670e86..cc6946708 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q80a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7-spark4_0/q80a/explain.txt
@@ -707,7 +707,7 @@ Functions: []
 
 (126) CometTakeOrderedAndProject
 Input [5]: [channel#36, id#37, sales#130, returns#131, profit#132]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#36 ASC NULLS FIRST,id#37 ASC NULLS FIRST], output=[channel#36,id#37,sales#130,returns#131,profit#132]), [channel#36, id#37, sales#130, returns#131, profit#132], 100, [channel#36 ASC NULLS FIRST, id#37 ASC NULLS FIRST], [channel#36, id#37, sales#130, returns#131, profit#132]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#36 ASC NULLS FIRST,id#37 ASC NULLS FIRST], output=[channel#36,id#37,sales#130,returns#131,profit#132]), [channel#36, id#37, sales#130, returns#131, profit#132], 100, 0, [channel#36 ASC NULLS FIRST, id#37 ASC NULLS FIRST], [channel#36, id#37, sales#130, returns#131, profit#132]
 
 (127) CometColumnarToRow [codegen id : 28]
 Input [5]: [channel#36, id#37, sales#130, returns#131, profit#132]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q10a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q10a/explain.txt
index 21a3020e1..232bcbff7 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q10a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q10a/explain.txt
@@ -223,7 +223,7 @@ Functions [1]: [count(1)]
 
 (39) CometTakeOrderedAndProject
 Input [14]: [cd_gender#30, cd_marital_status#31, cd_education_status#32, cnt1#35, cd_purchase_estimate#25, cnt2#36, cd_credit_rating#33, cnt3#37, cd_dep_count#27, cnt4#38, cd_dep_employed_count#28, cnt5#39, cd_dep_college_count#29, cnt6#40]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[cd_gender#30 ASC NULLS FIRST,cd_marital_status#31 ASC NULLS FIRST,cd_education_status#32 ASC NULLS FIRST,cd_purchase_estimate#25 ASC NULLS FIRST,cd_credit_rating#33 ASC NULLS FIRST,cd_dep_count#27 ASC NULLS FIRST,cd_dep_employed_count#28 ASC NULLS FIRST,cd_dep_college_count#29 ASC NULLS FIRST], output=[cd_gender#30,cd_marital_status#31,cd_education_status#32,cnt1#35,cd_purchase_estimate#25,cnt2#36,cd_credit_rating#33,cnt3#37,cd_dep_cou [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[cd_gender#30 ASC NULLS FIRST,cd_marital_status#31 ASC NULLS FIRST,cd_education_status#32 ASC NULLS FIRST,cd_purchase_estimate#25 ASC NULLS FIRST,cd_credit_rating#33 ASC NULLS FIRST,cd_dep_count#27 ASC NULLS FIRST,cd_dep_employed_count#28 ASC NULLS FIRST,cd_dep_college_count#29 ASC NULLS FIRST], output=[cd_gender#30,cd_marital_status#31,cd_education_status#32,cnt1#35,cd_purchase_estimate#25,cnt2#36,cd_credit_rating#33,cnt3#37,cd_dep_cou [...]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [14]: [cd_gender#30, cd_marital_status#31, cd_education_status#32, cnt1#35, cd_purchase_estimate#25, cnt2#36, cd_credit_rating#33, cnt3#37, cd_dep_count#27, cnt4#38, cd_dep_employed_count#28, cnt5#39, cd_dep_college_count#29, cnt6#40]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q11/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q11/explain.txt
index 90ffbe79d..acf432228 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q11/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q11/explain.txt
@@ -406,7 +406,7 @@ Arguments: [customer_id#41, customer_first_name#42, customer_last_name#43, custo
 
 (71) CometTakeOrderedAndProject
 Input [4]: [customer_id#41, customer_first_name#42, customer_last_name#43, customer_email_address#44]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#41 ASC NULLS FIRST,customer_first_name#42 ASC NULLS FIRST,customer_last_name#43 ASC NULLS FIRST,customer_email_address#44 ASC NULLS FIRST], output=[customer_id#41,customer_first_name#42,customer_last_name#43,customer_email_address#44]), [customer_id#41, customer_first_name#42, customer_last_name#43, customer_email_address#44], 100, [customer_id#41 ASC NULLS FIRST, customer_first_name#42 ASC NULLS FIRST, customer_last_name#4 [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_id#41 ASC NULLS FIRST,customer_first_name#42 ASC NULLS FIRST,customer_last_name#43 ASC NULLS FIRST,customer_email_address#44 ASC NULLS FIRST], output=[customer_id#41,customer_first_name#42,customer_last_name#43,customer_email_address#44]), [customer_id#41, customer_first_name#42, customer_last_name#43, customer_email_address#44], 100, 0, [customer_id#41 ASC NULLS FIRST, customer_first_name#42 ASC NULLS FIRST, customer_last_nam [...]
 
 (72) CometColumnarToRow [codegen id : 1]
 Input [4]: [customer_id#41, customer_first_name#42, customer_last_name#43, customer_email_address#44]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q14/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q14/explain.txt
index b2d894225..d36a69113 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q14/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q14/explain.txt
@@ -478,7 +478,7 @@ Arguments: [i_brand_id#40, i_class_id#41, i_category_id#42], [i_brand_id#61, i_c
 
 (84) CometTakeOrderedAndProject
 Input [12]: [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#71, i_brand_id#61, i_class_id#62, i_category_id#63, sales#72, number_sales#73]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#50,i_brand_id#40,i_class_id#41,i_category_id#42,sales#51,number_sales#52,channel#71,i_brand_id#61,i_class_id#62,i_category_id#63,sales#72,number_sales#73]), [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#71, i_brand_id#61, i_class_id#62, i_category_id#63, sales#72, number_sales# [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#50,i_brand_id#40,i_class_id#41,i_category_id#42,sales#51,number_sales#52,channel#71,i_brand_id#61,i_class_id#62,i_category_id#63,sales#72,number_sales#73]), [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#71, i_brand_id#61, i_class_id#62, i_category_id#63, sales#72, number_sales# [...]
 
 (85) CometColumnarToRow [codegen id : 1]
 Input [12]: [channel#50, i_brand_id#40, i_class_id#41, i_category_id#42, sales#51, number_sales#52, channel#71, i_brand_id#61, i_class_id#62, i_category_id#63, sales#72, number_sales#73]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q14a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q14a/explain.txt
index 124efb808..4133a9002 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q14a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q14a/explain.txt
@@ -680,7 +680,7 @@ Functions: []
 
 (121) CometTakeOrderedAndProject
 Input [6]: [channel#49, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#89, number_sales#90]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#49 ASC NULLS FIRST,i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#49,i_brand_id#40,i_class_id#41,i_category_id#42,sum_sales#89,number_sales#90]), [channel#49, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#89, number_sales#90], 100, [channel#49 ASC NULLS FIRST, i_brand_id#40 ASC NULLS FIRST, i_class_id#41 ASC NULLS FIRST, i_category_id#42 ASC NULLS FIRST [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#49 ASC NULLS FIRST,i_brand_id#40 ASC NULLS FIRST,i_class_id#41 ASC NULLS FIRST,i_category_id#42 ASC NULLS FIRST], output=[channel#49,i_brand_id#40,i_class_id#41,i_category_id#42,sum_sales#89,number_sales#90]), [channel#49, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#89, number_sales#90], 100, 0, [channel#49 ASC NULLS FIRST, i_brand_id#40 ASC NULLS FIRST, i_class_id#41 ASC NULLS FIRST, i_category_id#42 ASC NULLS FI [...]
 
 (122) CometColumnarToRow [codegen id : 1]
 Input [6]: [channel#49, i_brand_id#40, i_class_id#41, i_category_id#42, sum_sales#89, number_sales#90]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q18a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q18a/explain.txt
index d3de898cd..b610e8191 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q18a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q18a/explain.txt
@@ -798,7 +798,7 @@ Child 4 Input [11]: [i_item_id#231, ca_country#232, ca_state#233, county#234, ag
 
 (145) CometTakeOrderedAndProject
 Input [11]: [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#197, agg2#198, agg3#199, agg4#200, agg5#201, agg6#202, agg7#203]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_country#32 ASC NULLS FIRST,ca_state#33 ASC NULLS FIRST,ca_county#34 ASC NULLS FIRST,i_item_id#31 ASC NULLS FIRST], output=[i_item_id#31,ca_country#32,ca_state#33,ca_county#34,agg1#197,agg2#198,agg3#199,agg4#200,agg5#201,agg6#202,agg7#203]), [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#197, agg2#198, agg3#199, agg4#200, agg5#201, agg6#202, agg7#203], 100, [ca_country#32 ASC NULLS FIRST, ca_state#33 ASC NULLS FIRST, c [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_country#32 ASC NULLS FIRST,ca_state#33 ASC NULLS FIRST,ca_county#34 ASC NULLS FIRST,i_item_id#31 ASC NULLS FIRST], output=[i_item_id#31,ca_country#32,ca_state#33,ca_county#34,agg1#197,agg2#198,agg3#199,agg4#200,agg5#201,agg6#202,agg7#203]), [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#197, agg2#198, agg3#199, agg4#200, agg5#201, agg6#202, agg7#203], 100, 0, [ca_country#32 ASC NULLS FIRST, ca_state#33 ASC NULLS FIRST [...]
 
 (146) CometColumnarToRow [codegen id : 1]
 Input [11]: [i_item_id#31, ca_country#32, ca_state#33, ca_county#34, agg1#197, agg2#198, agg3#199, agg4#200, agg5#201, agg6#202, agg7#203]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q22a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q22a/explain.txt
index 524d2a32a..a4a3ce9ea 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q22a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q22a/explain.txt
@@ -261,7 +261,7 @@ Child 4 Input [5]: [i_product_name#57, i_brand#58, i_class#59, i_category#60, qo
 
 (46) CometTakeOrderedAndProject
 Input [5]: [i_product_name#20, i_brand#21, i_class#22, i_category#23, qoh#47]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[qoh#47 ASC NULLS FIRST,i_product_name#20 ASC NULLS FIRST,i_brand#21 ASC NULLS FIRST,i_class#22 ASC NULLS FIRST,i_category#23 ASC NULLS FIRST], output=[i_product_name#20,i_brand#21,i_class#22,i_category#23,qoh#47]), [i_product_name#20, i_brand#21, i_class#22, i_category#23, qoh#47], 100, [qoh#47 ASC NULLS FIRST, i_product_name#20 ASC NULLS FIRST, i_brand#21 ASC NULLS FIRST, i_class#22 ASC NULLS FIRST, i_category#23 ASC NULLS FIRST], [i_ [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[qoh#47 ASC NULLS FIRST,i_product_name#20 ASC NULLS FIRST,i_brand#21 ASC NULLS FIRST,i_class#22 ASC NULLS FIRST,i_category#23 ASC NULLS FIRST], output=[i_product_name#20,i_brand#21,i_class#22,i_category#23,qoh#47]), [i_product_name#20, i_brand#21, i_class#22, i_category#23, qoh#47], 100, 0, [qoh#47 ASC NULLS FIRST, i_product_name#20 ASC NULLS FIRST, i_brand#21 ASC NULLS FIRST, i_class#22 ASC NULLS FIRST, i_category#23 ASC NULLS FIRST],  [...]
 
 (47) CometColumnarToRow [codegen id : 1]
 Input [5]: [i_product_name#20, i_brand#21, i_class#22, i_category#23, qoh#47]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q27a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q27a/explain.txt
index a88140fee..46529c3e5 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q27a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q27a/explain.txt
@@ -393,7 +393,7 @@ Child 2 Input [7]: [i_item_id#90, s_state#91, g_state#92, agg1#93, agg2#94, agg3
 
 (70) CometTakeOrderedAndProject
 Input [7]: [i_item_id#22, s_state#23, g_state#79, agg1#80, agg2#81, agg3#82, agg4#83]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#22 ASC NULLS FIRST,s_state#23 ASC NULLS FIRST], output=[i_item_id#22,s_state#23,g_state#79,agg1#80,agg2#81,agg3#82,agg4#83]), [i_item_id#22, s_state#23, g_state#79, agg1#80, agg2#81, agg3#82, agg4#83], 100, [i_item_id#22 ASC NULLS FIRST, s_state#23 ASC NULLS FIRST], [i_item_id#22, s_state#23, g_state#79, agg1#80, agg2#81, agg3#82, agg4#83]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[i_item_id#22 ASC NULLS FIRST,s_state#23 ASC NULLS FIRST], output=[i_item_id#22,s_state#23,g_state#79,agg1#80,agg2#81,agg3#82,agg4#83]), [i_item_id#22, s_state#23, g_state#79, agg1#80, agg2#81, agg3#82, agg4#83], 100, 0, [i_item_id#22 ASC NULLS FIRST, s_state#23 ASC NULLS FIRST], [i_item_id#22, s_state#23, g_state#79, agg1#80, agg2#81, agg3#82, agg4#83]
 
 (71) CometColumnarToRow [codegen id : 1]
 Input [7]: [i_item_id#22, s_state#23, g_state#79, agg1#80, agg2#81, agg3#82, agg4#83]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q35a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q35a/explain.txt
index 2306ef9af..319193448 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q35a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q35a/explain.txt
@@ -223,7 +223,7 @@ Functions [10]: [count(1), avg(cd_dep_count#25), max(cd_dep_count#25), sum(cd_de
 
 (39) CometTakeOrderedAndProject
 Input [18]: [ca_state#21, cd_gender#28, cd_marital_status#29, cd_dep_count#25, cnt1#43, avg(cd_dep_count)#44, max(cd_dep_count)#45, sum(cd_dep_count)#46, cd_dep_employed_count#26, cnt2#47, avg(cd_dep_employed_count)#48, max(cd_dep_employed_count)#49, sum(cd_dep_employed_count)#50, cd_dep_college_count#27, cnt3#51, avg(cd_dep_college_count)#52, max(cd_dep_college_count)#53, sum(cd_dep_college_count)#54]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_state#21 ASC NULLS FIRST,cd_gender#28 ASC NULLS FIRST,cd_marital_status#29 ASC NULLS FIRST,cd_dep_count#25 ASC NULLS FIRST,cd_dep_employed_count#26 ASC NULLS FIRST,cd_dep_college_count#27 ASC NULLS FIRST], output=[ca_state#21,cd_gender#28,cd_marital_status#29,cd_dep_count#25,cnt1#43,avg(cd_dep_count)#44,max(cd_dep_count)#45,sum(cd_dep_count)#46,cd_dep_employed_count#26,cnt2#47,avg(cd_dep_employed_count)#48,max(cd_dep_employed_count) [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[ca_state#21 ASC NULLS FIRST,cd_gender#28 ASC NULLS FIRST,cd_marital_status#29 ASC NULLS FIRST,cd_dep_count#25 ASC NULLS FIRST,cd_dep_employed_count#26 ASC NULLS FIRST,cd_dep_college_count#27 ASC NULLS FIRST], output=[ca_state#21,cd_gender#28,cd_marital_status#29,cd_dep_count#25,cnt1#43,avg(cd_dep_count)#44,max(cd_dep_count)#45,sum(cd_dep_count)#46,cd_dep_employed_count#26,cnt2#47,avg(cd_dep_employed_count)#48,max(cd_dep_employed_count) [...]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [18]: [ca_state#21, cd_gender#28, cd_marital_status#29, cd_dep_count#25, cnt1#43, avg(cd_dep_count)#44, max(cd_dep_count)#45, sum(cd_dep_count)#46, cd_dep_employed_count#26, cnt2#47, avg(cd_dep_employed_count)#48, max(cd_dep_employed_count)#49, sum(cd_dep_employed_count)#50, cd_dep_college_count#27, cnt3#51, avg(cd_dep_college_count)#52, max(cd_dep_college_count)#53, sum(cd_dep_college_count)#54]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q49/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q49/explain.txt
index 281d422ff..786c55693 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q49/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q49/explain.txt
@@ -418,7 +418,7 @@ Functions: []
 
 (77) CometTakeOrderedAndProject
 Input [5]: [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#27 ASC NULLS FIRST,return_rank#25 ASC NULLS FIRST,currency_rank#26 ASC NULLS FIRST,item#22 ASC NULLS FIRST], output=[channel#27,item#22,return_ratio#23,return_rank#25,currency_rank#26]), [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26], 100, [channel#27 ASC NULLS FIRST, return_rank#25 ASC NULLS FIRST, currency_rank#26 ASC NULLS FIRST, item#22 ASC NULLS FIRST], [channel#27, item#22, return_ratio#23, retur [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#27 ASC NULLS FIRST,return_rank#25 ASC NULLS FIRST,currency_rank#26 ASC NULLS FIRST,item#22 ASC NULLS FIRST], output=[channel#27,item#22,return_ratio#23,return_rank#25,currency_rank#26]), [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26], 100, 0, [channel#27 ASC NULLS FIRST, return_rank#25 ASC NULLS FIRST, currency_rank#26 ASC NULLS FIRST, item#22 ASC NULLS FIRST], [channel#27, item#22, return_ratio#23, re [...]
 
 (78) CometColumnarToRow [codegen id : 11]
 Input [5]: [channel#27, item#22, return_ratio#23, return_rank#25, currency_rank#26]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q5a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q5a/explain.txt
index a3507abe1..9d28d6894 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q5a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q5a/explain.txt
@@ -524,7 +524,7 @@ Functions: []
 
 (91) CometTakeOrderedAndProject
 Input [5]: [channel#35, id#36, sales#136, returns#137, profit#138]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#35 ASC NULLS FIRST,id#36 ASC NULLS FIRST], output=[channel#35,id#36,sales#136,returns#137,profit#138]), [channel#35, id#36, sales#136, returns#137, profit#138], 100, [channel#35 ASC NULLS FIRST, id#36 ASC NULLS FIRST], [channel#35, id#36, sales#136, returns#137, profit#138]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#35 ASC NULLS FIRST,id#36 ASC NULLS FIRST], output=[channel#35,id#36,sales#136,returns#137,profit#138]), [channel#35, id#36, sales#136, returns#137, profit#138], 100, 0, [channel#35 ASC NULLS FIRST, id#36 ASC NULLS FIRST], [channel#35, id#36, sales#136, returns#137, profit#138]
 
 (92) CometColumnarToRow [codegen id : 19]
 Input [5]: [channel#35, id#36, sales#136, returns#137, profit#138]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q6/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q6/explain.txt
index 3eafe390b..62f5dcd1d 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q6/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q6/explain.txt
@@ -222,7 +222,7 @@ Condition : (cnt#23 >= 10)
 
 (39) CometTakeOrderedAndProject
 Input [3]: [state#22, cnt#23, ca_state#3]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[cnt#23 ASC NULLS FIRST,ca_state#3 ASC NULLS FIRST], output=[state#22,cnt#23]), [state#22, cnt#23], 100, [cnt#23 ASC NULLS FIRST, ca_state#3 ASC NULLS FIRST], [state#22, cnt#23]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[cnt#23 ASC NULLS FIRST,ca_state#3 ASC NULLS FIRST], output=[state#22,cnt#23]), [state#22, cnt#23], 100, 0, [cnt#23 ASC NULLS FIRST, ca_state#3 ASC NULLS FIRST], [state#22, cnt#23]
 
 (40) CometColumnarToRow [codegen id : 1]
 Input [2]: [state#22, cnt#23]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q72/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q72/explain.txt
index 86b9e9582..66cd5f1de 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q72/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q72/explain.txt
@@ -362,7 +362,7 @@ Functions [1]: [count(1)]
 
 (63) CometTakeOrderedAndProject
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC NUL [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[total_cnt#37 DESC NULLS LAST,i_item_desc#17 ASC NULLS FIRST,w_warehouse_name#15 ASC NULLS FIRST,d_week_seq#24 ASC NULLS FIRST], output=[i_item_desc#17,w_warehouse_name#15,d_week_seq#24,no_promo#35,promo#36,total_cnt#37]), [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37], 100, 0, [total_cnt#37 DESC NULLS LAST, i_item_desc#17 ASC NULLS FIRST, w_warehouse_name#15 ASC NULLS FIRST, d_week_seq#24 ASC  [...]
 
 (64) CometColumnarToRow [codegen id : 1]
 Input [6]: [i_item_desc#17, w_warehouse_name#15, d_week_seq#24, no_promo#35, promo#36, total_cnt#37]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q74/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q74/explain.txt
index 8c35a7684..9f7765232 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q74/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q74/explain.txt
@@ -406,7 +406,7 @@ Arguments: [customer_id#28, customer_first_name#29, customer_last_name#30], [cus
 
 (71) CometTakeOrderedAndProject
 Input [3]: [customer_id#28, customer_first_name#29, customer_last_name#30]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_first_name#29 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST,customer_last_name#30 ASC NULLS FIRST], output=[customer_id#28,customer_first_name#29,customer_last_name#30]), [customer_id#28, customer_first_name#29, customer_last_name#30], 100, [customer_first_name#29 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST, customer_last_name#30 ASC NULLS FIRST], [customer_id#28, customer_first_name#29, customer_last_name#30]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[customer_first_name#29 ASC NULLS FIRST,customer_id#28 ASC NULLS FIRST,customer_last_name#30 ASC NULLS FIRST], output=[customer_id#28,customer_first_name#29,customer_last_name#30]), [customer_id#28, customer_first_name#29, customer_last_name#30], 100, 0, [customer_first_name#29 ASC NULLS FIRST, customer_id#28 ASC NULLS FIRST, customer_last_name#30 ASC NULLS FIRST], [customer_id#28, customer_first_name#29, customer_last_name#30]
 
 (72) CometColumnarToRow [codegen id : 1]
 Input [3]: [customer_id#28, customer_first_name#29, customer_last_name#30]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q75/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q75/explain.txt
index 9eaf821bd..a7b7f7e06 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q75/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q75/explain.txt
@@ -674,7 +674,7 @@ Arguments: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#1
 
 (123) CometTakeOrderedAndProject
 Input [10]: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#124 ASC NULLS FIRST,sales_amt_diff#125 ASC NULLS FIRST], output=[prev_year#120,year#121,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#122,curr_yr_cnt#123,sales_cnt_diff#124,sales_amt_diff#125]), [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125], 100, [sales_cnt_diff#124 ASC NULLS FIR [...]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[sales_cnt_diff#124 ASC NULLS FIRST,sales_amt_diff#125 ASC NULLS FIRST], output=[prev_year#120,year#121,i_brand_id#8,i_class_id#9,i_category_id#10,i_manufact_id#12,prev_yr_cnt#122,curr_yr_cnt#123,sales_cnt_diff#124,sales_amt_diff#125]), [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125], 100, 0, [sales_cnt_diff#124 ASC NULLS  [...]
 
 (124) CometColumnarToRow [codegen id : 1]
 Input [10]: [prev_year#120, year#121, i_brand_id#8, i_class_id#9, i_category_id#10, i_manufact_id#12, prev_yr_cnt#122, curr_yr_cnt#123, sales_cnt_diff#124, sales_amt_diff#125]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q77a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q77a/explain.txt
index 2c7e67835..e64e56f55 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q77a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q77a/explain.txt
@@ -571,7 +571,7 @@ Functions: []
 
 (102) CometTakeOrderedAndProject
 Input [5]: [channel#24, id#25, sales#91, returns#92, profit#93]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#24 ASC NULLS FIRST,id#25 ASC NULLS FIRST], output=[channel#24,id#25,sales#91,returns#92,profit#93]), [channel#24, id#25, sales#91, returns#92, profit#93], 100, [channel#24 ASC NULLS FIRST, id#25 ASC NULLS FIRST], [channel#24, id#25, sales#91, returns#92, profit#93]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#24 ASC NULLS FIRST,id#25 ASC NULLS FIRST], output=[channel#24,id#25,sales#91,returns#92,profit#93]), [channel#24, id#25, sales#91, returns#92, profit#93], 100, 0, [channel#24 ASC NULLS FIRST, id#25 ASC NULLS FIRST], [channel#24, id#25, sales#91, returns#92, profit#93]
 
 (103) CometColumnarToRow [codegen id : 22]
 Input [5]: [channel#24, id#25, sales#91, returns#92, profit#93]
diff --git a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q80a/explain.txt b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q80a/explain.txt
index faf228291..143856f44 100644
--- a/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q80a/explain.txt
+++ b/spark/src/test/resources/tpcds-plan-stability/approved-plans-v2_7/q80a/explain.txt
@@ -689,7 +689,7 @@ Functions: []
 
 (123) CometTakeOrderedAndProject
 Input [5]: [channel#31, id#32, sales#115, returns#116, profit#117]
-Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#31 ASC NULLS FIRST,id#32 ASC NULLS FIRST], output=[channel#31,id#32,sales#115,returns#116,profit#117]), [channel#31, id#32, sales#115, returns#116, profit#117], 100, [channel#31 ASC NULLS FIRST, id#32 ASC NULLS FIRST], [channel#31, id#32, sales#115, returns#116, profit#117]
+Arguments: TakeOrderedAndProject(limit=100, orderBy=[channel#31 ASC NULLS FIRST,id#32 ASC NULLS FIRST], output=[channel#31,id#32,sales#115,returns#116,profit#117]), [channel#31, id#32, sales#115, returns#116, profit#117], 100, 0, [channel#31 ASC NULLS FIRST, id#32 ASC NULLS FIRST], [channel#31, id#32, sales#115, returns#116, profit#117]
 
 (124) CometColumnarToRow [codegen id : 19]
 Input [5]: [channel#31, id#32, sales#115, returns#116, profit#117]
diff --git a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
index f2dcedb53..42058036e 100644
--- a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
+++ b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
@@ -1877,11 +1877,7 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
             Set(
               "Comet shuffle is not enabled: spark.comet.exec.shuffle.enabled is not enabled",
               "make_interval is not supported")),
-          (
-            s"select * from $table LIMIT 10 OFFSET 3",
-            Set(
-              "Comet shuffle is not enabled",
-              "CollectLimit with non-zero offset is not supported")))
+          (s"select * from $table LIMIT 10 OFFSET 3", Set("Comet shuffle is not enabled")))
           .foreach(test => {
             val qry = test._1
             val expected = test._2
diff --git a/spark/src/test/scala/org/apache/comet/exec/CometExecSuite.scala b/spark/src/test/scala/org/apache/comet/exec/CometExecSuite.scala
index 33a5e0e99..339f90e81 100644
--- a/spark/src/test/scala/org/apache/comet/exec/CometExecSuite.scala
+++ b/spark/src/test/scala/org/apache/comet/exec/CometExecSuite.scala
@@ -1000,6 +1000,59 @@ class CometExecSuite extends CometTestBase {
     }
   }
 
+  test("TakeOrderedAndProjectExec with positive offset") {
+    withParquetTable((0 until 50).map(i => (i, i + 42)), "tbl") {
+      val regularDfWithOffset = sql("SELECT _1, _2 FROM tbl order by _1 LIMIT 5 OFFSET 7")
+      checkSparkAnswerAndOperator(regularDfWithOffset)
+      val dfWithOffsetOnly = sql("SELECT _1, _2 FROM tbl order by _1 OFFSET 12")
+      checkSparkAnswerAndOperator(dfWithOffsetOnly)
+      val incompleteDf = sql("SELECT _1, _2 FROM tbl order by _1 LIMIT 5 OFFSET 47")
+      checkSparkAnswerAndOperator(incompleteDf)
+      val emptyDf = sql("SELECT _1, _2 FROM tbl order by _1 LIMIT 50 OFFSET 1000")
+      checkSparkAnswerAndOperator(emptyDf)
+    }
+  }
+
+  test("CollectLimitExec with positive offset") {
+    withParquetTable((0 until 50).map(i => (i, i + 12)), "tbl") {
+      // disable top-k sort to switch from TakeProjectExec to CollectLimitExec in the execution plan
+      withSQLConf(SQLConf.TOP_K_SORT_FALLBACK_THRESHOLD.key -> "0") {
+        val regularDfWithOffset = sql("SELECT _1, _2 FROM tbl order by _2 LIMIT 4 OFFSET 4")
+        checkSparkAnswerAndOperator(regularDfWithOffset)
+        val dfWithOffsetOnly = sql("SELECT _1, _2 FROM tbl order by _2 OFFSET 15")
+        checkSparkAnswerAndOperator(dfWithOffsetOnly)
+        val incompleteDf = sql("SELECT _1, _2 FROM tbl order by _1 LIMIT 25 OFFSET 40")
+        checkSparkAnswerAndOperator(incompleteDf)
+        val emptyDf = sql("SELECT _1, _2 FROM tbl order by _1 LIMIT 50 OFFSET 1000")
+        checkSparkAnswerAndOperator(emptyDf)
+      }
+    }
+  }
+
+  test("GlobalLimit with positive offset") {
+    withParquetTable((0 until 50).map(i => (i, i + 13)), "tbl") {
+      val regularDfWithOffset =
+        sql("SELECT _1, _2 FROM tbl order by _2 LIMIT 4 OFFSET 1").groupBy("_1").agg(sum("_2"))
+      checkSparkAnswerAndOperator(regularDfWithOffset)
+      val dfWithOffsetOnly = sql("SELECT _1, _2 FROM tbl order by _2 OFFSET 15").agg(sum("_2"))
+      checkSparkAnswerAndOperator(dfWithOffsetOnly)
+    }
+  }
+
+  test("explicit zero limit and offset") {
+    withParquetTable((0 until 50).map(i => (i, i + 8)), "tbl") {
+      withSQLConf(
+        "spark.sql.optimizer.excludedRules" -> "org.apache.spark.sql.catalyst.optimizer.EliminateLimits") {
+        val dfWithZeroLimitAndOffsetOrdered =
+          sql("SELECT _1, _2 FROM tbl order by _2 LIMIT 0 OFFSET 0")
+        checkSparkAnswerAndOperator(dfWithZeroLimitAndOffsetOrdered)
+        val dfWithZeroLimitAndOffsetUnordered =
+          sql("SELECT _1, _2 FROM tbl LIMIT 0 OFFSET 0")
+        checkSparkAnswerAndOperator(dfWithZeroLimitAndOffsetUnordered)
+      }
+    }
+  }
+
   test("sort with dictionary") {
     withSQLConf(CometConf.COMET_BATCH_SIZE.key -> 8192.toString) {
       withTempDir { dir =>
@@ -1698,7 +1751,7 @@ class CometExecSuite extends CometTestBase {
       })
   }
 
-  test("Fallback to Spark for TakeOrderedAndProjectExec with offset") {
+  test("TakeOrderedAndProjectExec with offset") {
     Seq("true", "false").foreach(aqeEnabled =>
       withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> aqeEnabled) {
         withTable("t1") {
@@ -1709,9 +1762,8 @@ class CometExecSuite extends CometTestBase {
             .repartition(3) // Force repartition to test data will come to single partition
             .write
             .saveAsTable("t1")
-
           val df = sql("SELECT * FROM t1 ORDER BY a, b LIMIT 3 OFFSET 1").groupBy($"a").sum("b")
-          checkSparkAnswer(df)
+          checkSparkAnswerAndOperator(df)
         }
       })
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org