You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by al...@apache.org on 2026/10/01 05:07:31 UTC

(asterixdb) branch master updated: [ASTERIXDB-3928][COMP] Bound CLUSTER BY's seed-draw sort

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

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new b57e560b10 [ASTERIXDB-3928][COMP] Bound CLUSTER BY's seed-draw sort
b57e560b10 is described below

commit b57e560b10b4feab15c27e4e08303874b595a426
Author: Ali Alsuliman <al...@gmail.com>
AuthorDate: Tue Sep 29 11:27:14 2026 -0700

    [ASTERIXDB-3928][COMP] Bound CLUSTER BY's seed-draw sort
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details: the seed draw orders the vectors on a shuffle key and keeps
    the first. Property enforcement replaces that sort with an unbounded
    local one, dropping its bound, which only PushLimitIntoOrderByRule
    restores, and only from an INTEGER limit. The draw's LIMIT was a
    BIGINT, so on partitioned input every vector went through a full
    external sort to pick one.
    
    Ext-ref: MB-74142
    Generated-by: Claude Opus 5.5 <no...@anthropic.com>
    Change-Id: I2e708b78ce44026d11b469253fc49e0c53959bae
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21933
    Reviewed-by: Shahrzad Shirazi <sh...@ucr.edu>
    Tested-by: Ali Alsuliman <al...@gmail.com>
---
 .../asterix/optimizer/rules/RewriteClusterByToKMeansRule.java    | 9 +++------
 .../optimizerts/results/cluster-by/kmeans-decor-validate.plan    | 4 ++--
 .../results/cluster-by/kmeans-init-random-validate.plan          | 4 ++--
 .../results/cluster-by/kmeans-join-members-projected.plan        | 4 ++--
 .../results/cluster-by/kmeans-syntax-full-validate.plan          | 4 ++--
 .../optimizerts/results/cluster-by/kmeans-syntax-validate.plan   | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.10.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.11.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.12.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.8.plan           | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.9.plan           | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.10.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.11.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.12.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.8.plan           | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.9.plan           | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.10.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.11.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.12.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.8.plan           | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.9.plan           | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.10.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.11.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.12.plan          | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.8.plan           | 4 ++--
 .../kmeans-num-iterations/kmeans-num-iterations.9.plan           | 4 ++--
 26 files changed, 53 insertions(+), 56 deletions(-)

diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RewriteClusterByToKMeansRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RewriteClusterByToKMeansRule.java
index a9a86ab58c..f6750f7749 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RewriteClusterByToKMeansRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RewriteClusterByToKMeansRule.java
@@ -27,6 +27,7 @@ import java.util.Set;
 
 import org.apache.asterix.common.clustering.ClusterByOptions;
 import org.apache.asterix.om.base.ABoolean;
+import org.apache.asterix.om.base.AInt32;
 import org.apache.asterix.om.base.AInt64;
 import org.apache.asterix.om.base.AString;
 import org.apache.asterix.om.constants.AsterixConstantValue;
@@ -559,19 +560,15 @@ public class RewriteClusterByToKMeansRule implements IAlgebraicRewriteRule {
         assign.getInputs().add(new MutableObject<>(guard));
         finish(assign, context);
 
-        // A top-n sort: PushLimitIntoOrderByRule, which would fuse a sort and a limit, has already run.
         OrderOperator order = new OrderOperator(new ArrayList<>(), n);
         order.setSourceLocation(loc);
         order.getOrderExpressions().add(Pair.of(OrderOperator.ASC_ORDER, ref(keyVar)));
         order.getInputs().add(new MutableObject<>(assign));
-        // The pass that fuses a LIMIT into a top-n sort ran before this rule, so the bound is set here
-        // directly, the way the labelling join sets its broadcast NLJ. Property enforcement then derives a
-        // local sort from this one and inherits the bound onto it.
         order.setPhysicalOperator(new StableSortPOperator(n));
         finish(order, context);
 
-        // The top-n bounds the sort; the limit bounds the stream.
-        LimitOperator limit = new LimitOperator(constant((long) n).getValue());
+        // INTEGER: enforcement drops this sort's bound, and PushLimitIntoOrderByRule restores it only from one.
+        LimitOperator limit = new LimitOperator(new ConstantExpression(new AsterixConstantValue(new AInt32(n))));
         limit.setSourceLocation(loc);
         limit.getInputs().add(new MutableObject<>(order));
         finish(limit, context);
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-decor-validate.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-decor-validate.plan
index a0facf9146..d31ace28fb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-decor-validate.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-decor-validate.plan
@@ -123,8 +123,8 @@ distribute result [$$94] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                 -- STREAM_LIMIT  |PARTITIONED|
                                                   exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    order (ASC, $$98) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                    -- STABLE_SORT [$$98(ASC)]  |PARTITIONED|
+                                                    order (topK: 1) (ASC, $$98) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                    -- STABLE_SORT [topK: 1] [$$98(ASC)]  |PARTITIONED|
                                                       exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                         assign [$$98] <- [vector-shuffle-key($$97, 42)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-init-random-validate.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-init-random-validate.plan
index 58899216fd..36026ea117 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-init-random-validate.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-init-random-validate.plan
@@ -87,8 +87,8 @@ distribute result [$$73] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                         -- STREAM_LIMIT  |PARTITIONED|
                                           exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            order (ASC, $$76) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                            -- STABLE_SORT [$$76(ASC)]  |PARTITIONED|
+                                            order (topK: 3) (ASC, $$76) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                            -- STABLE_SORT [topK: 3] [$$76(ASC)]  |PARTITIONED|
                                               exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                 assign [$$76] <- [vector-shuffle-key($$75, 42)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-join-members-projected.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-join-members-projected.plan
index 17113c1a0c..85f931f703 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-join-members-projected.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-join-members-projected.plan
@@ -210,8 +210,8 @@ distribute result [$$236] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$250) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$250(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$250) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$250(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$250] <- [vector-shuffle-key($$249, 42)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-syntax-full-validate.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-syntax-full-validate.plan
index 90866d77c0..28ff6ca7a2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-syntax-full-validate.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-syntax-full-validate.plan
@@ -133,8 +133,8 @@ distribute result [$$76] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                     -- STREAM_LIMIT  |PARTITIONED|
                                                       exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        order (ASC, $$81) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                        -- STABLE_SORT [$$81(ASC)]  |PARTITIONED|
+                                                        order (topK: 1) (ASC, $$81) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                        -- STABLE_SORT [topK: 1] [$$81(ASC)]  |PARTITIONED|
                                                           exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                             assign [$$81] <- [vector-shuffle-key($$80, 42)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-syntax-validate.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-syntax-validate.plan
index 3837163616..b0ed679f13 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-syntax-validate.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cluster-by/kmeans-syntax-validate.plan
@@ -119,8 +119,8 @@ distribute result [$$73]
                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                     exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      order (ASC, $$76)
-                                                      -- STABLE_SORT [$$76(ASC)]  |PARTITIONED|
+                                                      order (topK: 1) (ASC, $$76)
+                                                      -- STABLE_SORT [topK: 1] [$$76(ASC)]  |PARTITIONED|
                                                         exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                           assign [$$76] <- [vector-shuffle-key($$75, 42)]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
index 95e1f6f863..61ab7133fc 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
index 95e1f6f863..61ab7133fc 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
index a0b44f8dcb..562e681fc5 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
index de5b705bc0..11fe4656f1 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
index 7811439ca5..bfd91dcb8e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
index 0e5341bd05..c25a5b51bb 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
index 0e5341bd05..c25a5b51bb 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
index a8ee26da57..143f12b92f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
index af45d10de4..2611be03cc 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
index 93e66f0879..e284e59cb2 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_cbo/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
index a0ed1ae03b..b18947c62a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
index a0ed1ae03b..b18947c62a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
index 04ed50c437..949679427e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
index 3fb593b7f7..64722848bc 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
index 6c8a731e74..4b9dae4d99 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_full_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
index 01c3d7b247..60d5e74281 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.10.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
index a0ed1ae03b..b18947c62a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.11.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
index 4de3cbb0d2..1d655c9736 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.12.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
index 3fb593b7f7..64722848bc 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.8.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
index 6c8a731e74..4b9dae4d99 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_less_parallelism/cluster-by/kmeans-num-iterations/kmeans-num-iterations.9.plan
@@ -150,8 +150,8 @@ distribute result [$$92] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-c
                                                                   -- STREAM_LIMIT  |PARTITIONED|
                                                                     exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      order (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
-                                                                      -- STABLE_SORT [$$114(ASC)]  |PARTITIONED|
+                                                                      order (topK: 1) (ASC, $$114) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                                                      -- STABLE_SORT [topK: 1] [$$114(ASC)]  |PARTITIONED|
                                                                         exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           assign [$$114] <- [vector-shuffle-key($$113, 10)] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]